Documentation
¶
Index ¶
- Variables
- func EncodeGrpcMessage(msg string) string
- func IsCompressed(msg []byte) bool
- func IsDataFrame(msg []byte) bool
- func IsEndOfStream(msg []byte) bool
- func IsMetadataFrame(msg []byte) bool
- func MakeMessageHeader(flags MessageFlags, length uint32) []byte
- func ValidateGRPCFrame(msg []byte) error
- type MessageFlags
Constants ¶
This section is empty.
Variables ¶
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 ¶ added in v0.2.2
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 ¶
IsCompressed returns true if the message header sets the compression flag.
func IsDataFrame ¶
IsDataFrame returns true if the message is a gRPC data frame. A data frame has its MSB unset.
func IsEndOfStream ¶
IsEndOfStream returns true if the header sets the EOS flag and the message is empty.
func IsMetadataFrame ¶
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 ¶
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.