Skip to main content

Crate beve

Crate beve 

Source
Expand description

BEVE - Binary Efficient Versatile Encoding

High-performance, tagged binary format designed for scientific computing. This crate provides a robust, fast, and ergonomic implementation with serde support.

  • Little-endian encoding
  • Direct struct serialization via serde::{Serialize, Deserialize}
  • Typed arrays for numeric, boolean, and string sequences when possible
  • Object keys as strings or integer types
  • Enum variants as ordinary values, per BEVE Version 2 (what serde_json writes)
  • Zero-copy deserialization for &str fields (borrow directly from the input buffer)
  • Validation helpers for checking BEVE payload integrity without deserialization
  • Selective field loading via JSON Pointer (RFC 6901) with optional array slicing — see from_field and from_field_slice

Example

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Point { x: f64, y: f64 }

let p = Point { x: 1.0, y: -2.0 };
let bytes = beve::to_vec(&p).unwrap();
let p2: Point = beve::from_slice(&bytes).unwrap();
assert_eq!(p, p2);

Validate a payload without decoding it into a concrete Rust type:

use std::io::Cursor;

let bytes = beve::to_vec(&vec![1u32, 2, 3]).unwrap();
beve::validate_slice(&bytes).unwrap();
beve::validate_reader(Cursor::new(bytes)).unwrap();

Re-exports§

pub use crate::aligned::aligned_typed_slice_size;
pub use crate::aligned::read_aligned_typed_slice;
pub use crate::aligned::read_aligned_typed_slice_ref;
pub use crate::aligned::to_vec_aligned_typed_slice;
pub use crate::aligned::write_aligned_typed_slice;
pub use crate::aligned::write_aligned_typed_slice_at;
pub use crate::fast::BeveTypedSlice;
pub use crate::fast::complex_slice_size;
pub use crate::fast::read_complex_slice;
pub use crate::fast::read_complex_slice_from_reader;
pub use crate::fast::read_typed_slice;
pub use crate::fast::read_typed_slice_from_reader;
pub use crate::fast::to_vec_bool_slice;
pub use crate::fast::to_vec_complex_slice;
pub use crate::fast::to_vec_str_slice;
pub use crate::fast::to_vec_string_slice;
pub use crate::fast::to_vec_typed_slice;
pub use crate::fast::to_writer_complex_slice;
pub use crate::fast::to_writer_typed_slice;
pub use crate::fast::typed_slice_size;
pub use crate::fast::write_bool_slice;
pub use crate::fast::write_complex_slice;
pub use crate::fast::write_str_slice;
pub use crate::fast::write_string_slice;
pub use crate::fast::write_typed_slice;
pub use crate::field::from_field;
pub use crate::field::from_field_slice;
pub use crate::field::skip_value;
pub use crate::mat::Compression;mat
pub use crate::mat::InvalidNamePolicy;mat
pub use crate::mat::LibVer;mat
pub use crate::mat::MatV73Options;mat
pub use crate::mat::NullPolicy;mat
pub use crate::mat::OneDimensionalMode;mat
pub use crate::mat::RootBinding;mat
pub use crate::mat::RowMajorPolicy;mat
pub use crate::mat::UnsupportedPolicy;mat
pub use crate::mat::beve_file_to_mat_v73_file;mat
pub use crate::mat::beve_slice_to_mat_v73_bytes;mat
pub use crate::mat::beve_slice_to_mat_v73_file;mat
pub use crate::mat::beve_slice_to_mat_v73_writer;mat

Modules§

aligned
Aligned typed numeric arrays — the BEVE wire type built for zero-copy access.
complex
Serde serialize_with helpers for foreign complex types (e.g. num_complex::Complex) that implement ComplexElement (two contiguous Component fields: re then im).
complex_array
#[serde(with = ...)] helpers for bulk (memcpy) decode of numeric (beve::typed::*) and complex (beve::complex_array::*) array fields. #[serde(with = "beve::complex_array::<scalar>")] for a Vec<T> field whose T is a ComplexElement of that scalar: bulk encode and bulk (memcpy) decode of a complex array.
fast
field
Navigate into a BEVE payload using a JSON Pointer (RFC 6901) and deserialize only the targeted value. Intermediate values are skipped without allocation, making this efficient for extracting a single field from a large payload.
matmat
BEVE -> MATLAB v7.3 conversion.
typed
#[serde(with = ...)] helpers for bulk (memcpy) decode of numeric (beve::typed::*) and complex (beve::complex_array::*) array fields. #[serde(with = "beve::typed::<scalar>")] for a Vec<scalar> field: bulk encode and bulk (memcpy) decode of a typed numeric array.
util
BEVE-specific utilities and helper types.

Structs§

Complex
ComplexSlice
A contiguous slice of complex values, serialized as a BEVE complex array with a single bulk write of the borrowed payload — the complex counterpart of TypedSlice.
Deserializer
Matrix
MatrixOwned
RawMatrix
Serializer
StreamingDeserializer
A BEVE deserializer that reads directly from a std::io::Read.
StreamingSerializer
A BEVE serializer that writes directly to a std::io::Write with zero buffering.
TypedSlice
An opt-in wrapper that serializes a contiguous numeric slice &[T] as a BEVE typed array via a single bulk write, rather than element-by-element.

Enums§

BigInt
Large integer that doesn’t fit in 64 bits.
BigIntKey
Large integer key that doesn’t fit in 64 bits.
DecodedMatrix
Error
Marked #[non_exhaustive] so that naming a new failure mode is not itself a breaking change: adding RecursionLimitExceeded broke every downstream exhaustive match, and a decoder will keep learning to refuse things.
Key
A map key that can be a string or integer.
MatrixDecodeMode
MatrixLayout
Number
A BEVE number, which can be signed, unsigned, or floating-point.
Value
Represents any valid BEVE value.
ValueError
Error type for Value deserialization.

Constants§

DATA_DELIMITER
The single-byte data delimiter (BEVE extension 0).
MAX_RECURSION_DEPTH
Ceiling on how deeply a decoded value may nest.

Traits§

ComplexElement
A type the bulk complex-array helpers may read as raw bytes: two contiguous Self::Component scalars, real part first.

Functions§

beve_slice_to_json
Convert BEVE bytes into compact JSON bytes.
beve_slice_to_json_string
Convert BEVE bytes into a JSON string.
decode_matrix_slice
from_reader
Deserialize a value by reading all bytes from a reader into a buffer first.
from_reader_streaming
Deserialize a value by streaming from a reader without buffering the entire input.
from_slice
Deserialize a value from a BEVE byte slice.
from_value
Deserialize a concrete type from a Value.
from_value_ref
Deserialize a concrete type from a Value reference.
json_slice_to_beve
Convert JSON bytes into BEVE bytes without building an intermediate DOM.
json_str_to_beve
Convert a JSON string into BEVE bytes without building an intermediate DOM.
serialized_size
Compute the exact number of bytes to_writer_streaming would write for value, without producing them.
to_vec
to_vec_into
to_writer
Serialize a value into any writer.
to_writer_streaming
Serialize directly to a writer with zero internal buffering.
validate_reader
Validate BEVE data from any reader without deserializing into a concrete type.
validate_slice
Validate that bytes contains exactly one well-formed BEVE value.
write_delimiter
Write a data delimiter byte to the given writer.

Type Aliases§

Object
A BEVE object with ordered key-value pairs.
Result