grpcwire

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package grpcwire reads gRPC request messages without their schema: it splits a body into gRPC messages and finds the text in each protobuf message, for rules to inspect.

Protobuf's wire format doesn't say which length-delimited fields are strings, bytes or nested messages. A field whose bytes are a whole protobuf message is read as one (its fields get their own names); a field whose bytes are UTF-8 is text, whatever its characters. Some bytes are both, and give both. A group is read as a nested message. Binary bytes give their runs of readable text. Numbers outside a length-delimited field and anything that fails to parse give nothing.

Index

Constants

View Source
const FrameHeader = 5

FrameHeader is a gRPC message's prefix: a compressed flag (0 or 1) and the message length, 4 bytes big-endian.

View Source
const LongPath = "~"

LongPath ends a path cut to MaxName bytes: no ArgumentPattern has it.

View Source
const MaxName = 256

MaxName is the longest field path Fields gives, the longest an exclusion can name (ArgumentPattern): a longer one keeps its first MaxName-1 bytes and ends in LongPath, which no exclusion can name, so that one exclusion never covers every path cut to the same name.

Variables

View Source
var DefaultLimits = Limits{Depth: 16, Fields: 1024}

DefaultLimits are those the pipeline uses.

Functions

func Gunzip

func Gunzip(data []byte, limit int64) (out []byte, ok bool)

Gunzip decompresses a message compressed with grpc-encoding gzip, up to limit bytes. ok is false when data isn't gzip, or decompresses to more than limit bytes: then out is what fit.

Types

type Field

type Field struct {
	Name  string
	Value string
}

Field is text found in a message: Name is the path of field numbers from the message, dot-separated ("2.1": field 1 of the message in field 2).

func Fields

func Fields(msg []byte, s *grpcschema.Schema, t *grpcschema.Message, lim Limits, out []Field) (fields []Field, unknown int, ok bool)

Fields returns the text fields of msg, a protobuf message of type t of schema s, appended to out; unknown, the fields t doesn't describe; and whether the message parsed whole and stayed within lim (design 0013 §6).

Each field t describes is read by its kind: a string as text (as Strings reads UTF-8, a byte that isn't UTF-8 a space), bytes as text (bytesText): whole when they are mostly printable UTF-8 of at least 8 bytes (minBytesText), else by their runs of at least 12 readable characters (minBytesRun), a message or group by its type, one level deeper (a message also as text, as Strings reads one: whole when printable, else the runs between its fields), numbers as nothing, and a packed repeated number as bytes, or as unknown when it isn't a list of its kind's numbers. Fields are named by their proto names, joined by dots ("user.name"), without indexes; an extension "[package.extension]". An Any's value is read as the type its last type_url names, under the Any's name, when s has it and it is a message; else as Strings reads it.

What t doesn't describe is read as Strings reads it, named by number under the nearest name ("user.7"): a field number t doesn't have, a field sent with a wire type its kind doesn't take, and a message field whose bytes aren't a message. Every occurrence of a field is read, and every member of a oneof. The reading is charged against a budget of bytes read linear in msg (readBudget), and the text given against one of bytes of text (textBudget): past either, the message is over lim.

func Strings

func Strings(msg []byte, lim Limits, out []Field) (fields []Field, ok bool)

Strings returns the text fields of a protobuf message, appended to out, and reports whether the message parsed whole and stayed within lim. A message that doesn't parse gives what was found before the error. A panic while reading (it runs on an adapter's goroutine, which nothing else recovers) is a message not read whole, as one that doesn't parse.

type Limits

type Limits struct {
	// Depth is how deep nested messages are read.
	Depth int
	// Fields is how many text fields are returned.
	Fields int
}

Limits bound the work on one body.

type Message

type Message struct {
	// Compressed: the message is compressed with the call's grpc-encoding.
	Compressed bool
	// Data is the message, or as much of it as the body holds.
	Data []byte
	// Cut: the body ends inside the message.
	Cut bool
}

Message is one gRPC message of a body.

func Messages

func Messages(body []byte, truncated bool) (msgs []Message, ok bool)

Messages splits body into gRPC messages. ok is false when body isn't a sequence of messages: a bad flag, or a body that ends inside a prefix or a message while it is not truncated.

Jump to

Keyboard shortcuts

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