flat encoding for list and pairs

Co-authored-by: rvcas <x@rvcas.dev>
This commit is contained in:
Kasey White
2022-08-04 02:36:39 -04:00
committed by Lucas
parent 198dae7f5d
commit d14920265e
8 changed files with 187 additions and 47 deletions

View File

@@ -156,11 +156,14 @@ impl Encoder {
/// This is byte alignment agnostic.
/// If there are bytes in a list then write 1 bit followed by the functions encoding.
/// After the last item write a 0 bit. If the list is empty only encode a 0 bit.
pub fn encode_list_with(
pub fn encode_list_with<T>(
&mut self,
list: Vec<u8>,
encoder_func: for<'r> fn(u8, &'r mut Encoder) -> Result<(), Error>,
) -> Result<&mut Self, Error> {
list: &[T],
encoder_func: for<'r> fn(&T, &'r mut Encoder) -> Result<(), Error>,
) -> Result<&mut Self, Error>
where
T: Encode,
{
for item in list {
self.one();
encoder_func(item, self)?;