grpcproto

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: Apache-2.0 Imports: 5 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 EncodeGrpcMessage

func EncodeGrpcMessage(msg string) string

EncodeGrpcMessage is used to encode status code in header field "grpc-message". It does percent encoding and also replaces invalid utf-8 characters with Unicode replacement character.

It checks to see if each individual byte in msg is an allowable byte, and then either percent encoding or passing it through. When percent encoding, the byte is converted into hexadecimal notation with a '%' prepended.

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