feat: to_cbor and to_hex for Program
This commit is contained in:
@@ -15,6 +15,7 @@ exclude = ["test_data/*"]
|
||||
[dependencies]
|
||||
flat-rs = { path = "../flat", version = "0.0.6" }
|
||||
hex = "0.4.3"
|
||||
minicbor = { version = "0.18.0", features = ["std"] }
|
||||
peg = "0.8.0"
|
||||
pretty = "0.11.3"
|
||||
thiserror = "1.0.31"
|
||||
|
||||
@@ -33,8 +33,14 @@ where
|
||||
self.flat()
|
||||
}
|
||||
|
||||
pub fn flat_hex(&self) -> Result<String, en::Error> {
|
||||
let bytes = self.flat()?;
|
||||
pub fn to_cbor(&self) -> Result<Vec<u8>, en::Error> {
|
||||
let flat_bytes = self.flat()?;
|
||||
|
||||
minicbor::to_vec(&flat_bytes).map_err(|err| en::Error::Message(err.to_string()))
|
||||
}
|
||||
|
||||
pub fn to_hex(&self) -> Result<String, en::Error> {
|
||||
let bytes = self.to_cbor()?;
|
||||
|
||||
let hex = hex::encode(&bytes);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user