Documentation
¶
Overview ¶
Package stencil helps to download and refresh protobuf descriptors from remote server and provides helper functions to get protobuf schema descriptors and can parse the messages dynamically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( //ErrNotFound default sentinel error if proto not found ErrNotFound = errors.New("not found") //ErrInvalidDescriptor is for when descriptor does not match the message ErrInvalidDescriptor = errors.New("invalid descriptor") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Parse parses protobuf message from wire format to protoreflect.ProtoMessage given fully qualified name of proto message.
// Returns ErrNotFound error if given class name is not found
Parse(string, []byte) (protoreflect.ProtoMessage, error)
// Serialize serializes data to bytes given fully qualified name of proto message.
// Returns ErrNotFound error if given class name is not found
Serialize(string, interface{}) ([]byte, error)
// GetDescriptor returns protoreflect.MessageDescriptor given fully qualified proto java class name
GetDescriptor(string) (protoreflect.MessageDescriptor, error)
// Close stops background refresh if configured.
Close()
// Refresh loads new values from specified url. If the schema is already fetched, the previous value
// will continue to be used by Parse methods while the new value is loading.
// If schemas not loaded, then this function will block until the value is loaded.
Refresh()
}
Client provides utility functions to parse protobuf messages at runtime. protobuf messages can be identified by specifying fully qualified generated proto java class name.
type HTTPOptions ¶
type HTTPOptions struct {
// Timeout specifies a time limit for requests made by this client. Default to 10s.
// `0` duration not allowed. Client will set to default value (i.e. 10s).
Timeout time.Duration
// Headers provide extra headers to be added in requests made by this client
Headers map[string]string
}
HTTPOptions options for http client
type Options ¶
type Options struct {
// AutoRefresh boolean to enable or disable autorefresh. Default to false
AutoRefresh bool
// RefreshInterval refresh interval to fetch descriptor file from server. Default to 12h.
// `0` duration not allowed. Client will set to default value (i.e. 12h).
RefreshInterval time.Duration
// HTTPOptions options for http client
HTTPOptions
// RefreshStrategy refresh strategy to use while fetching schema.
// Default strategy set to `stencil.LongPollingRefresh` strategy
RefreshStrategy
// Logger is the interface used to get logging from stencil internals.
Logger
}
Options options for stencil client
type RefreshStrategy ¶
type RefreshStrategy int
RefreshStrategy clients can configure which refresh strategy to use to download latest schema. Default is LongPollingRefresh strategy
const ( // LongPollingRefresh this refresh strategy tries to update schema on every specified interval. // It doesn't check for schema changes explicitly. LongPollingRefresh RefreshStrategy = iota // VersionBasedRefresh this refresh strategy utilizes versions API provided by Stencil Server. // If new version is available then only schema cache would be updated. VersionBasedRefresh )
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver protobuf type resolver
func NewResolver ¶
NewResolver parses protobuf fileDescriptorSet schema returns type Resolver
func (*Resolver) Get ¶
func (r *Resolver) Get(className string) (protoreflect.MessageType, bool)
Get returns protobuf messageType for given proto message fullname. If java package file option is added, then message classname would be javapackage + message name. If java package file option is not defined then className would be proto message fullName.
func (*Resolver) GetTypeResolver ¶
func (r *Resolver) GetTypeResolver() *protoregistry.Types
GetTypeResolver returns type resolver