Implement Serialize for flexbuffer::Reader (#6635)

* Implement Serialize for flexbuffer::Reader

* bump version

* Remove use of experimantal or-patterns

* Remove more use of experimantal or-patterns

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-05-10 23:15:46 -04:00
committed by GitHub
parent a1730fcea8
commit 8fd10606c1
9 changed files with 125 additions and 40 deletions

View File

@@ -32,10 +32,11 @@ macro_rules! push_slice {
fn $push_name<T, S>(&mut self, xs: S)
where
T: Into<$scalar> + Copy,
S: AsRef<[T]>
S: AsRef<[T]>,
{
let mut value = Value::$new_vec(xs.as_ref().len());
let mut width = xs.as_ref()
let mut width = xs
.as_ref()
.iter()
.map(|x| BitWidth::from((*x).into()))
.max()
@@ -56,7 +57,7 @@ macro_rules! push_slice {
value.set_child_width_or_panic(width);
self.values.push(value);
}
}
};
}
macro_rules! push_indirect {
($push_name: ident, $scalar: ty, $Direct: ident, $Indirect: ident) => {
@@ -65,15 +66,13 @@ macro_rules! push_indirect {
let child_width = x.width_or_child_width();
let address = self.buffer.len();
store_value(&mut self.buffer, x, child_width);
self.values.push(
Value::Reference {
address,
child_width,
fxb_type: FlexBufferType::$Indirect,
}
);
self.values.push(Value::Reference {
address,
child_width,
fxb_type: FlexBufferType::$Indirect,
});
}
}
};
}
bitflags! {