Giter VIP home page Giter VIP logo

anybuf's Introduction

anybuf

anybuf on crates.io Docs

A minimal, zero dependency protobuf encoder and decoder to encode/decode anything. It is designed to create the value bytes of a protobuf Any, hence the name.

Due to its low level design, anybuf allows you to do things wrong in many ways and you should have a solid understanding of how protobuf encoding works in general to better understand the API.

The crate anybuf is split in two major components:

  • anybuf::Anybuf is a protobuf encoder
  • anybuf::Bufany is a protobuf decoder

Non goals

Supported

  • Varint fields (bool/uint32/uint64/sint32/sint64/int32/int64)
  • Variable length fields (string/bytes)
  • Nested messages: Just append an Anybuf instance
  • Repeated (bool/uint32/uint64/sint32/sint64/int32/int64/string/bytes/messages)

Not yet supported

How to use it

Encoding

use anybuf::Anybuf;

let data = Anybuf::new()
    .append_uint64(1, 4)        // field number 1 gets value 4
    .append_string(2, "hello")  // field number 2 gets a string
    .append_bytes(3, b"hello")  // field number 3 gets bytes
    .append_message(4, &Anybuf::new().append_bool(3, true)) // field 4 gets a message
    .append_repeated_uint64(5, &[23, 56, 192])              // field number 5 is a repeated uint64
    .into_vec();                // done

// data is now a serialized protobuf document

Decoding

use anybuf::Bufany;

let deserialized = Bufany::deserialize(&data).unwrap(); // data from above
let id = deserialized.uint64(1).unwrap(); // 4
let title = deserialized.string(2).unwrap(); // "hello"

anybuf's People

Contributors

webmaster128 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.