grpcproto

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EndStreamHeader is a gRPC frame header that indicates EOS.
	// This is ok because the MSB of the data frame header will never be used by
	// the gRPC protocol. gRPC-Web utilizes it to distinguish between normal data and trailers,
	// which implies we may also use it for our own purposes.
	// We use it to indicate that the stream is complete.
	EndStreamHeader = []byte{metadataMask, 0, 0, 0, 0}
)

Functions

func IsCompressed

func IsCompressed(msg []byte) bool

IsCompressed returns true if the message header sets the compression flag.

func IsDataFrame

func IsDataFrame(msg []byte) bool

IsDataFrame returns true if the message is a gRPC data frame. A data frame has its MSB unset.

func IsEndOfStream

func IsEndOfStream(msg []byte) bool

IsEndOfStream returns true if the header sets the EOS flag and the message is empty.

func IsMetadataFrame

func IsMetadataFrame(msg []byte) bool

IsMetadataFrame returns true if the message is a gRPC metadata frame. A metadata frame has its MSB set.

func MakeMessageHeader

func MakeMessageHeader(flags MessageFlags, length uint32) []byte

MakeMessageHeader creates a gRPC message frame header based on the given flags and message length.

func ValidateGRPCFrame

func ValidateGRPCFrame(msg []byte) error

ValidateGRPCFrame ensures the message is a well-formed gRPC message. A well-formed message has at least a well-formed header and a length equal to the declared length.

Types

type MessageFlags

type MessageFlags uint8

MessageFlags type represents the flags set in the header of a gRPC data frame.

const (
	// MessageHeaderLength is the length of a gRPC data frame message header.
	MessageHeaderLength = 5

	// MetadataFlags is flags with the MSB set to 1 to indicate a metadata gRPC message.
	MetadataFlags MessageFlags = metadataMask
)

func ParseMessageHeader

func ParseMessageHeader(header []byte) (MessageFlags, uint32, error)

ParseMessageHeader parses a byte slice into a gRPC data frame header.

Jump to

Keyboard shortcuts

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