Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var JSONPBFallbackStructTagParser bsoncodec.StructTagParserFunc = func(sf reflect.StructField) (bsoncodec.StructTags, error) { if _, ok := sf.Tag.Lookup("bson"); ok { return bsoncodec.DefaultStructTagParser(sf) } tag, ok := sf.Tag.Lookup("protobuf") if !ok { return bsoncodec.DefaultStructTagParser(sf) } return parseTags(tag, false) }
JSONPBFallbackStructTagParser is the StructTagParser used by the MessageCodec by default. It has the same behavior as bsoncodec.DefaultStructTagParser but will also fallback to parsing the protobuf tag on a field where the bson tag isn't available. In this case, the key will be taken from the json property, or from the name property if there is none.
An example:
type T struct { Name string `protobuf:"bytes,1,opt,name=name,proto3"` // Key is "name" FooBar string `protobuf:"bytes,2,opt,name=foo_bar,json=fooBar,proto3"` // Key is "fooBar" BarFoo string `protobuf:"bytes,3,opt,name=bar_foo,json=barFoo,proto3" bson:"barfoo"` // Key is "barfoo" }
var ProtoNamesFallbackStructTagParser bsoncodec.StructTagParserFunc = func(sf reflect.StructField) (bsoncodec.StructTags, error) { if _, ok := sf.Tag.Lookup("bson"); ok { return bsoncodec.DefaultStructTagParser(sf) } tag, ok := sf.Tag.Lookup("protobuf") if !ok { return bsoncodec.DefaultStructTagParser(sf) } return parseTags(tag, true) }
ProtoNamesFallbackStructTagParser has the same behavior as JSONPBFallbackStructTagParser except it forces the use of the name property as the key when parsing protobuf tags.
Message type.
Functions ¶
This section is empty.
Types ¶
type MessageCodec ¶
type MessageCodec struct {
*bsoncodec.StructCodec
}
MessageCodec is the Codec used for proto.Message values.
func NewMessageCodec ¶
func NewMessageCodec(opts ...*protobsonoptions.MessageCodecOptions) *MessageCodec
NewMessageCodec returns a MessageCodec with options opts.
func (*MessageCodec) DecodeValue ¶
func (c *MessageCodec) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, v reflect.Value) error
DecodeValue is the ValueDecoderFunc for proto.Message.
func (*MessageCodec) EncodeValue ¶
func (c *MessageCodec) EncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, v reflect.Value) error
EncodeValue is the ValueEncoderFunc for proto.Message.