protobuf

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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).

func ShowRawTypes

func ShowRawTypes(raw *jsonval.OMap, fieldTypes map[string]any) *jsonval.OMap

ShowRawTypes rewrites raw-decode field-number keys to include the wire type, recursing into submessages.

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.

func NewParser

func NewParser(data []byte) *Parser

NewParser returns a parser over raw wire data.

func (*Parser) Parse

func (p *Parser) Parse() (*jsonval.OMap, error)

Parse reads all fields into an ordered map keyed by field number.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL