Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotImplementingProto occurs when value for decoding is not implementing proto.Message interface ErrNotImplementingProto = errors.New("value not implementing proto interface") )
Functions ¶
func NewCodec ¶
func NewCodec(opts ...Option) bsoncodec.ValueCodec
NewCodec returns a new instance of a BSON codec for Protobuf messages. Messages are encoded using field numbers as document keys, so that stored messages can survive field renames.
If no FieldNamer option passed, FieldNamerByNumber will be used as default
Types ¶
type FieldNamer ¶
type FieldNamer interface { // FieldDescriptorToFieldName is function to get document field name from proto field descriptor FieldDescriptorToFieldName(fd protoreflect.FieldDescriptor) string // FieldNameToFieldDescriptor is function to get proto field descriptor from document field name FieldNameToFieldDescriptor(fd protoreflect.FieldDescriptors, name string) (protoreflect.FieldDescriptor, error) }
FieldNamer is used to build field name in document from its field descriptor
type FieldNamerByJsonName ¶
type FieldNamerByJsonName struct { }
FieldNamerByJsonName makes field name based on json name of field
func (*FieldNamerByJsonName) FieldDescriptorToFieldName ¶
func (f *FieldNamerByJsonName) FieldDescriptorToFieldName(fd protoreflect.FieldDescriptor) string
FieldDescriptorToFieldName is implementation of FieldNamer method
func (*FieldNamerByJsonName) FieldNameToFieldDescriptor ¶
func (f *FieldNamerByJsonName) FieldNameToFieldDescriptor(fd protoreflect.FieldDescriptors, name string) (protoreflect.FieldDescriptor, error)
FieldNameToFieldDescriptor is implementation of FieldNamer method
type FieldNamerByName ¶
type FieldNamerByName struct { }
FieldNamerByName makes field name based on field name in proto spec
func (*FieldNamerByName) FieldDescriptorToFieldName ¶
func (f *FieldNamerByName) FieldDescriptorToFieldName(fd protoreflect.FieldDescriptor) string
FieldDescriptorToFieldName is implementation of FieldNamer method
func (*FieldNamerByName) FieldNameToFieldDescriptor ¶
func (f *FieldNamerByName) FieldNameToFieldDescriptor(fd protoreflect.FieldDescriptors, name string) (protoreflect.FieldDescriptor, error)
FieldNameToFieldDescriptor is implementation of FieldNamer method
type FieldNamerByNumber ¶
type FieldNamerByNumber struct { }
FieldNamerByNumber makes field names based on field tag number. With this implementation fields in proto spec can be renamed and documents still can be decoded without loss of any data
func (*FieldNamerByNumber) FieldDescriptorToFieldName ¶
func (f *FieldNamerByNumber) FieldDescriptorToFieldName(fd protoreflect.FieldDescriptor) string
FieldDescriptorToFieldName is implementation of FieldNamer method
func (*FieldNamerByNumber) FieldNameToFieldDescriptor ¶
func (f *FieldNamerByNumber) FieldNameToFieldDescriptor(fd protoreflect.FieldDescriptors, name string) (protoreflect.FieldDescriptor, error)
FieldNameToFieldDescriptor is implementation of FieldNamer method
type Option ¶
type Option func(*protobufCodec)
Option - functional option for protobufCodec
func WithFieldNamer ¶
func WithFieldNamer(namer FieldNamer) Option
WithFieldNamer - returns options with FieldNamer instance
func WithFieldNamerByJsonName ¶
func WithFieldNamerByJsonName() Option
WithFieldNamerByJsonName makes FieldNamer Option with FieldNamerByJsonName instance
func WithFieldNamerByName ¶
func WithFieldNamerByName() Option
WithFieldNamerByName makes FieldNamer Option with FieldNamerByName instance
func WithFieldNamerByNumber ¶
func WithFieldNamerByNumber() Option
WithFieldNamerByNumber makes FieldNamer Option with FieldNamerByNumber instance