mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-19 10:33:05 +00:00
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:
@@ -97,8 +97,7 @@ pub(super) fn sort_map_by_keys(values: &mut [Value], buffer: &[u8]) {
|
||||
// preferred over custom sorting or adding another dependency. By construction, this part
|
||||
// of the values stack must be alternating (key, value) pairs. The public API must not be
|
||||
// able to trigger the above debug_assets that protect this unsafe usage.
|
||||
let pairs: &mut [[Value; 2]] =
|
||||
unsafe { std::slice::from_raw_parts_mut(raw_pairs, pairs_len) };
|
||||
let pairs: &mut [[Value; 2]] = unsafe { std::slice::from_raw_parts_mut(raw_pairs, pairs_len) };
|
||||
#[rustfmt::skip]
|
||||
pairs.sort_unstable_by(|[key1, _], [key2, _]| {
|
||||
if let Value::Key(a1) = *key1 {
|
||||
|
||||
@@ -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! {
|
||||
|
||||
@@ -36,6 +36,10 @@ impl FlexbufferSerializer {
|
||||
pub fn take_buffer(&mut self) -> Vec<u8> {
|
||||
self.builder.take_buffer()
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.builder.reset();
|
||||
self.nesting.clear();
|
||||
}
|
||||
fn finish_if_not_nested(&mut self) -> Result<(), Error> {
|
||||
if self.nesting.is_empty() {
|
||||
assert_eq!(self.builder.values.len(), 1);
|
||||
|
||||
Reference in New Issue
Block a user