protobuf_to_json/
lib.rs

1//! # protobuf-to-json
2//!
3//! A parser that converts arbitrary protobuf data to json
4//!
5//! ## Features
6//! * No schema required
7//! * Use field number as json key
8//! * Configurable bytes encoding (base64, hex, byte array, etc.)
9//! * Guess length-delimited value types (string, nested message, bytes)
10//!
11//! ## Limitations
12//! * Length-delimited value type is guessed based on content. It may not always be correct.
13//! * Repeated fields (with the same field number) may not be grouped into arrays when only one field is parsed.
14//!
15//! ## Examples
16//!
17//! ``` rust
18//! use protobuf_to_json::Parser;
19//! use hex_literal::hex;
20//! use serde_json::json;
21//!
22//! let data = hex!("0d1c0000001203596f751a024d65202b2a0a0a066162633132331200");
23//! let parser = Parser::new();
24//! let json = parser.parse(&data).unwrap();
25//! let expected = json!({
26//!     "1": 28,
27//!     "2": "You",
28//!     "3": "Me",
29//!     "4": 43,
30//!     "5": {
31//!         "1": "abc123",
32//!         "2": ""
33//!     }
34//! });
35//! assert_eq!(json, expected);
36//! ```
37//!
38
39mod message;
40mod parser;
41mod varint;
42
43pub use message::{Field, FieldValue, Message};
44pub use parser::{BytesEncoding, Parser};
45pub use varint::decode_var;