-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document _CDDL_CODEGEN_RAW_BYTES_TYPE_ + trait export (#192)
* Document _CDDL_CODEGEN_RAW_BYTES_TYPE_ + trait export The `RawBytesEncoding` trait will now be exported in `serialization.rs` when it's used in the CDDL input. Documented `_CDDL_CODEGEN_RAW_BYTES_TYPE_` usage in the README too. * README.md update for typo + clarification * fix tests * comment in docs folder instead
- Loading branch information
1 parent
b05d631
commit e25dbe7
Showing
8 changed files
with
61 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pub trait RawBytesEncoding { | ||
fn to_raw_bytes(&self) -> &[u8]; | ||
|
||
fn from_raw_bytes(bytes: &[u8]) -> Result<Self, DeserializeError> | ||
where | ||
Self: Sized; | ||
|
||
fn to_raw_hex(&self) -> String { | ||
hex::encode(self.to_raw_bytes()) | ||
} | ||
|
||
fn from_raw_hex(hex_str: &str) -> Result<Self, DeserializeError> | ||
where | ||
Self: Sized, | ||
{ | ||
let bytes = hex::decode(hex_str) | ||
.map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)))?; | ||
Self::from_raw_bytes(bytes.as_ref()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ impl<T: cbor_event::se::Serialize> ToCBORBytes for T { | |
self.serialize(&mut buf).unwrap(); | ||
buf.finalize() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters