protobson

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 4 Imported by: 0

README

protobson

PkgGoDev GitHub go.mod Go version GoReportCard GitHub

BSON codecs for Google's protocol buffers.

This library provides add-ons to go.mongodb.org/mongo-driver for first-class protobuf support with similar API design, extensive testing and high reuse of already existing codecs. The following types are currently mapped:

Protobuf MongoDB
message Document
google.protobuf.Timestamp Date
google.protobuf.Duration 64-bit integer
google.protobuf.BoolValue Boolean
google.protobuf.BytesValue Binary
google.protobuf.DoubleValue Double
google.protobuf.FloatValue Double
google.protobuf.Int32Value 32-bit integer
google.protobuf.Int64Value 64-bit integer
google.protobuf.StringValue String
google.protobuf.UInt32Value 32-bit integer
google.protobuf.UInt64Value 64-bit integer
google.type.DateTime Date

This list will grow as we add support for most Well-Known Types as well as Google APIs Common Types.

Usage

$ go get go.vallahaye.net/protobson
// Set client options
clientOptions := options.Client().
  SetRegistry(protobson.DefaultRegistry).
  ApplyURI("mongodb://localhost:27017")

// Connect to MongoDB
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
  log.Fatal(err)
}

// Check the connection
err = client.Ping(context.TODO(), nil)
if err != nil {
  log.Fatal(err)
}

fmt.Println("Connected to MongoDB!")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = bson.NewRegistryBuilder().
	RegisterCodec(knowncodec.TypeBoolValue, defaultBoolValueCodec).
	RegisterCodec(knowncodec.TypeBytesValue, defaultBytesValueCodec).
	RegisterCodec(knowncodec.TypeDoubleValue, defaultDoubleValueCodec).
	RegisterCodec(knowncodec.TypeDuration, defaultDurationCodec).
	RegisterCodec(knowncodec.TypeFloatValue, defaultFloatValueCodec).
	RegisterCodec(knowncodec.TypeInt32Value, defaultInt32ValueCodec).
	RegisterCodec(knowncodec.TypeInt64Value, defaultInt64ValueCodec).
	RegisterHookEncoder(protobsoncodec.TypeMessage, defaultMessageCodec).
	RegisterHookDecoder(protobsoncodec.TypeMessage, defaultMessageCodec).
	RegisterCodec(knowncodec.TypeStringValue, defaultStringValueCodec).
	RegisterCodec(knowncodec.TypeTimestamp, defaultTimestampCodec).
	RegisterCodec(knowncodec.TypeUInt32Value, defaultUInt32ValueCodec).
	RegisterCodec(knowncodec.TypeUInt64Value, defaultUInt64ValueCodec).
	RegisterCodec(googleapiscodec.TypeDateTime, defaultGAPIDateTimeCodec).
	Build()

DefaultRegistry is the default bsoncodec.Registry with all default protobson codecs registered.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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