#thrift #codec #protocols #message #binary #data

thrift_codec

A library for encoding/decoding binaries specified by the thrift protocol

5 unstable releases

0.3.1 Jan 16, 2024
0.3.0 Jan 13, 2024
0.2.0 Apr 6, 2022
0.1.1 Oct 19, 2017
0.1.0 Oct 12, 2017

#456 in Encoding

Download history 2378/week @ 2023-11-21 3707/week @ 2023-11-28 2861/week @ 2023-12-05 4217/week @ 2023-12-12 3118/week @ 2023-12-19 1348/week @ 2023-12-26 3680/week @ 2024-01-02 5985/week @ 2024-01-09 5069/week @ 2024-01-16 7162/week @ 2024-01-23 6478/week @ 2024-01-30 6626/week @ 2024-02-06 7398/week @ 2024-02-13 6563/week @ 2024-02-20 8279/week @ 2024-02-27 7759/week @ 2024-03-05

31,263 downloads per month
Used in 27 crates (3 directly)

MIT license

67KB
1.5K SLoC

thrift_codec

thrift_codec Documentation Actions Status License: MIT

This crate provides functionalities for encoding/deconding Thrift protocol.

Documentation

References

Examples

Encodes a message:

use thrift_codec::CompactEncode;
use thrift_codec::data::Struct;
use thrift_codec::message::Message;

let message = Message::oneway("foo_method", 1, Struct::from(("arg1", 2)));
let mut buf = Vec::new();
message.compact_encode(&mut buf).unwrap();
assert_eq!(
    buf,
    [130, 129, 1, 10, 102, 111, 111, 95, 109, 101, 116,
    104, 111, 100, 24, 4, 97, 114, 103, 49, 21, 4, 0]
);

Decodes the above binary:

use thrift_codec::CompactDecode;
use thrift_codec::data::Struct;
use thrift_codec::message::Message;

let bytes = [
    130, 129, 1, 10, 102, 111, 111, 95, 109, 101, 116,
    104, 111, 100, 24, 4, 97, 114, 103, 49, 21, 4, 0
];

let message = Message::compact_decode(&mut &bytes[..]).unwrap();
let expected = Message::oneway("foo_method", 1, Struct::from(("arg1", 2)));
assert_eq!(message, expected);

Dependencies

~1.2–1.6MB
~37K SLoC