cereal

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUUIDByteLen = errors.New("proto uuid message must be 16 bytes")
View Source
var File_cereal_proto_decimal_proto protoreflect.FileDescriptor
View Source
var File_cereal_proto_raw_data_proto protoreflect.FileDescriptor
View Source
var File_cereal_proto_uuid_proto protoreflect.FileDescriptor

Functions

func ClipTimestamp

func ClipTimestamp(timestamp *timestamppb.Timestamp)

Mongo db only stores time down to the millisecond, this method clips the accuracy of the protobuf time message to match mongo db. This can be useful for testing code round trips through BSON / the database.

Types

type Decimal

type Decimal struct {

	// High bytes
	High uint64 `protobuf:"varint,1,opt,name=high,proto3" json:"high,omitempty"`
	// low bytes
	Low uint64 `protobuf:"varint,2,opt,name=low,proto3" json:"low,omitempty"`
	// contains filtered or unexported fields
}

Decimal 128 binary that matches the bson specification using a dual uint64 encoding.

func DecimalFromBson

func DecimalFromBson(value primitive.Decimal128) *Decimal

func (*Decimal) Descriptor deprecated

func (*Decimal) Descriptor() ([]byte, []int)

Deprecated: Use Decimal.ProtoReflect.Descriptor instead.

func (*Decimal) GetHigh

func (x *Decimal) GetHigh() uint64

func (*Decimal) GetLow

func (x *Decimal) GetLow() uint64

func (*Decimal) ProtoMessage

func (*Decimal) ProtoMessage()

func (*Decimal) ProtoReflect

func (x *Decimal) ProtoReflect() protoreflect.Message

func (*Decimal) Reset

func (x *Decimal) Reset()

func (*Decimal) String

func (x *Decimal) String() string

func (*Decimal) ToBson

func (x *Decimal) ToBson() primitive.Decimal128

type RawData

type RawData struct {

	// Raw data bytes go here.
	Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

Wrapper type for Raw binary data for ease of type-based marshalling and unmarshalling.

func (*RawData) Descriptor deprecated

func (*RawData) Descriptor() ([]byte, []int)

Deprecated: Use RawData.ProtoReflect.Descriptor instead.

func (*RawData) GetData

func (x *RawData) GetData() []byte

func (*RawData) ProtoMessage

func (*RawData) ProtoMessage()

func (*RawData) ProtoReflect

func (x *RawData) ProtoReflect() protoreflect.Message

func (*RawData) Reset

func (x *RawData) Reset()

func (*RawData) String

func (x *RawData) String() string

type UUID

type UUID struct {

	// Raw uuid bytes go here.
	Bin []byte `protobuf:"bytes,1,opt,name=bin,proto3" json:"bin,omitempty"`
	// contains filtered or unexported fields
}

Wrapper type for UUID to make type-based marshalling and unmarshalling easier

func MustUUIDRandom

func MustUUIDRandom() *UUID

Generate a new random UUID using google's UUID implementation.

func NewUUIDRandom

func NewUUIDRandom() (*UUID, error)

Generate a new random UUID using google's UUID implementation.

func UUIDFromGoogle

func UUIDFromGoogle(value googleUUID.UUID) *UUID

Create a new protobuf UUID value from a Google UUID value.

func UUIDFromMongo

func UUIDFromMongo(value mongoUUID.UUID) *UUID

Create a new protobuf UUID value from a Mongo UUID value.

func (*UUID) Descriptor deprecated

func (*UUID) Descriptor() ([]byte, []int)

Deprecated: Use UUID.ProtoReflect.Descriptor instead.

func (*UUID) GetBin

func (x *UUID) GetBin() []byte

func (*UUID) MustGoogle

func (x *UUID) MustGoogle() googleUUID.UUID

As .ToGoogle(), but panics on conversion error.

func (*UUID) MustMongo

func (x *UUID) MustMongo() mongoUUID.UUID

As .ToMongo(), but panics on conversion error.

func (*UUID) ProtoMessage

func (*UUID) ProtoMessage()

func (*UUID) ProtoReflect

func (x *UUID) ProtoReflect() protoreflect.Message

func (*UUID) Reset

func (x *UUID) Reset()

func (*UUID) Scan

func (x *UUID) Scan(src interface{}) error

Scan unmarshalls a value from an SQL database

src can be string or byte.

func (*UUID) String

func (x *UUID) String() string

func (*UUID) ToGoogle

func (x *UUID) ToGoogle() (googleUUID.UUID, error)

Converts cereal UUID value into google UUID value. Returns zero value if message pointer is nil.

func (*UUID) ToMongo

func (x *UUID) ToMongo() (mongoUUID.UUID, error)

Converts cereal UUID value into mongo helper UUID value (NOT the binary primitive value).

func (*UUID) Validate

func (x *UUID) Validate() error

Validates that a protobuf UID value is the correct number of bytes.

func (*UUID) Value

func (x *UUID) Value() (driver.Value, error)

Value stores the data as a binary blob. For string values, use one of the wrapper types in protoSQL

Jump to

Keyboard shortcuts

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