streamvisitor

package
v0.0.0-...-a171562 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLazyStreamVisitor

func NewLazyStreamVisitor(streamMessage proto.Message) func() *StreamVisitor

Types

type EOFCallback

type EOFCallback func() error

type InvalidTransitionCallback

type InvalidTransitionCallback func(from, to protoreflect.FieldNumber, allowed []protoreflect.FieldNumber, message proto.Message) error

InvalidTransitionCallback is a callback that is called when an invalid transition is attempted. 'message' is nil when 'to' is eofState.

type MessageCallback

type MessageCallback any

MessageCallback is a function with signature func(message someConcreteProtoMessage) error someConcreteProtoMessage must be the type passed to NewStreamVisitor().

type Stream

type Stream interface {
	RecvMsg(m any) error
}

Stream is a grpc.ServerStream or grpc.ClientStream.

type StreamVisitor

type StreamVisitor struct {
	// contains filtered or unexported fields
}

StreamVisitor allows to consume messages in a gRPC stream. Message order should follow the automata, defined on fields in a oneof group.

func NewStreamVisitor

func NewStreamVisitor(streamMessage proto.Message) (*StreamVisitor, error)

func (*StreamVisitor) Visit

func (s *StreamVisitor) Visit(stream Stream, opts ...StreamVisitorOption) error

type StreamVisitorOption

type StreamVisitorOption func(*svConfig) error

StreamVisitorOption is an option for the visitor. Must return nil or an error, compatible with the gRPC status package.

func WithCallback

func WithCallback(transitionTo protoreflect.FieldNumber, cb MessageCallback) StreamVisitorOption

WithCallback registers cb to be called when entering transitionTo when parsing the stream. Only one callback can be registered per target

func WithEOFCallback

func WithEOFCallback(cb EOFCallback) StreamVisitorOption

WithEOFCallback sets a callback for end of stream.

func WithNotExpectingToGet

func WithNotExpectingToGet(code codes.Code, transitionTo ...protoreflect.FieldNumber) StreamVisitorOption

WithNotExpectingToGet is used to list fields that the caller is not expecting to get during this Visit() invocation.

func WithStartState

func WithStartState(startState protoreflect.FieldNumber) StreamVisitorOption

WithStartState allows to specify a custom automata start state. The visitor then acts as if it has just visited field with startState number.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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