Documentation
¶
Overview ¶
Package protobuf reads Protobuf wire data with or without a schema.
NewParser walks raw wire format into an ordered field-number map, tracking each field's wire type; ShowRawTypes annotates that output the way CyberChef's Protobuf Decode does. CompileSchema compiles a .proto source so decoding can use real field names and types, and SchemaDecode applies it. The Protobuf Decode and Protobuf Encode operations are built on these.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompileSchema ¶
func CompileSchema(schema string) (protoreflect.MessageDescriptor, error)
CompileSchema compiles .proto text and returns the first top-level message descriptor (CyberChef's mainMessageName is the first message defined).
func SchemaDecode ¶
func SchemaDecode(data []byte, raw *jsonval.OMap, schema string, showUnknown, showTypes bool) ([]byte, error)
SchemaDecode decodes protobuf data against a .proto schema, mirroring protobufjs toObject conventions (bytes as strings, longs as numbers, enums as names, defaults included).
Types ¶
type Parser ¶
type Parser struct {
// FieldTypes maps a field number to its wire type (int), or to a nested
// map[string]any of sub-field types for submessages.
FieldTypes map[string]any
// contains filtered or unexported fields
}
Parser performs a schema-less decode of protobuf wire data, mirroring CyberChef's lib/Protobuf.mjs raw parser. It records per-field wire types (for the "Show Types" option) and treats a length-delimited field as a nested message when it parses cleanly, otherwise as a byte string.