All Projects → near → borsh-rs

near / borsh-rs

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Rust implementation of Binary Object Representation Serializer for Hashing

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to borsh-rs

SwiftCBOR
A CBOR implementation for Swift
Stars: ✭ 95 (-36.24%)
Mutual labels:  serialization, binary-serialization
desert
Binary serialization library for Scala
Stars: ✭ 42 (-71.81%)
Mutual labels:  serialization, binary-serialization
javascript-serialization-benchmark
Comparison and benchmark of JavaScript serialization libraries (Protocol Buffer, Avro, BSON, etc.)
Stars: ✭ 54 (-63.76%)
Mutual labels:  serialization, binary-serialization
edap
No description or website provided.
Stars: ✭ 22 (-85.23%)
Mutual labels:  serialization
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (-48.32%)
Mutual labels:  serialization
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (-81.21%)
Mutual labels:  serialization
serial-builder
Library for manually creating Java serialization data.
Stars: ✭ 20 (-86.58%)
Mutual labels:  serialization
urlpack
Pure JavaScript toolkit for data URLs (MessagePack, Base58 and Base62)
Stars: ✭ 51 (-65.77%)
Mutual labels:  serialization
wasmbin
A self-generating WebAssembly parser & serializer in Rust.
Stars: ✭ 40 (-73.15%)
Mutual labels:  serialization
json5
Header only JSON/JSON5 parser and serializer for C++
Stars: ✭ 22 (-85.23%)
Mutual labels:  serialization
sexpresso
An s-expression library for C++
Stars: ✭ 41 (-72.48%)
Mutual labels:  serialization
break-fast-serial
A proof of concept that demonstrates asynchronous scanning for Java deserialization bugs
Stars: ✭ 53 (-64.43%)
Mutual labels:  serialization
kafka-serde-scala
Implicitly converts typeclass encoders to kafka Serializer, Deserializer, Serde.
Stars: ✭ 52 (-65.1%)
Mutual labels:  serialization
Unity-SerializeReferenceExtensions
Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.
Stars: ✭ 255 (+71.14%)
Mutual labels:  serialization
serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (-67.11%)
Mutual labels:  serialization
surge
Simple, specialised, and efficient binary marshaling
Stars: ✭ 36 (-75.84%)
Mutual labels:  serialization
bytecodec
A tiny Rust framework for implementing encoders/decoders of byte-oriented protocols
Stars: ✭ 21 (-85.91%)
Mutual labels:  serialization
HTTP-Wrapper
A simple http wrapper
Stars: ✭ 13 (-91.28%)
Mutual labels:  serialization
json struct
json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa
Stars: ✭ 279 (+87.25%)
Mutual labels:  serialization
msgpack-smalltalk
MessagePack serialization library for various Smalltalk dialects / msgpack.org[Smalltalk]
Stars: ✭ 22 (-85.23%)
Mutual labels:  serialization

Borsh in Rust   Latest Version borsh: rustc 1.40+ License Apache-2.0 badge License MIT badge

borsh-rs is Rust implementation of the Borsh binary serialization format.

Borsh stands for Binary Object Representation Serializer for Hashing. It is meant to be used in security-critical projects as it prioritizes consistency, safety, speed, and comes with a strict specification.

Example

use borsh::{BorshSerialize, BorshDeserialize};

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct A {
    x: u64,
    y: String,
}

#[test]
fn test_simple_struct() {
    let a = A {
        x: 3301,
        y: "liber primus".to_string(),
    };
    let encoded_a = a.try_to_vec().unwrap();
    let decoded_a = A::try_from_slice(&encoded_a).unwrap();
    assert_eq!(a, decoded_a);
}

Features

Opting out from Serde allows borsh to have some features that currently are not available for serde-compatible serializers. Currently we support two features: borsh_init and borsh_skip (the former one not available in Serde).

borsh_init allows to automatically run an initialization function right after deserialization. This adds a lot of convenience for objects that are architectured to be used as strictly immutable. Usage example:

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh_init(init)]
struct Message {
    message: String,
    timestamp: u64,
    public_key: CryptoKey,
    signature: CryptoSignature
    hash: CryptoHash
}

impl Message {
    pub fn init(&mut self) {
        self.hash = CryptoHash::new().write_string(self.message).write_u64(self.timestamp);
        self.signature.verify(self.hash, self.public_key);
    }
}

borsh_skip allows to skip serializing/deserializing fields, assuming they implement Default trait, similary to #[serde(skip)].

#[derive(BorshSerialize, BorshDeserialize)]
struct A {
    x: u64,
    #[borsh_skip]
    y: f32,
}

Releasing

The versions of all public crates in this repository are collectively managed by a single version in the workspace manifest.

So, to publish a new version of all the crates, you can do so by simply bumping that to the next "patch" version and submit a PR.

We have CI Infrastructure put in place to automate the process of publishing all crates once a version change has merged into master.

However, before you release, make sure the CHANGELOG is up to date and that the [Unreleased] section is present but empty.

License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.

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].