grpcwire

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 9 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.

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