Skip to main content

Module text

Module text 

Source
Available on crate feature text only.
Expand description

Textproto (text format) encoding and decoding.

The protobuf text format is a human-readable debug representation:

name: "Alice"
id: 42
address {
  street: "1 High St"
  city: "London"
}
tags: "a"
tags: "b"

It is not a stable wire format — the spec permits implementations to vary whitespace, field ordering, and float formatting. Use binary or JSON for interchange. Textproto is for config files, golden-file tests, and logging.

§Usage

Generated message types implement TextFormat when the text feature is enabled in codegen. The convenience functions cover the common cases:

use buffa::text::{encode_to_string, decode_from_str};

let s = encode_to_string(&my_msg);
let parsed: MyMsg = decode_from_str(&s)?;

For streaming or reuse, use TextEncoder / TextDecoder directly.

§no_std

Fully no_std + alloc. No external dependencies beyond the runtime crate itself.

Structs§

ParseError
An error encountered while parsing textproto input.
TextDecoder
Stateful textproto reader.
TextEncoder
Stateful textproto writer.
Token
A single textproto token, borrowing from the input.
Tokenizer
Stateful textproto tokenizer.

Enums§

NameKind
Secondary classification of a TokenKind::Name token.
ParseErrorKind
The category of textproto parse error.
ScalarKind
Secondary classification of a TokenKind::Scalar token.
TokenKind
The kind of a textproto token.
UnescapeError
Error returned by unescape and unescape_str.

Traits§

TextFormat
Textproto serialization for a Message type.

Functions§

decode_from_str
Decode a message from a textproto string.
encode_to_string
Encode a message as a single-line textproto string.
encode_to_string_pretty
Encode a message as a multi-line textproto string with 2-space indent.
escape_bytes
Write bytes as a double-quoted textproto string literal to w.
escape_str
Write s as a double-quoted textproto string literal to w, preserving multi-byte UTF-8 codepoints as-is.
merge_from_str
Merge a textproto string into an existing message.
unescape
Unescape a textproto string token — one or more adjacent quoted literals — into a byte vector.
unescape_str
Unescape a textproto string token and validate as UTF-8.