bsonpb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 0 Imported by: 0

README

bsonpb

Build Status GitHub GoDoc Test Coverage Release

This package allows to serialize/deserialize golang protobuf messages into/from bson documents.

Important notes:

import "github.com/romnn/bsonpb/v2" // only works with google.golang.org/protobuf, NOT github.com/golang/protobuf
Usage (v2)
Marshaling
import "github.com/romnn/bsonpb/v2"

myProto := &pb.Message{Name: "Test", Hilarity: pb.Message_SLAPSTICK}
opts := bsonpb.MarshalOptions{}
marshaled, err := opts.Marshal(someProto)
if err != nil {
    log.Fatal(err)
}
log.Infof("Marshaled: %v", marshaled)
Unmarshaling
import "github.com/romnn/bsonpb/v2"

var myProto pb.Message
inputBson := bson.D{{Key: "Name", Value: "Test"}}
if err := bsonpb.Unmarshal(inputBson, &myProto); err != nil {
    log.Fatal(err)
}
log.Infof("Unmarshaled: %v", myProto)

If you want to try it, you can run the provided example with

bazel run //examples/v2:example
Tests
bazel test //:go_default_test
bazel test //v2:go_default_test # v2 only
Acknowledgements

Documentation

Index

Constants

View Source
const Version = "0.2.0"

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
examples
v2
v2
internal/genid
Package genid contains constants for declarations in descriptor.proto and the well-known types.
Package genid contains constants for declarations in descriptor.proto and the well-known types.

Jump to

Keyboard shortcuts

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