Crates.io | httlib-protos |
lib.rs | httlib-protos |
version | 0.3.2 |
source | src |
created_at | 2021-09-21 20:48:14.413455 |
updated_at | 2021-10-10 12:03:18.163889 |
description | Protocol Buffers binary format implementation. |
homepage | https://github.com/xpepermint/httlib-rs/tree/main/protos |
repository | https://github.com/xpepermint/httlib-rs |
max_upload_size | |
id | 454604 |
size | 115,966 |
This crate implements Protocol Buffers binary protocol v3
(proto3
),
for encoding and decoding typed messages to and from the wire format. The
protocol deals in-depth with optimizing the representation of data types on
the wire so that as little data as possible is transmitted between the client
and server.
Protocol Buffers, also know as protos
or protobufs
, is an open-source
interface description language originally developed by Google and a library
that allows JSON-like data messages to be transmitted over the wire without
unnecessary ballast. Today, it is most relevant in the context of gRPC,
where RPC server and client code for arbitrary programming languages is
generated based on Protocol Buffers descriptions.
Protocol Buffers were developed primarily with the goal of speeding up the transmission of strongly typed key-value message objects over the network, which in turn means reducing the amount of data that needs to be transmitted over the wire from A to B.
REST and RPC are two concepts that are now considered a kind of de facto way of developing APIs in web development. Communication between the client and the server is mostly about transferring data in JSON format. This is user-friendly, but highly suboptimal at the network level.
Protocol Buffers addresses this issue and is one of the most optimized protocols which is also growing in popularity.
This library is not meant for generating code for the client and the server. The crate focuses on the low-level data compression and decompression for transmitting typed objects over the wire. It offers the full implementation of the Protocol Buffer's binary protocol.
Encoding example:
use httlib_protos::{Encoder, EncoderLit};
let encoder = Encoder::default();
let mut dst = Vec::new();
encoder.encode((&1, &150i32), &mut dst).unwrap(); // common type
encoder.encode((&2, EncoderLit::SInt32(&-150i32)), &mut dst).unwrap(); // specific type
Decoding example:
use httlib_protos::{Decoder, DecoderLit};
let mut decoder = Decoder::default();
let mut buf = vec![0x85, 0x35, 0x85];
let mut dst = vec![];
let size = decoder.decode(&mut buf, &mut dst).unwrap();
for (tag, typ, byt) in dst.drain(..) {
if tag == 1 {
i32::from(DecoderLit::Int32(byt));
}
}
License: MIT