thrift_codec

Crates.iothrift_codec
lib.rsthrift_codec
version0.3.2
sourcesrc
created_at2017-10-12 14:09:06.360805
updated_at2024-06-11 23:50:23.329514
descriptionA library for encoding/decoding binaries specified by the thrift protocol
homepagehttps://github.com/sile/thrift_codec
repositoryhttps://github.com/sile/thrift_codec
max_upload_size
id35402
size89,148
Takeru Ohta (sile)

documentation

README

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);
Commit count: 53

cargo fmt