GithubHelp home page GithubHelp logo

nrc / rust-protobuf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stepancheg/rust-protobuf

2.0 2.0 2.0 16.2 MB

Rust implementation of Google protocol buffers

License: MIT License

Shell 0.36% C++ 0.39% Rust 99.24%

rust-protobuf's Introduction

rust-protobuf

Build Status crates.io version License

Protobuf implementation in Rust.

  • Written in pure rust
  • Generate rust code
  • Has runtime library for generated code (Coded{Input|Output}Stream impl)
  • Supports both Protobuf versions 2 and 3

About versions and branches

  • 2.*.* is the latest stable version. 2.*.* versions follow semver conventions
  • versions below 2 are no longer supported

See CHANGELOG.md for a list of changes and compatility issues between versions.

How to generate rust code

There are several ways to generate rust code from .proto files

Invoke protoc programmatically with protoc-rust crate (recommended)

Have a look at readme in protoc-rust crate.

Use pure rust protobuf parser and code generator (alpha)

Readme should be in protobuf-codegen-pure crate.

Use protoc-gen-rust plugin

Readme is here.

Generated code

Have a look at generated files, used internally in rust-protobuf:

Rustdoc

docs.rs hosts rustdoc for protobuf.

Getting help

Feel free to open an issue if you need help with rust-protobuf.

Copy-on-write

Rust-protobuf can be used with bytes crate.

To enable Bytes you need to:

  1. Enable with-bytes feature in rust-protobuf:
[dependencies]
protobuf = { version = "2", features = ["with-bytes"] }
  1. Enable bytes option

with Customize when codegen is invoked programmatically:

With stable rust-protobuf:

protoc_rust::run(protoc_rust::Args {
    ...
    customize: Customize {
        carllerche_bytes_for_bytes: Some(true),
        carllerche_bytes_for_string: Some(true),
        ..Default::default()
    },
 });

With rust-protobuf from master:

protoc_rust::Args::new()
    ...
    .customize(Customize {
        carllerche_bytes_for_bytes: Some(true),
        carllerche_bytes_for_string: Some(true),
        ..Default::default()
    })
    .run()?;

or in .proto file:

import "rustproto.proto";

option (rustproto.carllerche_bytes_for_bytes_all) = true;
option (rustproto.carllerche_bytes_for_string_all) = true;

With these options enabled, fields of type bytes or string are generated as Bytes or Chars respectively. When CodedInputStream is constructed from Bytes object, fields of these types get subslices of original Bytes object, instead of being allocated on heap.

serde_derive support

(Only in master, not released yet)

Rust-protobuf can be used with serde.

To enable serde you need to:

  1. Enable serde option

with Customize when codegen is invoked programmatically:

with stable rust-protobuf:

protoc_rust::run(protoc_rust::Args {
    ...
    customize: Customize {
        serde_derive: Some(true),
        ..Default::default()
    },
});

with rust-protobuf from master:

protoc_rust::Args::new()
    ...
    .customize(Customize {
        serde_derive: Some(true),
        ..Default::default()
    })
    .run()?;

or in .proto file:

import "rustproto.proto";

option (rustproto.serde_derive_all) = true;

You may now Serialize and Deserialize messages:

let my_message = MyMessage::new();
serde_json::to_string(&my_message).unwrap();

Related projects

rust-protobuf's People

Contributors

stepancheg avatar texitoi avatar borntyping avatar meh avatar hansjorg avatar blei avatar tamird avatar busyjay avatar syakhmi avatar ealasu avatar tommilligan avatar robn avatar overvenus avatar jansegre avatar erickt avatar chinedufn avatar bonifaido avatar king6cong avatar bacek avatar thijsc avatar rajatgoel avatar yjh0502 avatar jamesray1 avatar miedzinski avatar dgalling avatar danburkert avatar ademidov avatar readmecritic avatar mehcode avatar scottlamb avatar

Stargazers

muuk avatar  avatar

Watchers

James Cloos avatar  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.