mirror of
https://github.com/trussed-dev/flexiber.git
synced 2026-06-20 04:16:10 -07:00
Bugfix and improvements
This commit is contained in:
@@ -126,6 +126,7 @@ impl DeriveEncodableStruct {
|
||||
F: FnOnce(&[&dyn flexiber::Encodable]) -> flexiber::Result<T>,
|
||||
{
|
||||
use core::convert::TryFrom;
|
||||
use flexiber::TagLike;
|
||||
field_encoder(&[#encode_fields])
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -137,6 +137,9 @@ pub trait EncodableHeapless: Encodable {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "heapless")]
|
||||
impl<X> EncodableHeapless for X where X: Encodable {}
|
||||
|
||||
/// Types that can be tagged.
|
||||
pub(crate) trait Taggable<T: TagLike>: Sized {
|
||||
fn tagged(&self, tag: T) -> TaggedValue<&Self, T> {
|
||||
@@ -241,7 +244,7 @@ where
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'a> Encodable for &'a [u8] {
|
||||
impl Encodable for &[u8] {
|
||||
fn encoded_length(&self) -> Result<Length> {
|
||||
self.len().try_into()
|
||||
}
|
||||
@@ -252,6 +255,23 @@ impl<'a> Encodable for &'a [u8] {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Option<&[u8]> {
|
||||
fn encoded_length(&self) -> Result<Length> {
|
||||
match self {
|
||||
Some(slice) => slice.encoded_length(),
|
||||
None => Ok(Length::zero()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Encode this value as BER-TLV using the provided [`Encoder`].
|
||||
fn encode(&self, encoder: &mut Encoder<'_>) -> Result<()> {
|
||||
match self {
|
||||
Some(slice) => encoder.bytes(slice),
|
||||
None => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_array {
|
||||
($($N:literal),*) => {
|
||||
$(
|
||||
|
||||
Reference in New Issue
Block a user