Documentation ¶
Index ¶
- func DynamicLocallyKnownMessageToGeneratedMessage(dynamicMessage *dynamicpb.Message) (proto.Message, error)
- func GetKey(x proto.Message) (string, error)
- func GetKeyForItem(item *api.Item) (string, error)
- func GetKeyForItemUsingModelRegistry(item *api.Item, modelRegistry Registry) (string, error)
- func GetKeyUsingModelRegistry(message proto.Message, modelRegistry Registry) (string, error)
- func GetName(x proto.Message) (string, error)
- func Key(x proto.Message) string
- func MarshalItem(pb proto.Message) (*api.Item, error)
- func MarshalItemUsingModelRegistry(pb proto.Message, modelRegistry Registry) (*api.Item, error)
- func Name(x proto.Message) string
- func RegisterRemote(remoteModel *ModelInfo, remoteRegistry *RemoteRegistry)
- func UnmarshalItem(item *api.Item) (proto.Message, error)
- func UnmarshalItemUsingModelRegistry(item *api.Item, modelRegistry Registry) (proto.Message, error)
- type KnownModel
- func GetModel(name string) (KnownModel, error)
- func GetModelFor(x proto.Message) (KnownModel, error)
- func GetModelForItem(item *api.Item) (KnownModel, error)
- func GetModelForKey(key string) (KnownModel, error)
- func GetModelFromModelRegistryForItem(item *api.Item, modelRegistry Registry) (KnownModel, error)
- func GetModelFromRegistry(name string, modelRegistry Registry) (KnownModel, error)
- func GetModelFromRegistryFor(x proto.Message, modelRegistry Registry) (KnownModel, error)
- func Register(pb proto.Message, spec Spec, opts ...ModelOption) KnownModel
- func RegisteredModels() []KnownModel
- type LocalRegistry
- func (r *LocalRegistry) GetModel(name string) (KnownModel, error)
- func (r *LocalRegistry) GetModelFor(x interface{}) (KnownModel, error)
- func (r *LocalRegistry) GetModelForKey(key string) (KnownModel, error)
- func (r *LocalRegistry) MessageTypeRegistry() *protoregistry.Types
- func (r *LocalRegistry) Register(x interface{}, spec Spec, opts ...ModelOption) (KnownModel, error)
- func (r *LocalRegistry) RegisteredModels() []KnownModel
- type LocallyKnownModel
- func (m *LocallyKnownModel) GoType() string
- func (m *LocallyKnownModel) InstanceName(x interface{}) (string, error)
- func (m *LocallyKnownModel) IsKeyValid(key string) bool
- func (m *LocallyKnownModel) KeyPrefix() string
- func (m *LocallyKnownModel) LocalGoType() reflect.Type
- func (m *LocallyKnownModel) ModelDetail() *generic.ModelDetail
- func (m *LocallyKnownModel) Name() string
- func (m *LocallyKnownModel) NameTemplate() string
- func (m *LocallyKnownModel) NewInstance() proto.Message
- func (m *LocallyKnownModel) ParseKey(key string) (name string, valid bool)
- func (m *LocallyKnownModel) PkgPath() string
- func (m *LocallyKnownModel) ProtoFile() string
- func (m *LocallyKnownModel) ProtoName() string
- func (m *LocallyKnownModel) Spec() *Spec
- func (m *LocallyKnownModel) StripKeyPrefix(key string) string
- type ModelInfo
- type ModelOption
- type NameFunc
- type Registry
- type RemoteRegistry
- func (r *RemoteRegistry) GetModel(name string) (KnownModel, error)
- func (r *RemoteRegistry) GetModelFor(x interface{}) (KnownModel, error)
- func (r *RemoteRegistry) GetModelForKey(key string) (KnownModel, error)
- func (r *RemoteRegistry) MessageTypeRegistry() *protoregistry.Types
- func (r *RemoteRegistry) Register(model interface{}, spec Spec, opts ...ModelOption) (KnownModel, error)
- func (r *RemoteRegistry) RegisteredModels() []KnownModel
- type RemotelyKnownModel
- func (m *RemotelyKnownModel) GoType() string
- func (m *RemotelyKnownModel) InstanceName(x interface{}) (string, error)
- func (m *RemotelyKnownModel) IsKeyValid(key string) bool
- func (m *RemotelyKnownModel) KeyPrefix() string
- func (m *RemotelyKnownModel) LocalGoType() reflect.Type
- func (m *RemotelyKnownModel) ModelDetail() *api.ModelDetail
- func (m *RemotelyKnownModel) Name() string
- func (m *RemotelyKnownModel) NameTemplate() string
- func (m *RemotelyKnownModel) NewInstance() proto.Message
- func (m *RemotelyKnownModel) ParseKey(key string) (name string, valid bool)
- func (m *RemotelyKnownModel) PkgPath() string
- func (m *RemotelyKnownModel) ProtoFile() string
- func (m *RemotelyKnownModel) ProtoName() string
- func (m *RemotelyKnownModel) Spec() *Spec
- func (m *RemotelyKnownModel) StripKeyPrefix(key string) string
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DynamicLocallyKnownMessageToGeneratedMessage ¶ added in v3.3.0
func DynamicLocallyKnownMessageToGeneratedMessage(dynamicMessage *dynamicpb.Message) (proto.Message, error)
DynamicLocallyKnownMessageToGeneratedMessage converts locally registered/known proto dynamic message to corresponding statically generated proto message. This function will fail when there is no registration of statically-generated proto message, i.e. dynamic message refers to remotely known model. This conversion method should help handling dynamic proto messages in mostly protoc-generated proto message oriented codebase (i.e. help for type conversions to named, help handle missing data fields as seen in generated proto messages,...)
func GetKey ¶
GetKey returns complete key for given model, including key prefix defined by model specification. It returns error if given model is not registered.
func GetKeyForItem ¶
GetKeyForItem returns key for given item.
func GetKeyForItemUsingModelRegistry ¶ added in v3.3.0
GetKeyForItem returns key for given item (using given model registry)
func GetKeyUsingModelRegistry ¶ added in v3.3.0
GetKeyUsingModelRegistry returns complete key for given model from given model registry, including key prefix defined by model specification. It returns error if given model is not registered.
func GetName ¶
GetName returns instance name for given model. It returns error if given model is not registered.
func MarshalItem ¶
MarshalItem is helper function for marshalling model instance into item
func MarshalItemUsingModelRegistry ¶ added in v3.3.0
MarshalItemUsingModelRegistry is helper function for marshalling model instance into item (using given model registry)
func RegisterRemote ¶ added in v3.3.0
func RegisterRemote(remoteModel *ModelInfo, remoteRegistry *RemoteRegistry)
RegisterRemote registers remotely known model in given RemoteRegistry
func UnmarshalItem ¶
UnmarshalItem is helper function for unmarshalling items.
Types ¶
type KnownModel ¶
type KnownModel interface { // Spec returns model specification for the model. Spec() *Spec // ModelDetail returns descriptor for the model. ModelDetail() *generic.ModelDetail // NewInstance creates new instance value for model type. NewInstance() proto.Message // ProtoName returns proto message name registered with the model. ProtoName() string // ProtoFile returns proto file name for the model. ProtoFile() string // NameTemplate returns name template for the model. NameTemplate() string // GoType returns go type for the model. GoType() string // LocalGoType returns reflect go type for the model. The reflect type can be retrieved only // for locally registered model that provide locally known go types. The remotely retrieved model // can't provide reflect type so if known model information is retrieved remotely, this method // will return nil. LocalGoType() reflect.Type // PkgPath returns package import path for the model definition. PkgPath() string // Name returns name for the model. Name() string // KeyPrefix returns key prefix for the model. KeyPrefix() string // ParseKey parses the given key and returns item name // or returns empty name and valid as false if the key is not valid. ParseKey(key string) (name string, valid bool) // IsKeyValid returns true if given key is valid for this model. IsKeyValid(key string) bool // StripKeyPrefix returns key with prefix stripped. StripKeyPrefix(key string) string // InstanceName computes message name for given proto message using name template (if present). InstanceName(x interface{}) (string, error) }
KnownModel represents a registered model
func GetModel ¶
func GetModel(name string) (KnownModel, error)
GetModel returns registered model for given model name.
func GetModelFor ¶
func GetModelFor(x proto.Message) (KnownModel, error)
GetModelFor returns model registered in DefaultRegistry for given proto message.
func GetModelForItem ¶
func GetModelForItem(item *api.Item) (KnownModel, error)
GetModelForItem returns model for given item.
func GetModelForKey ¶
func GetModelForKey(key string) (KnownModel, error)
GetModelForKey returns model registered in DefaultRegistry which matches key.
func GetModelFromModelRegistryForItem ¶ added in v3.3.0
func GetModelFromModelRegistryForItem(item *api.Item, modelRegistry Registry) (KnownModel, error)
GetModelFromModelRegistryForItem returns model for given item (using given model registry)
func GetModelFromRegistry ¶ added in v3.3.0
func GetModelFromRegistry(name string, modelRegistry Registry) (KnownModel, error)
GetModelFromRegistry returns registered model in given registry for given model name.
func GetModelFromRegistryFor ¶ added in v3.3.0
func GetModelFromRegistryFor(x proto.Message, modelRegistry Registry) (KnownModel, error)
GetModelFromRegistryFor returns model registered in modelRegistry for given proto message
func Register ¶
func Register(pb proto.Message, spec Spec, opts ...ModelOption) KnownModel
Register registers model in DefaultRegistry.
func RegisteredModels ¶
func RegisteredModels() []KnownModel
RegisteredModels returns models registered in the DefaultRegistry.
type LocalRegistry ¶ added in v3.3.0
type LocalRegistry struct {
// contains filtered or unexported fields
}
LocalRegistry defines model registry for managing registered local models. Local models are locally compiled into the program binary and hence some additional information in compare to remote models, i.e. go type.
func (*LocalRegistry) GetModel ¶ added in v3.3.0
func (r *LocalRegistry) GetModel(name string) (KnownModel, error)
GetModel returns registered model for the given model name or error if model is not found.
func (*LocalRegistry) GetModelFor ¶ added in v3.3.0
func (r *LocalRegistry) GetModelFor(x interface{}) (KnownModel, error)
GetModelFor returns registered model for the given proto message.
func (*LocalRegistry) GetModelForKey ¶ added in v3.3.0
func (r *LocalRegistry) GetModelForKey(key string) (KnownModel, error)
GetModelForKey returns registered model for the given key or error.
func (*LocalRegistry) MessageTypeRegistry ¶ added in v3.3.0
func (r *LocalRegistry) MessageTypeRegistry() *protoregistry.Types
MessageTypeRegistry creates new message type registry from registered proto messages
func (*LocalRegistry) Register ¶ added in v3.3.0
func (r *LocalRegistry) Register(x interface{}, spec Spec, opts ...ModelOption) (KnownModel, error)
Register registers either a protobuf message known at compile-time together with the given model specification, or a remote model represented by an instance of ModelInfo obtained via KnownModels RPC from MetaService. While the former case is prevalent, the latter option is useful for scenarios with multiple agents and configuration requests being proxied from one to another (remote model registered into LocalRegistry may act as a proxy for the agent from which it was learned). If spec.Class is unset then it defaults to 'config'.
func (*LocalRegistry) RegisteredModels ¶ added in v3.3.0
func (r *LocalRegistry) RegisteredModels() []KnownModel
RegisteredModels returns all registered modules.
type LocallyKnownModel ¶ added in v3.3.0
type LocallyKnownModel struct {
// contains filtered or unexported fields
}
LocallyKnownModel represents a registered local model (local model has go types compiled into program binary)
func (*LocallyKnownModel) GoType ¶ added in v3.3.0
func (m *LocallyKnownModel) GoType() string
GoType returns go type for the model.
func (*LocallyKnownModel) InstanceName ¶ added in v3.3.0
func (m *LocallyKnownModel) InstanceName(x interface{}) (string, error)
InstanceName computes message name for given proto message using name template (if present).
func (*LocallyKnownModel) IsKeyValid ¶ added in v3.3.0
func (m *LocallyKnownModel) IsKeyValid(key string) bool
IsKeyValid returns true if given key is valid for this model.
func (*LocallyKnownModel) KeyPrefix ¶ added in v3.3.0
func (m *LocallyKnownModel) KeyPrefix() string
KeyPrefix returns key prefix for the model.
func (*LocallyKnownModel) LocalGoType ¶ added in v3.3.0
func (m *LocallyKnownModel) LocalGoType() reflect.Type
LocalGoType returns reflect go type for the model.
func (*LocallyKnownModel) ModelDetail ¶ added in v3.3.0
func (m *LocallyKnownModel) ModelDetail() *generic.ModelDetail
ModelDetail returns descriptor for the model.
func (*LocallyKnownModel) Name ¶ added in v3.3.0
func (m *LocallyKnownModel) Name() string
Name returns name for the model.
func (*LocallyKnownModel) NameTemplate ¶ added in v3.3.0
func (m *LocallyKnownModel) NameTemplate() string
NameTemplate returns name template for the model.
func (*LocallyKnownModel) NewInstance ¶ added in v3.3.0
func (m *LocallyKnownModel) NewInstance() proto.Message
NewInstance creates new instance value for model type.
func (*LocallyKnownModel) ParseKey ¶ added in v3.3.0
func (m *LocallyKnownModel) ParseKey(key string) (name string, valid bool)
ParseKey parses the given key and returns item name or returns empty name and valid as false if the key is not valid.
func (*LocallyKnownModel) PkgPath ¶ added in v3.3.0
func (m *LocallyKnownModel) PkgPath() string
PkgPath returns package import path for the model definition.
func (*LocallyKnownModel) ProtoFile ¶ added in v3.3.0
func (m *LocallyKnownModel) ProtoFile() string
ProtoFile returns proto file name for the model.
func (*LocallyKnownModel) ProtoName ¶ added in v3.3.0
func (m *LocallyKnownModel) ProtoName() string
ProtoName returns proto message name registered with the model.
func (*LocallyKnownModel) Spec ¶ added in v3.3.0
func (m *LocallyKnownModel) Spec() *Spec
Spec returns model specification for the model.
func (*LocallyKnownModel) StripKeyPrefix ¶ added in v3.3.0
func (m *LocallyKnownModel) StripKeyPrefix(key string) string
StripKeyPrefix returns key with prefix stripped.
type ModelInfo ¶ added in v3.3.0
type ModelInfo struct { *generic.ModelDetail // MessageDescriptor is the proto message descriptor of the message represented by this ModelInfo struct MessageDescriptor protoreflect.MessageDescriptor }
ModelInfo represents model information retrieved using meta service
type ModelOption ¶
type ModelOption func(*modelOptions)
ModelOption defines function type which sets model options.
func WithNameTemplate ¶
func WithNameTemplate(t string) ModelOption
WithNameTemplate returns option for models which sets function for generating name of instances using custom template.
type Registry ¶
type Registry interface { // GetModel returns registered model for the given model name // or error if model is not found. GetModel(name string) (KnownModel, error) // GetModelFor returns registered model for the given proto message. GetModelFor(x interface{}) (KnownModel, error) // GetModelForKey returns registered model for the given key or error. GetModelForKey(key string) (KnownModel, error) // MessageTypeRegistry creates new message type registry from registered proto messages MessageTypeRegistry() *protoregistry.Types // RegisteredModels returns all registered modules. RegisteredModels() []KnownModel // Register registers either a protobuf message known at compile-time together // with the given model specification (for LocalRegistry), // or a remote model represented by an instance of ModelInfo obtained via KnownModels RPC from MetaService // (for RemoteRegistry or also for LocalRegistry but most likely just proxied to a remote agent). // If spec.Class is unset, then it defaults to 'config'. Register(x interface{}, spec Spec, opts ...ModelOption) (KnownModel, error) }
Registry defines model registry for managing registered models
var ( // DefaultRegistry represents a global registry for local models (models known in compile time) DefaultRegistry Registry = NewRegistry() )
type RemoteRegistry ¶ added in v3.3.0
type RemoteRegistry struct {
// contains filtered or unexported fields
}
RemoteRegistry defines model registry for managing registered remote models. The remote model have no included compiled code in program binary so only information available are from remote sources (i.e. generic.Client's known models)
func NewRemoteRegistry ¶ added in v3.3.0
func NewRemoteRegistry() *RemoteRegistry
NewRemoteRegistry returns initialized RemoteRegistry.
func (*RemoteRegistry) GetModel ¶ added in v3.3.0
func (r *RemoteRegistry) GetModel(name string) (KnownModel, error)
GetModel returns registered model for the given model name or error if model is not found.
func (*RemoteRegistry) GetModelFor ¶ added in v3.3.0
func (r *RemoteRegistry) GetModelFor(x interface{}) (KnownModel, error)
GetModelFor returns registered model for the given proto message.
func (*RemoteRegistry) GetModelForKey ¶ added in v3.3.0
func (r *RemoteRegistry) GetModelForKey(key string) (KnownModel, error)
GetModelForKey returns registered model for the given key or error.
func (*RemoteRegistry) MessageTypeRegistry ¶ added in v3.3.0
func (r *RemoteRegistry) MessageTypeRegistry() *protoregistry.Types
MessageTypeRegistry creates new message type registry from registered proto messages
func (*RemoteRegistry) Register ¶ added in v3.3.0
func (r *RemoteRegistry) Register(model interface{}, spec Spec, opts ...ModelOption) (KnownModel, error)
Register registers remote model ModelInfo (given as interface{} for common register interface flexibility). The given spec and options are already in ModelInfo and therefore these input arguments are ignored.
func (*RemoteRegistry) RegisteredModels ¶ added in v3.3.0
func (r *RemoteRegistry) RegisteredModels() []KnownModel
RegisteredModels returns all registered modules.
type RemotelyKnownModel ¶ added in v3.3.0
type RemotelyKnownModel struct {
// contains filtered or unexported fields
}
RemotelyKnownModel represents a registered remote model (remote model has only information about model from remote source, i.e. missing go type because VPP-Agent meta service doesn't provide it)
func (*RemotelyKnownModel) GoType ¶ added in v3.3.0
func (m *RemotelyKnownModel) GoType() string
GoType returns go type for the model.
func (*RemotelyKnownModel) InstanceName ¶ added in v3.3.0
func (m *RemotelyKnownModel) InstanceName(x interface{}) (string, error)
InstanceName computes message name for given proto message using name template (if present).
func (*RemotelyKnownModel) IsKeyValid ¶ added in v3.3.0
func (m *RemotelyKnownModel) IsKeyValid(key string) bool
IsKeyValid returns true if given key is valid for this model.
func (*RemotelyKnownModel) KeyPrefix ¶ added in v3.3.0
func (m *RemotelyKnownModel) KeyPrefix() string
KeyPrefix returns key prefix for the model.
func (*RemotelyKnownModel) LocalGoType ¶ added in v3.3.0
func (m *RemotelyKnownModel) LocalGoType() reflect.Type
LocalGoType should returns reflect go type for the model, but remotely known model doesn't have locally known reflect go type. It always returns nil.
func (*RemotelyKnownModel) ModelDetail ¶ added in v3.3.0
func (m *RemotelyKnownModel) ModelDetail() *api.ModelDetail
ModelDetail returns descriptor for the model.
func (*RemotelyKnownModel) Name ¶ added in v3.3.0
func (m *RemotelyKnownModel) Name() string
Name returns name for the model.
func (*RemotelyKnownModel) NameTemplate ¶ added in v3.3.0
func (m *RemotelyKnownModel) NameTemplate() string
NameTemplate returns name template for the model.
func (*RemotelyKnownModel) NewInstance ¶ added in v3.3.0
func (m *RemotelyKnownModel) NewInstance() proto.Message
NewInstance creates new instance value for model type. Due to missing go type for remote models, the created instance won't have the same go type as in case of local models, but dynamic proto message's go type (the proto descriptor will be the same).
func (*RemotelyKnownModel) ParseKey ¶ added in v3.3.0
func (m *RemotelyKnownModel) ParseKey(key string) (name string, valid bool)
ParseKey parses the given key and returns item name or returns empty name and valid as false if the key is not valid.
func (*RemotelyKnownModel) PkgPath ¶ added in v3.3.0
func (m *RemotelyKnownModel) PkgPath() string
PkgPath returns package import path for the model definition.
func (*RemotelyKnownModel) ProtoFile ¶ added in v3.3.0
func (m *RemotelyKnownModel) ProtoFile() string
ProtoFile returns proto file name for the model.
func (*RemotelyKnownModel) ProtoName ¶ added in v3.3.0
func (m *RemotelyKnownModel) ProtoName() string
ProtoName returns proto message name registered with the model.
func (*RemotelyKnownModel) Spec ¶ added in v3.3.0
func (m *RemotelyKnownModel) Spec() *Spec
Spec returns model specification for the model.
func (*RemotelyKnownModel) StripKeyPrefix ¶ added in v3.3.0
func (m *RemotelyKnownModel) StripKeyPrefix(key string) string
StripKeyPrefix returns key with prefix stripped.