Expand description
Flexbuffers is a high performance schemaless binary data format designed at Google. It is complementary to the schema-ed format Flatbuffers. See Flexbuffer Internals for details on the binary format.
See the examples for usage:
This rust implementation is in progress and, until the 1.0 release, breaking API changes may happen between minor versions.
§fexbluffers
Allocation optimized FlexBuffer implementation (Rust).
Slower for struct serialization/deserialization – faster for some kinds of vector building.
// use flexbuffers;
use fexbluffers;
use stats_alloc::{INSTRUMENTED_SYSTEM, Region, StatsAlloc};
use std::alloc::System;
#[global_allocator]
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM;
fn main() {
let reg = Region::new(&GLOBAL);
// let mut builder = flexbuffers::Builder::default();
let mut builder = fexbluffers::Builder::default();
let mut test_vec = builder.start_vector();
test_vec.push("hello!");
test_vec.push(123);
test_vec.push(());
test_vec.push("something else!");
test_vec.push(10_000);
test_vec.end_vector();
builder.view();
println!("stats: {:#?}", reg.change());
}
// This crate (OMM):
// stats: Stats {
// allocations: 1,
// deallocations: 0,
// reallocations: 3,
// bytes_allocated: 64,
// bytes_deallocated: 0,
// bytes_reallocated: 56,
// }
// time: [195.81 ns 197.43 ns 199.05 ns]
// Official FlexBuffers crate (OMM):
// Stats {
// allocations: 2,
// deallocations: 0,
// reallocations: 4,
// bytes_allocated: 192,
// bytes_deallocated: 0,
// bytes_reallocated: 120,
// }
// time: [266.06 ns 267.28 ns 268.46 ns]forked from google’s implementation https://github.com/google/flatbuffers/tree/c7b9dc83f58fe72162b076ba9c88d682f5d0eda6/rust/flexbuffers#readme
§Flexbuffers
Flexbuffers is a
schema-less binary format developed at Google. FlexBuffers can be accessed
without parsing, copying, or allocation. This is a huge win for efficiency,
memory friendly-ness, and allows for unique use cases such as mmap-ing large
amounts of free-form data.
FlexBuffers’ design and implementation allows for a very compact encoding,
with automatic sizing of containers to their smallest possible representation
(8/16/32/64 bits). Many values and offsets can be encoded in just 8 bits.
FlexBuffers supports Serde for automatically serializing
Rust data structures into its binary format.
§See Examples for Usage:
Flexbuffers is the schema-less cousin of Flatbuffers.
Structs§
- Blob
- This struct, when pushed will be serialized as a
FlexBufferType::Blob. - Builder
- Use this struct to build a Flexbuffer.
- Builder
Options - Options for sharing data within a flexbuffer.
- Flexbuffer
Serializer - Flexbuffer Serializer. This should be used to serialize structs.
- Indirect
Float - This struct, when pushed, will be serialized as a
FlexBufferType::IndirectFloat. - Indirect
Int - This struct, when pushed, will be serialized as a
FlexBufferType::IndirectInt. - IndirectU
Int - This struct, when pushed, will be serialized as a
FlexBufferType::IndirectUInt. - MapBuilder
- Builds a Flexbuffer map, returned by a Builder.
- MapReader
- Allows indexing on a flexbuffer map.
- Reader
Readers allow access to data stored in a Flexbuffer.- Reader
Iterator - Iterates over a flexbuffer vector, typed vector, or map. Yields Readers.
- Vector
Builder - Builds a Flexbuffer vector, returned by a Builder.
- Vector
Reader - Allows indexing on any flexbuffer vector type, (heterogenous vector, typed vector, or fixed length typed vector).
Enums§
- BitWidth
- Represents the size of Flexbuffers data.
- Deserialization
Error - Errors that may happen when deserializing a flexbuffer with serde.
- Flex
Buffer Type - Represents all the valid types in a flexbuffer.
- Reader
Error - All the possible errors when reading a flexbuffer.
- Serialization
Error - Errors that may happen with Serde.
Traits§
- Buffer
- The underlying buffer that is used by a flexbuffer Reader.
- Pushable
- Types that implement the Pushable trait can be written into a Flexbuffer.
Functions§
- from_
buffer - Deserialize a type from a flexbuffer.
- from_
slice - Deserialize a type from a flexbuffer.
- singleton
- Builds a Flexbuffer with the single pushed value as the root.
- to_vec
- Serialize as a flexbuffer into a vector.