#thrift #binary-protocol #encoding-decoding

thrift_codec

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

6 releases

0.3.2 Jun 11, 2024
0.3.1 Jan 16, 2024
0.2.0 Apr 6, 2022
0.1.1 Oct 19, 2017

#128 in Encoding

Download history 43130/week @ 2025-05-21 45302/week @ 2025-05-28 49149/week @ 2025-06-04 50197/week @ 2025-06-11 41954/week @ 2025-06-18 47319/week @ 2025-06-25 50735/week @ 2025-07-02 59858/week @ 2025-07-09 72676/week @ 2025-07-16 69428/week @ 2025-07-23 86717/week @ 2025-07-30 86751/week @ 2025-08-06 82621/week @ 2025-08-13 95841/week @ 2025-08-20 85099/week @ 2025-08-27 140176/week @ 2025-09-03

419,991 downloads per month
Used in 76 crates (5 directly)

MIT license

72KB
1.5K SLoC

thrift_codec

thrift_codec Documentation Actions Status License: MIT

This crate provides functionalities for encoding/decoding 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

~2MB
~43K SLoC