decode a byte stream of varint length-encoded messages into a stream of chunks

Overview

length-prefixed-stream

decode a byte stream of varint length-encoded messages into a stream of chunks

This crate is similar to and compatible with the javascript length-prefixed-stream package.

example

use async_std::{prelude::*,stream,task};
use length_prefixed_stream::decode;
use futures::{stream::TryStreamExt};
type Error = Box<dyn std::error::Error+Send+Sync+'static>;

// this program will print:
// [97,98,99,100,101,102]
// [65,66,67,68]

fn main() -> Result<(),Error> {
  task::block_on(async {
    let input = stream::from_iter(vec![
      Ok(vec![6,97,98,99]),
      Ok(vec![100,101]),
      Ok(vec![102,4,65,66]),
      Ok(vec![67,68]),
    ]).into_async_read();
    let mut decoder = decode(input);
    while let Some(chunk) = decoder.next().await {
      println!["{:?}", chunk?];
    }
    Ok(())
  })
}
You might also like...
Automatically commit all edits to a wip branch with GPT-3 commit messages

gwipt Automatic work-in-progress commits with descriptive commit messages generated by GPT-3 Codex Never again worry about the tension between "commit

turbocommit is a Rust-based CLI tool that generates high-quality git commit messages in accordance with the Conventional Commits specification, using OpenAI's
turbocommit is a Rust-based CLI tool that generates high-quality git commit messages in accordance with the Conventional Commits specification, using OpenAI's

turbocommit is a Rust-based CLI tool that generates high-quality git commit messages in accordance with the Conventional Commits specification, using OpenAI's `gpt-3.5-turbo` language model. It is easy to use and a cost-effective way to keep git commit history at a higher quality, helping developers stay on track with their work.

A CLI tool that uses ChatGPT to automatically generate commit messages.

Auto Git Commit This project is a tool that uses the OpenAI GPT model to automatically generate commit messages for Git commits based on the changes m

Extract patterns from unstructured log messages
Extract patterns from unstructured log messages

logu logu is for extracting patterns from (streaming) unstructured log messages. For parsing unstructured logs, it uses the parser from Drain. In simp

Test whether a given stream is a terminal

is-terminal Test whether a given stream is a terminal is-terminal is a simple utility that answers one question: Is this a terminal? A "terminal", als

Stream-based visual programming language for systems observability
Stream-based visual programming language for systems observability

Stream-based visual programming language for systems observability. Metalens allows to build observability programs in a reactive and visual way. On L

Scol (Stream Colorizer)

Scol (Stream Colorizer) Scol is a simple command-line program that reads lines from standard input and colorizes them based on a regular expression pa

100% stream-based O(n) syntax highlighter for ANSI terminal
100% stream-based O(n) syntax highlighter for ANSI terminal

Lex-highlighter 100% stream-based $\mathcal O(n)$ syntax highlighter for ANSI terminal Warning This is proof-of-concept implementation and WON't be co

Turn static CLI commands into TUIs with ease
Turn static CLI commands into TUIs with ease

lazycli Turn static CLI commands into TUIs with ease Demo: Usage Pick a command that spits out either a list or table of content, like ls, docker ps,

Owner
James Halliday
James Halliday
Write a simple CLI script, that when given a 64-byte encoded string

Write a simple CLI script, that when given a 64-byte encoded string, it finds a suitable 4-byte prefix so that, a SHA256 hash of the prefix combined with the original string of bytes, has two last bytes as 0xca, 0xfe. Script should expect the original content of the string to be passed in hexadecimal format and should return two lines, first being the SHA256 string found and second 4-byte prefix used (in hexadecimal format).

Andy Bell 0 Feb 4, 2022
Extension trait to chunk iterators into const-length arrays.

const-chunks This crate provides an extension trait that lets you chunk iterators into constant-length arrays using const generics. See the docs for m

Louis Gariépy 6 Jun 12, 2023
dovi_meta is a CLI tool for creating Dolby Vision XML metadata from an encoded deliverable with binary metadata.

dovi_meta dovi_meta is a CLI tool for creating Dolby Vision XML metadata from an encoded deliverable with binary metadata. Building Toolchain The mini

Rainbaby 12 Dec 14, 2022
CLI tool to encode/decode base64

b64 is a simple util to encode/decode base64 texts.

null 0 Jul 6, 2022
Encode and decode dynamically constructed values of arbitrary shapes to/from SCALE bytes

scale-value · This crate provides a Value type, which is a runtime representation that is compatible with scale_info::TypeDef. It somewhat analogous t

Parity Technologies 15 Jun 24, 2023
Decode URLs in your files!

urldecoder English | 简体中文 A tool to batch decode URLs in your files. A toy project written in Rust. Decoding URLs shortens the string length and incre

Absolutex 3 Feb 18, 2024
UnixString is An FFI-friendly null-terminated byte string

UnixString is an FFI-friendly null-terminated byte string that may be constructed from a String, a CString, a PathBuf, an OsString or a collection of bytes.

Vinícius Miguel 20 Apr 14, 2022
😱 Panic messages for humans.

human-panic Panic messages for humans. Handles panics by calling std::panic::set_hook to make errors nice for humans. Documentation Crates.io Why? Whe

Rust CLI WG 997 Jan 1, 2023
Command line tool to make conventional commit messages

Commit This project is a copy of cz-cli with some minor changes. I made this project for my own use, because I don't want to mess with the original cz

Pedro Mendes 80 Dec 26, 2022
dhcpm is a CLI tool for constructing & sending DHCP messages

dhcpm Sponsor Thank you to Bluecat for sponsoring this work! dhcpm leverages dhcproto check that out for the DHCP protocol. About A cli tool (and dhcp

Evan Cameron 12 Mar 28, 2022