Documentation ¶
Overview ¶
Package protobuf provides a bridge between resources and protobuf interface.
Index ¶
- func CreateResource(resourceType resource.Type) (resource.Resource, error)
- func ProtoMarshal(m proto.Message) ([]byte, error)
- func ProtoUnmarshal(b []byte, m proto.Message) error
- func RegisterDynamic[R DeepCopyable[R], T any, RS TypedResource[T, R]](resourceType resource.Type, r RS) error
- func RegisterResource[T any, R Res[T]](resourceType resource.Type, _ R) error
- func UnmarshalResource(r *Resource) (resource.Resource, error)
- type DeepCopyable
- type FromResourceOption
- type FromResourceOptions
- type ProtoMarshaler
- type ProtoUnmarshaler
- type Res
- type Resource
- type ResourceSpec
- func (spec ResourceSpec[T, S]) DeepCopy() ResourceSpec[T, S]
- func (spec *ResourceSpec[T, S]) Equal(other interface{}) bool
- func (spec *ResourceSpec[T, S]) GetValue() proto.Message
- func (spec *ResourceSpec[T, S]) MarshalJSON() ([]byte, error)
- func (spec *ResourceSpec[T, S]) MarshalProto() ([]byte, error)
- func (spec *ResourceSpec[T, S]) UnmarshalJSON(bytes []byte) error
- func (spec *ResourceSpec[T, S]) UnmarshalProto(protoBytes []byte) error
- type ResourceUnmarshaler
- type Spec
- type TypedResource
- type YAMLResource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateResource ¶
CreateResource creates an empty resource for a type.
func ProtoMarshal ¶
ProtoMarshal returns the wire-format encoding of m.
func ProtoUnmarshal ¶
ProtoUnmarshal parses the wire-format message in b and places the result in m. The provided message must be mutable (e.g., a non-nil pointer to a message).
func RegisterDynamic ¶
func RegisterDynamic[R DeepCopyable[R], T any, RS TypedResource[T, R]](resourceType resource.Type, r RS) error
RegisterDynamic creates a mapping between resource type and its protobuf marshaller and unmarshaller. It relies on TypedSpec returning Spec struct `with protobuf:<n>` tags.
func RegisterResource ¶
RegisterResource creates a mapping between resource type and its protobuf unmarshaller.
Types ¶
type DeepCopyable ¶
type DeepCopyable[T any] interface { DeepCopy() T }
DeepCopyable is a duplicate of github.com/cosi-project/runtime/pkg/resource/typed.DeepCopyable to prevent import cycles.
type FromResourceOption ¶ added in v0.2.0
type FromResourceOption func(*FromResourceOptions)
FromResourceOption is an option for FromResource.
func WithoutYAML ¶ added in v0.2.0
func WithoutYAML() FromResourceOption
WithoutYAML disables YAML spec.
type FromResourceOptions ¶ added in v0.2.0
type FromResourceOptions struct {
NoYAML bool
}
FromResourceOptions is a set of options for FromResource.
type ProtoMarshaler ¶
ProtoMarshaler is an interface which should be implemented by Resource spec to support conversion to protobuf.Resource.
type ProtoUnmarshaler ¶
ProtoUnmarshaler is an interface which should be implemented by Resource spec to support conversion from protobuf.Resource.
type Res ¶ added in v0.2.0
type Res[T any] interface { *T ResourceUnmarshaler resource.Resource }
Res is type parameter constraint for RegisterResource.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource which can be marshaled and unmarshaled from protobuf.
func FromResource ¶
func FromResource(r resource.Resource, opts ...FromResourceOption) (*Resource, error)
FromResource converts a resource which supports spec protobuf marshaling to protobuf.Resource.
func (*Resource) Unmarshal ¶
func (r *Resource) Unmarshal(res ResourceUnmarshaler) error
Unmarshal into specific Resource instance.
type ResourceSpec ¶
ResourceSpec wraps proto.Message structures and adds DeepCopy and marshaling methods. T is a protobuf generated structure. S is a pointer to T. Example usage: type WrappedSpec = ResourceSpec[ProtoSpec, *ProtoSpec].
func NewResourceSpec ¶
func NewResourceSpec[T any, S Spec[T]](value S) ResourceSpec[T, S]
NewResourceSpec creates new ResourceSpec[T, S]. T is a protobuf generated structure. S is a pointer to T.
func (ResourceSpec[T, S]) DeepCopy ¶
func (spec ResourceSpec[T, S]) DeepCopy() ResourceSpec[T, S]
DeepCopy creates a copy of the wrapped proto.Message.
func (*ResourceSpec[T, S]) Equal ¶
func (spec *ResourceSpec[T, S]) Equal(other interface{}) bool
Equal implements spec equality check.
func (*ResourceSpec[T, S]) GetValue ¶
func (spec *ResourceSpec[T, S]) GetValue() proto.Message
GetValue returns wrapped protobuf object.
func (*ResourceSpec[T, S]) MarshalJSON ¶
func (spec *ResourceSpec[T, S]) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*ResourceSpec[T, S]) MarshalProto ¶
func (spec *ResourceSpec[T, S]) MarshalProto() ([]byte, error)
MarshalProto implements ProtoMarshaler.
func (*ResourceSpec[T, S]) UnmarshalJSON ¶
func (spec *ResourceSpec[T, S]) UnmarshalJSON(bytes []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*ResourceSpec[T, S]) UnmarshalProto ¶
func (spec *ResourceSpec[T, S]) UnmarshalProto(protoBytes []byte) error
UnmarshalProto implements protobuf.ResourceUnmarshaler.
type ResourceUnmarshaler ¶
ResourceUnmarshaler is an interface which should be implemented by Resource to support conversion from protobuf.Resource.
type TypedResource ¶
type TypedResource[T any, R DeepCopyable[R]] interface { *T TypedSpec() *R resource.Resource }
TypedResource is similar to github.com/cosi-project/runtime/pkg/resource/typed.Resource and required to prevent import cycles.
type YAMLResource ¶ added in v0.2.0
type YAMLResource struct {
// contains filtered or unexported fields
}
YAMLResource is a wrapper around Resource which implements yaml.Unmarshaler. Its here and not in resource package to avoid circular dependency.
func (*YAMLResource) Resource ¶ added in v0.2.0
func (r *YAMLResource) Resource() resource.Resource
Resource returns the underlying resource.
func (*YAMLResource) UnmarshalYAML ¶ added in v0.2.0
func (r *YAMLResource) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.