All Projects → bincode-org → Bincode

bincode-org / Bincode

Licence: mit
A binary encoder / decoder implementation in Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Bincode

Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (-92.18%)
Mutual labels:  encoding, serialization, binary
sia
Sia - Binary serialisation and deserialisation
Stars: ✭ 52 (-95.27%)
Mutual labels:  encoding, serialization, binary
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-98.18%)
Mutual labels:  encoding, serialization, binary
Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (-43.82%)
Mutual labels:  encoding, serialization, binary
persistity
A persistence framework for game developers
Stars: ✭ 34 (-96.91%)
Mutual labels:  serialization, binary
content inspector
Fast inspection of binary buffers to guess/determine the type of content
Stars: ✭ 28 (-97.45%)
Mutual labels:  encoding, binary
hs-packer
Fast serialization in haskell
Stars: ✭ 13 (-98.82%)
Mutual labels:  serialization, binary
binary
package binary is a lightweight and high-performance serialization library to encode/decode between go data and []byte.
Stars: ✭ 20 (-98.18%)
Mutual labels:  serialization, binary
nason
🗜 Ultra tiny serializer / encoder with plugin-support. Useful to build binary files containing images, strings, numbers and more!
Stars: ✭ 30 (-97.27%)
Mutual labels:  serialization, binary
protodata
A textual language for binary data.
Stars: ✭ 35 (-96.82%)
Mutual labels:  serialization, binary
Watson
WATSON: Wasted but Amazing Turing-incomplete Stack-based Object Notation
Stars: ✭ 258 (-76.55%)
Mutual labels:  encoding, serialization
Bois
Salar.Bois is a compact, fast and powerful binary serializer for .NET Framework. With Bois you can serialize your existing objects with almost no change.
Stars: ✭ 53 (-95.18%)
Mutual labels:  serialization, binary
GroBuf
Fast binary serializer
Stars: ✭ 56 (-94.91%)
Mutual labels:  serialization, binary
Apex.Serialization
High performance contract-less binary serializer for .NET
Stars: ✭ 82 (-92.55%)
Mutual labels:  serialization, binary
Fastbinaryencoding
Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift
Stars: ✭ 421 (-61.73%)
Mutual labels:  serialization, binary
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (-66%)
Mutual labels:  serialization, binary
Iguana
universal serialization engine
Stars: ✭ 481 (-56.27%)
Mutual labels:  serialization, binary
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (-94.82%)
Mutual labels:  serialization, binary
ronin-support
A support library for Ronin. Like activesupport, but for hacking!
Stars: ✭ 23 (-97.91%)
Mutual labels:  encoding, binary
Fspickler
A fast multi-format message serializer for .NET
Stars: ✭ 299 (-72.82%)
Mutual labels:  serialization, binary

Bincode

CI

A compact encoder / decoder pair that uses a binary zero-fluff encoding scheme. The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program.

In addition to exposing two simple functions (one that encodes to Vec<u8>, and one that decodes from &[u8]), binary-encode exposes a Reader/Writer API that makes it work perfectly with other stream-based APIs such as Rust files, network streams, and the flate2-rs compression library.

API Documentation

Bincode in the wild

  • google/tarpc: Bincode is used to serialize and deserialize networked RPC messages.
  • servo/webrender: Bincode records webrender API calls for record/replay-style graphics debugging.
  • servo/ipc-channel: IPC-Channel uses Bincode to send structs between processes using a channel-like API.

Example

use serde::{Serialize, Deserialize};

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

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct World(Vec<Entity>);

fn main() {
    let world = World(vec![Entity { x: 0.0, y: 4.0 }, Entity { x: 10.0, y: 20.5 }]);

    let encoded: Vec<u8> = bincode::serialize(&world).unwrap();

    // 8 bytes for the length of the vector, 4 bytes per float.
    assert_eq!(encoded.len(), 8 + 4 * 4);

    let decoded: World = bincode::deserialize(&encoded[..]).unwrap();

    assert_eq!(world, decoded);
}

Details

The encoding (and thus decoding) proceeds unsurprisingly -- primitive types are encoded according to the underlying Writer, tuples and structs are encoded by encoding their fields one-by-one, and enums are encoded by first writing out the tag representing the variant and then the contents.

However, there are some implementation details to be aware of:

  • isize/usize are encoded as i64/u64, for portability.
  • enums variants are encoded as a u32 instead of a usize. u32 is enough for all practical uses.
  • str is encoded as (u64, &[u8]), where the u64 is the number of bytes contained in the encoded string.

Specification

Bincode's format will eventually be codified into a specification, along with its configuration options and default configuration. In the meantime, here are some frequently asked questions regarding use of the crate:

Is Bincode suitable for storage?

The encoding format is stable across minor revisions, provided the same configuration is used. This should ensure that later versions can still read data produced by a previous versions of the library if no major version change has occured.

Bincode is invariant over byte-order in the default configuration (bincode::options::DefaultOptions), making an exchange between different architectures possible. It is also rather space efficient, as it stores no metadata like struct field names in the output format and writes long streams of binary data without needing any potentially size-increasing encoding.

As a result, Bincode is suitable for storing data. Be aware that it does not implement any sort of data versioning scheme or file headers, as these features are outside the scope of this crate.

Is Bincode suitable for untrusted inputs?

Bincode attempts to protect against hostile data. There is a maximum size configuration available (bincode::config::Bounded), but not enabled in the default configuration. Enabling it causes pre-allocation size to be limited to prevent against memory exhaustion attacks.

Deserializing any incoming data will not cause undefined behavior or memory issues, assuming that the deserialization code for the struct is safe itself.

Bincode can be used for untrusted inputs in the sense that it will not create a security issues in your application, provided the configuration is changed to enable a maximum size limit. Malicious inputs will fail upon deserialization.

What is Bincode's MSRV (minimum supported Rust version)?

Bincode 1.0 maintains support for rust 1.18.0. Any changes to this are considered a breaking change for semver purposes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].