protobsoncodec

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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"
}
View Source
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.

View Source
var TypeBoolValue = reflect.TypeOf((*wrapperspb.BoolValue)(nil))

BoolValue type.

View Source
var TypeBytesValue = reflect.TypeOf((*wrapperspb.BytesValue)(nil))

BytesValue type.

View Source
var TypeDoubleValue = reflect.TypeOf((*wrapperspb.DoubleValue)(nil))

DoubleValue type.

View Source
var TypeDuration = reflect.TypeOf((*durationpb.Duration)(nil))

Duration type.

View Source
var TypeFloatValue = reflect.TypeOf((*wrapperspb.FloatValue)(nil))

FloatValue type.

View Source
var TypeInt32Value = reflect.TypeOf((*wrapperspb.Int32Value)(nil))

Int32Value type.

View Source
var TypeInt64Value = reflect.TypeOf((*wrapperspb.Int64Value)(nil))

Int64Value type.

View Source
var TypeMessage = reflect.TypeOf((*proto.Message)(nil)).Elem()

Message type.

View Source
var TypeStringValue = reflect.TypeOf((*wrapperspb.StringValue)(nil))

StringValue type.

View Source
var TypeTimestamp = reflect.TypeOf((*timestamppb.Timestamp)(nil))

Timestamp type.

View Source
var TypeUInt32Value = reflect.TypeOf((*wrapperspb.UInt32Value)(nil))

UInt32Value type.

View Source
var TypeUInt64Value = reflect.TypeOf((*wrapperspb.UInt64Value)(nil))

UInt64Value type.

Functions

This section is empty.

Types

type BoolValueCodec added in v0.2.0

type BoolValueCodec struct{}

BoolValueCodec is the Codec used for *wrapperspb.BoolValue values.

func NewBoolValueCodec added in v0.2.0

func NewBoolValueCodec() *BoolValueCodec

NewBoolValueCodec returns a BoolValueCodec.

func (*BoolValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.BoolValue.

func (*BoolValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.BoolValue.

type BytesValueCodec added in v0.2.0

type BytesValueCodec struct{}

BytesValueCodec is the Codec used for *wrapperspb.BytesValue values.

func NewBytesValueCodec added in v0.2.0

func NewBytesValueCodec() *BytesValueCodec

NewBytesValueCodec returns a BytesValueCodec.

func (*BytesValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.BytesValue.

func (*BytesValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.BytesValue.

type DoubleValueCodec added in v0.2.0

type DoubleValueCodec struct{}

DoubleValueCodec is the Codec used for *wrapperspb.DoubleValue values.

func NewDoubleValueCodec added in v0.2.0

func NewDoubleValueCodec() *DoubleValueCodec

NewDoubleValueCodec returns a DoubleValueCodec.

func (*DoubleValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.DoubleValue.

func (*DoubleValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.DoubleValue.

type DurationCodec added in v0.3.0

type DurationCodec struct{}

DurationCodec is the Codec used for *durationpb.Duration values.

func NewDurationCodec added in v0.3.0

func NewDurationCodec() *DurationCodec

NewDurationCodec returns a DurationCodec.

func (*DurationCodec) DecodeValue added in v0.3.0

DecodeValue is the ValueDecoderFunc for *durationpb.Duration.

func (*DurationCodec) EncodeValue added in v0.3.0

EncodeValue is the ValueEncoderFunc for *durationpb.Duration.

type FloatValueCodec added in v0.2.0

type FloatValueCodec struct{}

FloatValueCodec is the Codec used for *wrapperspb.FloatValue values.

func NewFloatValueCodec added in v0.2.0

func NewFloatValueCodec() *FloatValueCodec

NewFloatValueCodec returns a FloatValueCodec.

func (*FloatValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.FloatValue.

func (*FloatValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.FloatValue.

type Int32ValueCodec added in v0.2.0

type Int32ValueCodec struct{}

Int32ValueCodec is the Codec used for *wrapperspb.Int32Value values.

func NewInt32ValueCodec added in v0.2.0

func NewInt32ValueCodec() *Int32ValueCodec

NewInt32ValueCodec returns a Int32ValueCodec.

func (*Int32ValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.Int32Value.

func (*Int32ValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.Int32Value.

type Int64ValueCodec added in v0.2.0

type Int64ValueCodec struct{}

Int64ValueCodec is the Codec used for *wrapperspb.Int64Value values.

func NewInt64ValueCodec added in v0.2.0

func NewInt64ValueCodec() *Int64ValueCodec

NewInt64ValueCodec returns a Int64ValueCodec.

func (*Int64ValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.Int64Value.

func (*Int64ValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.Int64Value.

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

DecodeValue is the ValueDecoderFunc for proto.Message.

func (*MessageCodec) EncodeValue

EncodeValue is the ValueEncoderFunc for proto.Message.

type StringValueCodec added in v0.2.0

type StringValueCodec struct{}

StringValueCodec is the Codec used for *wrapperspb.StringValue values.

func NewStringValueCodec added in v0.2.0

func NewStringValueCodec() *StringValueCodec

NewStringValueCodec returns a StringValueCodec.

func (*StringValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.StringValue.

func (*StringValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.StringValue.

type TimestampCodec

type TimestampCodec struct{}

TimestampCodec is the Codec used for *timestamppb.Timestamp values.

func NewTimestampCodec

func NewTimestampCodec() *TimestampCodec

NewTimestampCodec returns a TimestampCodec.

func (*TimestampCodec) DecodeValue

DecodeValue is the ValueDecoderFunc for *timestamppb.Timestamp.

func (*TimestampCodec) EncodeValue

EncodeValue is the ValueEncoderFunc for *timestamppb.Timestamp.

type UInt32ValueCodec added in v0.2.0

type UInt32ValueCodec struct{}

UInt32ValueCodec is the Codec used for *wrapperspb.UInt32Value values.

func NewUInt32ValueCodec added in v0.2.0

func NewUInt32ValueCodec() *UInt32ValueCodec

NewUInt32ValueCodec returns a UInt32ValueCodec.

func (*UInt32ValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.UInt32Value.

func (*UInt32ValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.UInt32Value.

type UInt64ValueCodec added in v0.2.0

type UInt64ValueCodec struct{}

UInt64ValueCodec is the Codec used for *wrapperspb.UInt64Value values.

func NewUInt64ValueCodec added in v0.2.0

func NewUInt64ValueCodec() *UInt64ValueCodec

NewUInt64ValueCodec returns a UInt64ValueCodec.

func (*UInt64ValueCodec) DecodeValue added in v0.2.0

DecodeValue is the ValueDecoderFunc for *wrapperspb.UInt64Value.

func (*UInt64ValueCodec) EncodeValue added in v0.2.0

EncodeValue is the ValueEncoderFunc for *wrapperspb.UInt64Value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL