grpc

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ContentType = "application/grpc+proto"

ContentType is the Content-Type header value for gRPC requests.

View Source
const MaxMessageSize int64 = core.MaxGRPCMessageBytes

MaxMessageSize is the maximum encoded or decoded gRPC message size.

Variables

This section is empty.

Functions

func AcceptHeader

func AcceptHeader() core.KeyVal[string]

AcceptHeader returns the Accept header for gRPC requests.

func CheckedFrameLength added in v0.28.0

func CheckedFrameLength(messageLength int64) (int64, error)

CheckedFrameLength validates the message length and returns the complete wire-frame length. Keeping the addition here prevents every framing caller from having to repeat overflow checks before allocating or writing headers.

func DecodeMessage added in v0.28.0

func DecodeMessage(data []byte, compressed bool, encoding string) ([]byte, error)

DecodeMessage decompresses one gRPC message when its compressed flag is set. Decompression is bounded so a small compressed payload cannot expand beyond the gRPC message limit.

func DecodeMessageLimited added in v0.28.0

func DecodeMessageLimited(data []byte, compressed bool, encoding string, max int64) ([]byte, error)

DecodeMessageLimited is DecodeMessage with a caller-supplied decoded-size limit. Reflection uses this to enforce its aggregate limit before retaining another decompressed response.

func Frame

func Frame(data []byte, compressed bool) []byte

Frame wraps a valid message in gRPC length-prefixed format. Format: [compressed:1][length:4][data]. It returns nil when data cannot be represented by a strict gRPC frame; callers that need the reason should use FrameChecked.

func FrameChecked added in v0.28.0

func FrameChecked(data []byte, compressed bool) ([]byte, error)

FrameChecked wraps a message in gRPC length-prefixed format and rejects messages that cannot be represented by the wire format or exceed the configured message limit.

func Headers

func Headers() []core.KeyVal[string]

Headers returns the standard headers for gRPC requests.

func ReadFrame added in v0.17.0

func ReadFrame(r io.Reader) ([]byte, bool, error)

ReadFrame reads a single gRPC length-prefixed frame from the reader. Returns the message data, whether it was compressed, and any error. Returns io.EOF when the reader has no more data.

func ReadFrameBody added in v0.28.0

func ReadFrameBody(r io.Reader, length uint32, max int64) ([]byte, error)

ReadFrameBody reads a frame payload after ReadFrameHeader. max is checked before allocation so callers can enforce an operation-wide limit without briefly allocating an over-limit message.

func ReadFrameHeader added in v0.28.0

func ReadFrameHeader(r io.Reader) (uint32, bool, error)

ReadFrameHeader reads and validates the five-byte gRPC frame header. It returns io.EOF when the reader has no more data. The payload is not read, which lets callers enforce an aggregate limit before allocating it.

func Unframe

func Unframe(data []byte) ([]byte, bool, error)

Unframe extracts a gRPC length-prefixed message from the data. Returns the message data and whether it was compressed.

Types

type Code

type Code int

Code represents a gRPC status code.

const (
	OK                 Code = 0
	Canceled           Code = 1
	Unknown            Code = 2
	InvalidArgument    Code = 3
	DeadlineExceeded   Code = 4
	NotFound           Code = 5
	AlreadyExists      Code = 6
	PermissionDenied   Code = 7
	ResourceExhausted  Code = 8
	FailedPrecondition Code = 9
	Aborted            Code = 10
	OutOfRange         Code = 11
	Unimplemented      Code = 12
	Internal           Code = 13
	Unavailable        Code = 14
	DataLoss           Code = 15
	Unauthenticated    Code = 16
)

gRPC status codes.

func (Code) String

func (c Code) String() string

String returns the name of the status code.

type Status

type Status struct {
	Code    Code
	Message string
}

Status represents a gRPC status.

func ParseStatus

func ParseStatus(grpcStatus, grpcMessage string) *Status

ParseStatus parses gRPC status from HTTP trailers.

func (*Status) Error

func (s *Status) Error() string

func (*Status) OK

func (s *Status) OK() bool

OK returns true if the status represents success.

Jump to

Keyboard shortcuts

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