19 unstable releases

0.10.0 Feb 23, 2024
0.9.0 Mar 19, 2022
0.8.0 Jun 26, 2021
0.7.1 Mar 25, 2021
0.1.4 Jul 27, 2020

#2 in #tokio-codec

Download history 11/week @ 2024-03-10 21/week @ 2024-03-31 1/week @ 2024-04-07

248 downloads per month
Used in 2 crates

0BSD license

58KB
1K SLoC

blather

A talkative, somwhat reminiscent to HTTP, line-based protocol, implemented as a tokio-util Codec.


lib.rs:

A protocol and a communication library for a mostly line-based key/value pair protocol.

Communication buffers

blather defines a few buffers which it uses to send and receive information over its communication module.

Telegrams

The most central communication buffer is Telegram, which consists of a topic and zero or more key/value pairs, where each key must be unique.

use blather::Telegram;

let mut tg = Telegram::new_topic("AddUser").unwrap();

tg.add_param("Name", "Frank Foobar");
tg.add_param("Job", "Secret Agent");
tg.add_param("Age", "42");

assert_eq!(tg.get_topic(), Some("AddUser"));
assert_eq!(tg.get_str("Name").unwrap(), "Frank Foobar");
assert_eq!(tg.get_param::<u8>("Age").unwrap(), 42);

Params

These are simple key/value pairs, which can be seen as HashMap's with some restrictions on key names.

use blather::Params;

let mut params = Params::new();

params.add_param("Name", "Frank Foobar");
params.add_param("Job", "Secret Agent");
params.add_param("Age", "42");

assert_eq!(params.get_str("Name").unwrap(), "Frank Foobar");
assert_eq!(params.get_param::<u8>("Age").unwrap(), 42);

A set of "parameters", represented by the Params struct, is a set of key/value pairs. They look similar to Telegrams because the Telegram's implement their key/value paris using a Params buffer.

Communication

blather handles transmission using tokio-util's Framed framework, by implementing its own Codec. It can be used to send and receive the various communication buffers supported by the crate.

Dependencies

~3–12MB
~117K SLoC