├── go.mod ├── proto ├── pmongo │ └── objectid.proto └── third_party │ └── google │ └── protobuf │ ├── source_context.proto │ ├── empty.proto │ ├── struct.proto │ ├── wrappers.proto │ ├── duration.proto │ ├── any.proto │ ├── timestamp.proto │ ├── type.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── field_mask.proto │ └── descriptor.proto ├── proto_build.cmd ├── proto_build.sh ├── .gitignore ├── examples ├── mongodb-rw │ ├── proto_build.cmd │ ├── data.proto │ ├── main.go │ └── data.pb.go └── third_party │ └── protoc-gen-gotag │ └── tagger │ └── tagger.proto ├── pmongo ├── objectid.go ├── jsonpb.go └── objectid.pb.go ├── .vscode ├── launch.json └── settings.json ├── test ├── codecs_test.proto └── codecs_test.pb.go ├── README.md ├── codecs_test.go ├── codecs.go └── LICENSE /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/amsokol/mongo-go-driver-protobuf 2 | 3 | require ( 4 | github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157 5 | go.mongodb.org/mongo-driver v1.0.0-rc1 6 | ) 7 | -------------------------------------------------------------------------------- /proto/pmongo/objectid.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package pmongo; 3 | 4 | option go_package = "github.com/amsokol/mongo-go-driver-protobuf/pmongo"; 5 | 6 | message ObjectId{ 7 | string value = 1; 8 | } -------------------------------------------------------------------------------- /proto_build.cmd: -------------------------------------------------------------------------------- 1 | @protoc --proto_path=proto/pmongo --go_out=../../../ objectid.proto 2 | 3 | @protoc --proto_path=test --proto_path=proto --proto_path=proto/third_party --go_out=test codecs_test.proto 4 | -------------------------------------------------------------------------------- /proto_build.sh: -------------------------------------------------------------------------------- 1 | #bash 2 | 3 | protoc --proto_path=proto/pmongo --go_out=../../../ objectid.proto 4 | 5 | protoc --proto_path=test --proto_path=proto --proto_path=proto/third_party --go_out=test codecs_test.proto 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | go.sum 14 | -------------------------------------------------------------------------------- /examples/mongodb-rw/proto_build.cmd: -------------------------------------------------------------------------------- 1 | @protoc --proto_path=. --proto_path=../../proto --proto_path=../../proto/third_party --proto_path=../third_party --go_out=. data.proto 2 | 3 | @protoc --proto_path=. --proto_path=../../proto --proto_path=../../proto/third_party --proto_path=../third_party --gotag_out=xxx="bson+\"-\"",output_path=.:. data.proto 4 | -------------------------------------------------------------------------------- /pmongo/objectid.go: -------------------------------------------------------------------------------- 1 | package pmongo 2 | 3 | import ( 4 | "go.mongodb.org/mongo-driver/bson/primitive" 5 | ) 6 | 7 | // NewObjectId creates proto ObjectId from MongoDB ObjectID 8 | func NewObjectId(id primitive.ObjectID) *ObjectId { 9 | return &ObjectId{Value: id.Hex()} 10 | } 11 | 12 | // GetObjectID returns MongoDB object ID 13 | func (o *ObjectId) GetObjectID() (primitive.ObjectID, error) { 14 | return primitive.ObjectIDFromHex(o.Value) 15 | } 16 | -------------------------------------------------------------------------------- /examples/third_party/protoc-gen-gotag/tagger/tagger.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tagger; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option go_package = "github.com/amsokol/protoc-gen-gotag/tagger;tagger"; 8 | 9 | // Tags are applied at the field level 10 | extend google.protobuf.FieldOptions { 11 | // Multiple Tags can be spcified. 12 | string tags = 847939; 13 | } 14 | 15 | extend google.protobuf.OneofOptions { 16 | // Multiple Tags can be spcified. 17 | string oneof_tags = 847939; 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch mongodb-rw example", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${workspaceFolder}/examples/mongodb-rw/main.go", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "protoc": { 3 | "options": [ 4 | "--proto_path=proto", 5 | "--proto_path=proto/third_party" 6 | ] 7 | }, 8 | "cSpell.words": [ 9 | "Altas", 10 | "Fatalf", 11 | "Printf", 12 | "Uint", 13 | "Unkeyed", 14 | "amsokol", 15 | "bson", 16 | "bsoncodec", 17 | "bsonrw", 18 | "ectx", 19 | "gotag", 20 | "gzipped", 21 | "jsonpb", 22 | "mongodb", 23 | "objectid", 24 | "officional", 25 | "pmongo", 26 | "proto", 27 | "protobuf", 28 | "protoc", 29 | "ptypes", 30 | "struct", 31 | "tspb", 32 | "unmarshal" 33 | ] 34 | } -------------------------------------------------------------------------------- /pmongo/jsonpb.go: -------------------------------------------------------------------------------- 1 | package pmongo 2 | 3 | import ( 4 | "bytes" 5 | 6 | "github.com/golang/protobuf/jsonpb" 7 | "github.com/golang/protobuf/ptypes/wrappers" 8 | ) 9 | 10 | // MarshalJSONPB marshals ObjectId to JSONPB string 11 | func (o *ObjectId) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { 12 | s, err := m.MarshalToString(&wrappers.StringValue{Value: o.Value}) 13 | if err != nil { 14 | return nil, err 15 | } 16 | return []byte(s), nil 17 | } 18 | 19 | // UnmarshalJSONPB unmarshal JSONPB string to ObjectId 20 | func (o *ObjectId) UnmarshalJSONPB(m *jsonpb.Unmarshaler, data []byte) error { 21 | var id wrappers.StringValue 22 | if err := m.Unmarshal(bytes.NewReader(data), &id); err != nil { 23 | return err 24 | } 25 | o.Value = id.Value 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /test/codecs_test.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package test; 3 | 4 | import "google/protobuf/timestamp.proto"; 5 | import "google/protobuf/wrappers.proto"; 6 | 7 | import "pmongo/objectid.proto"; 8 | 9 | message Data{ 10 | google.protobuf.BoolValue boolValue = 1; 11 | 12 | google.protobuf.BytesValue bytesValue = 2; 13 | 14 | google.protobuf.DoubleValue doubleValue = 3; 15 | 16 | google.protobuf.FloatValue floatValue = 4; 17 | 18 | google.protobuf.Int32Value int32Value = 5; 19 | 20 | google.protobuf.Int64Value int64Value = 6; 21 | 22 | google.protobuf.StringValue stringValue = 7; 23 | 24 | google.protobuf.UInt32Value uint32Value = 8; 25 | 26 | google.protobuf.UInt64Value uint64Value = 9; 27 | 28 | google.protobuf.Timestamp timestamp = 10; 29 | 30 | pmongo.ObjectId id = 11; 31 | } 32 | -------------------------------------------------------------------------------- /examples/mongodb-rw/data.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package main; 3 | 4 | import "google/protobuf/timestamp.proto"; 5 | import "google/protobuf/wrappers.proto"; 6 | import "protoc-gen-gotag/tagger/tagger.proto"; 7 | 8 | import "pmongo/objectid.proto"; 9 | 10 | message Data{ 11 | pmongo.ObjectId id = 1 [(tagger.tags) = "bson:\"_id,omitempty\"" ]; 12 | 13 | bool boolValue = 2; 14 | google.protobuf.BoolValue boolProtoValue = 3; 15 | 16 | bytes bytesValue = 4; 17 | google.protobuf.BytesValue bytesProtoValue = 5; 18 | 19 | double doubleValue = 6; 20 | google.protobuf.DoubleValue doubleProtoValue = 7; 21 | 22 | float floatValue = 8; 23 | google.protobuf.FloatValue floatProtoValue = 9; 24 | 25 | int32 int32Value = 10; 26 | google.protobuf.Int32Value int32ProtoValue = 11; 27 | 28 | int64 int64Value = 12; 29 | google.protobuf.Int64Value int64ProtoValue = 13; 30 | 31 | string stringValue = 14; 32 | google.protobuf.StringValue stringProtoValue = 15; 33 | 34 | uint32 uint32Value = 16; 35 | google.protobuf.UInt32Value uint32ProtoValue = 17; 36 | 37 | uint64 uint64Value = 18; 38 | google.protobuf.UInt64Value uint64ProtoValue = 19; 39 | 40 | google.protobuf.Timestamp timestamp = 20; 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mongo-go-driver-protobuf 2 | 3 | This is extension for officional MongoDB Go driver adds support for Google protocol buffers types. 4 | 5 | - [Description](#description) 6 | - [Links](#links) 7 | - [Requirements](#requirements) 8 | - [Installation](#installation) 9 | - [Usage example](#usage-example) 10 | 11 | ## Description 12 | 13 | It contains set of BSON marshal/unmarshal codecs for Google protocol buffers type wrappers, Timestamp and MongoDB ObjectID: 14 | 15 | - `BoolValue` 16 | - `BytesValue` 17 | - `DoubleValue` 18 | - `FloatValue` 19 | - `Int32Value` 20 | - `Int64Value` 21 | - `StringValue` 22 | - `Uint32Value` 23 | - `Uint64Value` 24 | - `Timestamp` 25 | - `ObjectID` 26 | 27 | ## Links 28 | 29 | - Official MongoDB Go Driver: [https://go.mongodb.org/mongo-driver](https://go.mongodb.org/mongo-driver) 30 | - Google protocol buffers types (wrappers): [https://github.com/golang/protobuf/blob/master/ptypes/wrappers/wrappers.proto](https://github.com/golang/protobuf/blob/master/ptypes/wrappers/wrappers.proto) 31 | - Google protocol buffers Timestamp type: [https://github.com/golang/protobuf/blob/master/ptypes/timestamp/timestamp.proto](https://github.com/golang/protobuf/blob/master/ptypes/timestamp/timestamp.proto) 32 | - MongoDB ObjectID type: [https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/objectid.go](https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/objectid.go) 33 | - MongoDB ObjectID my proto wrapper: [https://github.com/amsokol/mongo-go-driver-protobuf/blob/master/proto/mongodb/objectid.proto](https://github.com/amsokol/mongo-go-driver-protobuf/blob/master/proto/mongodb/objectid.proto) 34 | 35 | ## Requirements 36 | 37 | - Google protocol buffers version `proto3` 38 | - Official MongoDB Go Driver RC1 or higher 39 | 40 | ## Installation 41 | 42 | Installing using `go get`: 43 | 44 | ```bash 45 | go get -u github.com/amsokol/mongo-go-driver-protobuf 46 | ``` 47 | 48 | or you don't need to do anything manually if you are using Go modules. Go modules installs necessary packages automatically. 49 | 50 | ## Usage example 51 | 52 | First install `protoc-gen-gotag` to make available Go language `tags` for proto messages 53 | 54 | ```bash 55 | go get -u github.com/amsokol/protoc-gen-gotag 56 | ``` 57 | 58 | Next 59 | 60 | 1. Create free Altas mini MongoDB instance 61 | 2. Create `experiments` database 62 | 3. Create `proto` collection into `experiments` database 63 | 4. Run this [example](https://github.com/amsokol/mongo-go-driver-protobuf/tree/master/examples/mongodb-rw) 64 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/genproto/protobuf/source_context;source_context"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source_context.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/empty"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | // The JSON representation for `Empty` is empty JSON object `{}`. 52 | message Empty {} 53 | -------------------------------------------------------------------------------- /pmongo/objectid.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: objectid.proto 3 | 4 | package pmongo 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "github.com/golang/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | // Reference imports to suppress errors if they are not otherwise used. 13 | var _ = proto.Marshal 14 | var _ = fmt.Errorf 15 | var _ = math.Inf 16 | 17 | // This is a compile-time assertion to ensure that this generated file 18 | // is compatible with the proto package it is being compiled against. 19 | // A compilation error at this line likely means your copy of the 20 | // proto package needs to be updated. 21 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 22 | 23 | type ObjectId struct { 24 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 25 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 26 | XXX_unrecognized []byte `json:"-"` 27 | XXX_sizecache int32 `json:"-"` 28 | } 29 | 30 | func (m *ObjectId) Reset() { *m = ObjectId{} } 31 | func (m *ObjectId) String() string { return proto.CompactTextString(m) } 32 | func (*ObjectId) ProtoMessage() {} 33 | func (*ObjectId) Descriptor() ([]byte, []int) { 34 | return fileDescriptor_311fc7ad12a77133, []int{0} 35 | } 36 | 37 | func (m *ObjectId) XXX_Unmarshal(b []byte) error { 38 | return xxx_messageInfo_ObjectId.Unmarshal(m, b) 39 | } 40 | func (m *ObjectId) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 41 | return xxx_messageInfo_ObjectId.Marshal(b, m, deterministic) 42 | } 43 | func (m *ObjectId) XXX_Merge(src proto.Message) { 44 | xxx_messageInfo_ObjectId.Merge(m, src) 45 | } 46 | func (m *ObjectId) XXX_Size() int { 47 | return xxx_messageInfo_ObjectId.Size(m) 48 | } 49 | func (m *ObjectId) XXX_DiscardUnknown() { 50 | xxx_messageInfo_ObjectId.DiscardUnknown(m) 51 | } 52 | 53 | var xxx_messageInfo_ObjectId proto.InternalMessageInfo 54 | 55 | func (m *ObjectId) GetValue() string { 56 | if m != nil { 57 | return m.Value 58 | } 59 | return "" 60 | } 61 | 62 | func init() { 63 | proto.RegisterType((*ObjectId)(nil), "pmongo.ObjectId") 64 | } 65 | 66 | func init() { proto.RegisterFile("objectid.proto", fileDescriptor_311fc7ad12a77133) } 67 | 68 | var fileDescriptor_311fc7ad12a77133 = []byte{ 69 | // 124 bytes of a gzipped FileDescriptorProto 70 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcb, 0x4f, 0xca, 0x4a, 71 | 0x4d, 0x2e, 0xc9, 0x4c, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2b, 0xc8, 0xcd, 0xcf, 72 | 0x4b, 0xcf, 0x57, 0x52, 0xe0, 0xe2, 0xf0, 0x07, 0xcb, 0x78, 0xa6, 0x08, 0x89, 0x70, 0xb1, 0x96, 73 | 0x25, 0xe6, 0x94, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x38, 0x4e, 0x26, 0x51, 74 | 0x46, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x89, 0xb9, 0xc5, 0xf9, 75 | 0xd9, 0xf9, 0x39, 0xfa, 0x60, 0xdd, 0xba, 0xe9, 0xf9, 0xba, 0x29, 0x45, 0x99, 0x65, 0xa9, 0x45, 76 | 0xba, 0x60, 0x53, 0x93, 0x4a, 0xd3, 0xf4, 0x21, 0xe6, 0x26, 0xb1, 0x81, 0x05, 0x8c, 0x01, 0x01, 77 | 0x00, 0x00, 0xff, 0xff, 0xbe, 0x64, 0x87, 0x94, 0x78, 0x00, 0x00, 0x00, 78 | } 79 | -------------------------------------------------------------------------------- /codecs_test.go: -------------------------------------------------------------------------------- 1 | package codecs 2 | 3 | import ( 4 | "bytes" 5 | "reflect" 6 | "testing" 7 | "time" 8 | 9 | "github.com/golang/protobuf/jsonpb" 10 | "github.com/golang/protobuf/ptypes" 11 | "github.com/golang/protobuf/ptypes/wrappers" 12 | "go.mongodb.org/mongo-driver/bson" 13 | "go.mongodb.org/mongo-driver/bson/primitive" 14 | 15 | "github.com/amsokol/mongo-go-driver-protobuf/pmongo" 16 | "github.com/amsokol/mongo-go-driver-protobuf/test" 17 | ) 18 | 19 | func TestCodecs(t *testing.T) { 20 | rb := bson.NewRegistryBuilder() 21 | r := Register(rb).Build() 22 | 23 | tm := time.Now() 24 | // BSON accuracy is in milliseconds 25 | tm = time.Date(tm.Year(), tm.Month(), tm.Day(), tm.Hour(), tm.Minute(), tm.Second(), 26 | (tm.Nanosecond()/1000000)*1000000, tm.Location()) 27 | 28 | ts, err := ptypes.TimestampProto(tm) 29 | if err != nil { 30 | t.Errorf("ptypes.TimestampProto error = %v", err) 31 | return 32 | } 33 | 34 | objectID := primitive.NewObjectID() 35 | id := pmongo.NewObjectId(objectID) 36 | 37 | t.Run("primitive object id", func(t *testing.T) { 38 | resultID, err := id.GetObjectID() 39 | if err != nil { 40 | t.Errorf("mongodb.ObjectId.GetPrimitiveObjectID() error = %v", err) 41 | return 42 | } 43 | 44 | if !reflect.DeepEqual(objectID, resultID) { 45 | t.Errorf("failed: primitive object ID=%#v, ID=%#v", objectID, id) 46 | return 47 | } 48 | }) 49 | 50 | in := test.Data{ 51 | BoolValue: &wrappers.BoolValue{Value: true}, 52 | BytesValue: &wrappers.BytesValue{Value: make([]byte, 5)}, 53 | DoubleValue: &wrappers.DoubleValue{Value: 1.2}, 54 | FloatValue: &wrappers.FloatValue{Value: 1.3}, 55 | Int32Value: &wrappers.Int32Value{Value: -12345}, 56 | Int64Value: &wrappers.Int64Value{Value: -123456789}, 57 | StringValue: &wrappers.StringValue{Value: "qwerty"}, 58 | Uint32Value: &wrappers.UInt32Value{Value: 12345}, 59 | Uint64Value: &wrappers.UInt64Value{Value: 123456789}, 60 | Timestamp: ts, 61 | Id: id, 62 | } 63 | 64 | t.Run("marshal/unmarshal", func(t *testing.T) { 65 | b, err := bson.MarshalWithRegistry(r, &in) 66 | if err != nil { 67 | t.Errorf("bson.MarshalWithRegistry error = %v", err) 68 | return 69 | } 70 | 71 | var out test.Data 72 | 73 | if err = bson.UnmarshalWithRegistry(r, b, &out); err != nil { 74 | t.Errorf("bson.UnmarshalWithRegistry error = %v", err) 75 | return 76 | } 77 | 78 | if !reflect.DeepEqual(in, out) { 79 | t.Errorf("failed: in=%#v, out=%#v", in, out) 80 | return 81 | } 82 | }) 83 | 84 | t.Run("marshal-jsonpb/unmarshal-jsonpb", func(t *testing.T) { 85 | var b bytes.Buffer 86 | 87 | m := &jsonpb.Marshaler{} 88 | 89 | if err := m.Marshal(&b, &in); err != nil { 90 | t.Errorf("jsonpb.Marshaler.Marshal error = %v", err) 91 | return 92 | } 93 | 94 | var out test.Data 95 | if err = jsonpb.Unmarshal(&b, &out); err != nil { 96 | t.Errorf("jsonpb.Unmarshal error = %v", err) 97 | return 98 | } 99 | 100 | if !reflect.DeepEqual(in, out) { 101 | t.Errorf("failed: in=%#v, out=%#v", in, out) 102 | return 103 | } 104 | }) 105 | } 106 | -------------------------------------------------------------------------------- /examples/mongodb-rw/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "log" 7 | "time" 8 | 9 | "github.com/golang/protobuf/jsonpb" 10 | "github.com/golang/protobuf/ptypes" 11 | "github.com/golang/protobuf/ptypes/wrappers" 12 | 13 | "go.mongodb.org/mongo-driver/bson" 14 | "go.mongodb.org/mongo-driver/mongo" 15 | "go.mongodb.org/mongo-driver/mongo/options" 16 | 17 | "github.com/amsokol/mongo-go-driver-protobuf" 18 | ) 19 | 20 | func main() { 21 | log.Printf("connecting to MongoDB...") 22 | 23 | // Register custom codecs for protobuf Timestamp and wrapper types 24 | reg := codecs.Register(bson.NewRegistryBuilder()).Build() 25 | 26 | // Create MongoDB client with registered custom codecs for protobuf Timestamp and wrapper types 27 | // NOTE: "mongodb+srv" protocol means connect to Altas cloud MongoDB server 28 | // use just "mongodb" if you connect to on-premise MongoDB server 29 | client, err := mongo.NewClient(options.Client(). 30 | ApplyURI("mongodb+srv://USER:PASSWORD@SERVER/experiments"). 31 | SetRegistry(reg), 32 | ) 33 | 34 | if err != nil { 35 | log.Fatalf("failed to create new MongoDB client: %#v", err) 36 | } 37 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 38 | defer cancel() 39 | 40 | // Connect client 41 | if err = client.Connect(ctx); err != nil { 42 | log.Fatalf("failed to connect to MongoDB: %#v", err) 43 | } 44 | 45 | log.Printf("connected successfully") 46 | 47 | // Get collection from database 48 | coll := client.Database("experiments").Collection("proto") 49 | 50 | // Create protobuf Timestamp value from golang Time 51 | ts := ptypes.TimestampNow() 52 | 53 | // Fill in data structure 54 | in := Data{ 55 | BoolValue: true, 56 | BoolProtoValue: &wrappers.BoolValue{Value: true}, 57 | 58 | BytesValue: []byte{1, 2, 3, 4, 5}, 59 | BytesProtoValue: &wrappers.BytesValue{Value: []byte{1, 2, 3, 4, 5}}, 60 | 61 | DoubleValue: 123.45678, 62 | DoubleProtoValue: &wrappers.DoubleValue{Value: 123.45678}, 63 | 64 | FloatValue: 123.45, 65 | FloatProtoValue: &wrappers.FloatValue{Value: 123.45}, 66 | 67 | Int32Value: -12345, 68 | Int32ProtoValue: &wrappers.Int32Value{Value: -12345}, 69 | 70 | Int64Value: -123456789000, 71 | Int64ProtoValue: &wrappers.Int64Value{Value: -123456789000}, 72 | 73 | StringValue: "qwerty", 74 | StringProtoValue: &wrappers.StringValue{Value: "qwerty"}, 75 | 76 | Uint32Value: 12345, 77 | Uint32ProtoValue: &wrappers.UInt32Value{Value: 12345}, 78 | 79 | Uint64Value: 123456789000, 80 | Uint64ProtoValue: &wrappers.UInt64Value{Value: 123456789000}, 81 | 82 | Timestamp: ts, 83 | } 84 | 85 | log.Printf("insert data into collection ...") 86 | 87 | // Insert data into the collection 88 | res, err := coll.InsertOne(ctx, &in) 89 | if err != nil { 90 | log.Fatalf("insert data into collection : %#v", err) 91 | } 92 | id := res.InsertedID 93 | log.Printf("inserted new item with id=%v successfully", id) 94 | 95 | // Create filter and output structure to read data from collection 96 | var out Data 97 | filter := bson.D{{Key: "_id", Value: id}} 98 | 99 | // Read data from collection 100 | err = coll.FindOne(ctx, filter).Decode(&out) 101 | if err != nil { 102 | log.Fatalf("failed to read data (id=%v) from collection : %#v", id, err) 103 | } 104 | 105 | var b bytes.Buffer 106 | m := &jsonpb.Marshaler{Indent: " "} 107 | if err := m.Marshal(&b, &out); err != nil { 108 | log.Fatalf("jsonpb.Marshaler.Marshal error = %v", err) 109 | } 110 | 111 | log.Printf("read successfully:\n%s", b.String()) 112 | } 113 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/struct;structpb"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "StructProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | 44 | // `Struct` represents a structured data value, consisting of fields 45 | // which map to dynamically typed values. In some languages, `Struct` 46 | // might be supported by a native representation. For example, in 47 | // scripting languages like JS a struct is represented as an 48 | // object. The details of that representation are described together 49 | // with the proto support for the language. 50 | // 51 | // The JSON representation for `Struct` is JSON object. 52 | message Struct { 53 | // Unordered map of dynamically typed values. 54 | map fields = 1; 55 | } 56 | 57 | // `Value` represents a dynamically typed value which can be either 58 | // null, a number, a string, a boolean, a recursive struct value, or a 59 | // list of values. A producer of value is expected to set one of that 60 | // variants, absence of any variant indicates an error. 61 | // 62 | // The JSON representation for `Value` is JSON value. 63 | message Value { 64 | // The kind of value. 65 | oneof kind { 66 | // Represents a null value. 67 | NullValue null_value = 1; 68 | // Represents a double value. 69 | double number_value = 2; 70 | // Represents a string value. 71 | string string_value = 3; 72 | // Represents a boolean value. 73 | bool bool_value = 4; 74 | // Represents a structured value. 75 | Struct struct_value = 5; 76 | // Represents a repeated `Value`. 77 | ListValue list_value = 6; 78 | } 79 | } 80 | 81 | // `NullValue` is a singleton enumeration to represent the null value for the 82 | // `Value` type union. 83 | // 84 | // The JSON representation for `NullValue` is JSON `null`. 85 | enum NullValue { 86 | // Null value. 87 | NULL_VALUE = 0; 88 | } 89 | 90 | // `ListValue` is a wrapper around a repeated field of values. 91 | // 92 | // The JSON representation for `ListValue` is JSON array. 93 | message ListValue { 94 | // Repeated field of dynamically typed values. 95 | repeated Value values = 1; 96 | } 97 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | package google.protobuf; 39 | 40 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 41 | option cc_enable_arenas = true; 42 | option go_package = "github.com/golang/protobuf/ptypes/wrappers"; 43 | option java_package = "com.google.protobuf"; 44 | option java_outer_classname = "WrappersProto"; 45 | option java_multiple_files = true; 46 | option objc_class_prefix = "GPB"; 47 | 48 | // Wrapper message for `double`. 49 | // 50 | // The JSON representation for `DoubleValue` is JSON number. 51 | message DoubleValue { 52 | // The double value. 53 | double value = 1; 54 | } 55 | 56 | // Wrapper message for `float`. 57 | // 58 | // The JSON representation for `FloatValue` is JSON number. 59 | message FloatValue { 60 | // The float value. 61 | float value = 1; 62 | } 63 | 64 | // Wrapper message for `int64`. 65 | // 66 | // The JSON representation for `Int64Value` is JSON string. 67 | message Int64Value { 68 | // The int64 value. 69 | int64 value = 1; 70 | } 71 | 72 | // Wrapper message for `uint64`. 73 | // 74 | // The JSON representation for `UInt64Value` is JSON string. 75 | message UInt64Value { 76 | // The uint64 value. 77 | uint64 value = 1; 78 | } 79 | 80 | // Wrapper message for `int32`. 81 | // 82 | // The JSON representation for `Int32Value` is JSON number. 83 | message Int32Value { 84 | // The int32 value. 85 | int32 value = 1; 86 | } 87 | 88 | // Wrapper message for `uint32`. 89 | // 90 | // The JSON representation for `UInt32Value` is JSON number. 91 | message UInt32Value { 92 | // The uint32 value. 93 | uint32 value = 1; 94 | } 95 | 96 | // Wrapper message for `bool`. 97 | // 98 | // The JSON representation for `BoolValue` is JSON `true` and `false`. 99 | message BoolValue { 100 | // The bool value. 101 | bool value = 1; 102 | } 103 | 104 | // Wrapper message for `string`. 105 | // 106 | // The JSON representation for `StringValue` is JSON string. 107 | message StringValue { 108 | // The string value. 109 | string value = 1; 110 | } 111 | 112 | // Wrapper message for `bytes`. 113 | // 114 | // The JSON representation for `BytesValue` is JSON string. 115 | message BytesValue { 116 | // The bytes value. 117 | bytes value = 1; 118 | } 119 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/duration"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "DurationProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Duration represents a signed, fixed-length span of time represented 44 | // as a count of seconds and fractions of seconds at nanosecond 45 | // resolution. It is independent of any calendar and concepts like "day" 46 | // or "month". It is related to Timestamp in that the difference between 47 | // two Timestamp values is a Duration and it can be added or subtracted 48 | // from a Timestamp. Range is approximately +-10,000 years. 49 | // 50 | // # Examples 51 | // 52 | // Example 1: Compute Duration from two Timestamps in pseudo code. 53 | // 54 | // Timestamp start = ...; 55 | // Timestamp end = ...; 56 | // Duration duration = ...; 57 | // 58 | // duration.seconds = end.seconds - start.seconds; 59 | // duration.nanos = end.nanos - start.nanos; 60 | // 61 | // if (duration.seconds < 0 && duration.nanos > 0) { 62 | // duration.seconds += 1; 63 | // duration.nanos -= 1000000000; 64 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 65 | // duration.seconds -= 1; 66 | // duration.nanos += 1000000000; 67 | // } 68 | // 69 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 70 | // 71 | // Timestamp start = ...; 72 | // Duration duration = ...; 73 | // Timestamp end = ...; 74 | // 75 | // end.seconds = start.seconds + duration.seconds; 76 | // end.nanos = start.nanos + duration.nanos; 77 | // 78 | // if (end.nanos < 0) { 79 | // end.seconds -= 1; 80 | // end.nanos += 1000000000; 81 | // } else if (end.nanos >= 1000000000) { 82 | // end.seconds += 1; 83 | // end.nanos -= 1000000000; 84 | // } 85 | // 86 | // Example 3: Compute Duration from datetime.timedelta in Python. 87 | // 88 | // td = datetime.timedelta(days=3, minutes=10) 89 | // duration = Duration() 90 | // duration.FromTimedelta(td) 91 | // 92 | // # JSON Mapping 93 | // 94 | // In JSON format, the Duration type is encoded as a string rather than an 95 | // object, where the string ends in the suffix "s" (indicating seconds) and 96 | // is preceded by the number of seconds, with nanoseconds expressed as 97 | // fractional seconds. For example, 3 seconds with 0 nanoseconds should be 98 | // encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 99 | // be expressed in JSON format as "3.000000001s", and 3 seconds and 1 100 | // microsecond should be expressed in JSON format as "3.000001s". 101 | // 102 | // 103 | message Duration { 104 | 105 | // Signed seconds of the span of time. Must be from -315,576,000,000 106 | // to +315,576,000,000 inclusive. Note: these bounds are computed from: 107 | // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 108 | int64 seconds = 1; 109 | 110 | // Signed fractions of a second at nanosecond resolution of the span 111 | // of time. Durations less than one second are represented with a 0 112 | // `seconds` field and a positive or negative `nanos` field. For durations 113 | // of one second or more, a non-zero value for the `nanos` field must be 114 | // of the same sign as the `seconds` field. Must be from -999,999,999 115 | // to +999,999,999 inclusive. 116 | int32 nanos = 2; 117 | } 118 | -------------------------------------------------------------------------------- /codecs.go: -------------------------------------------------------------------------------- 1 | package codecs 2 | 3 | import ( 4 | "reflect" 5 | "time" 6 | 7 | "github.com/golang/protobuf/ptypes" 8 | "github.com/golang/protobuf/ptypes/timestamp" 9 | "github.com/golang/protobuf/ptypes/wrappers" 10 | "go.mongodb.org/mongo-driver/bson/bsoncodec" 11 | "go.mongodb.org/mongo-driver/bson/bsonrw" 12 | "go.mongodb.org/mongo-driver/bson/primitive" 13 | 14 | "github.com/amsokol/mongo-go-driver-protobuf/pmongo" 15 | ) 16 | 17 | var ( 18 | // Protobuf wrappers types 19 | boolValueType = reflect.TypeOf(wrappers.BoolValue{}) 20 | bytesValueType = reflect.TypeOf(wrappers.BytesValue{}) 21 | doubleValueType = reflect.TypeOf(wrappers.DoubleValue{}) 22 | floatValueType = reflect.TypeOf(wrappers.FloatValue{}) 23 | int32ValueType = reflect.TypeOf(wrappers.Int32Value{}) 24 | int64ValueType = reflect.TypeOf(wrappers.Int64Value{}) 25 | stringValueType = reflect.TypeOf(wrappers.StringValue{}) 26 | uint32ValueType = reflect.TypeOf(wrappers.UInt32Value{}) 27 | uint64ValueType = reflect.TypeOf(wrappers.UInt64Value{}) 28 | 29 | // Protobuf Timestamp type 30 | timestampType = reflect.TypeOf(timestamp.Timestamp{}) 31 | 32 | // Time type 33 | timeType = reflect.TypeOf(time.Time{}) 34 | 35 | // ObjectId type 36 | objectIDType = reflect.TypeOf(pmongo.ObjectId{}) 37 | objectIDPrimitiveType = reflect.TypeOf(primitive.ObjectID{}) 38 | 39 | // Codecs 40 | wrapperValueCodecRef = &wrapperValueCodec{} 41 | timestampCodecRef = ×tampCodec{} 42 | objectIDCodecRef = &objectIDCodec{} 43 | ) 44 | 45 | // wrapperValueCodec is codec for Protobuf type wrappers 46 | type wrapperValueCodec struct { 47 | } 48 | 49 | // EncodeValue encodes Protobuf type wrapper value to BSON value 50 | func (e *wrapperValueCodec) EncodeValue(ectx bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { 51 | val = val.FieldByName("Value") 52 | enc, err := ectx.LookupEncoder(val.Type()) 53 | if err != nil { 54 | return err 55 | } 56 | return enc.EncodeValue(ectx, vw, val) 57 | } 58 | 59 | // DecodeValue decodes BSON value to Protobuf type wrapper value 60 | func (e *wrapperValueCodec) DecodeValue(ectx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { 61 | val = val.FieldByName("Value") 62 | enc, err := ectx.LookupDecoder(val.Type()) 63 | if err != nil { 64 | return err 65 | } 66 | return enc.DecodeValue(ectx, vr, val) 67 | } 68 | 69 | // timestampCodec is codec for Protobuf Timestamp 70 | type timestampCodec struct { 71 | } 72 | 73 | // EncodeValue encodes Protobuf Timestamp value to BSON value 74 | func (e *timestampCodec) EncodeValue(ectx bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { 75 | v := val.Interface().(timestamp.Timestamp) 76 | t, err := ptypes.Timestamp(&v) 77 | if err != nil { 78 | return err 79 | } 80 | enc, err := ectx.LookupEncoder(timeType) 81 | if err != nil { 82 | return err 83 | } 84 | return enc.EncodeValue(ectx, vw, reflect.ValueOf(t.In(time.UTC))) 85 | } 86 | 87 | // DecodeValue decodes BSON value to Timestamp value 88 | func (e *timestampCodec) DecodeValue(ectx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { 89 | enc, err := ectx.LookupDecoder(timeType) 90 | if err != nil { 91 | return err 92 | } 93 | var t time.Time 94 | if err = enc.DecodeValue(ectx, vr, reflect.ValueOf(&t).Elem()); err != nil { 95 | return err 96 | } 97 | ts, err := ptypes.TimestampProto(t.In(time.UTC)) 98 | if err != nil { 99 | return err 100 | } 101 | val.Set(reflect.ValueOf(*ts)) 102 | return nil 103 | } 104 | 105 | // objectIDCodec is codec for Protobuf ObjectId 106 | type objectIDCodec struct { 107 | } 108 | 109 | // EncodeValue encodes Protobuf ObjectId value to BSON value 110 | func (e *objectIDCodec) EncodeValue(ectx bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { 111 | v := val.Interface().(pmongo.ObjectId) 112 | // Create primitive.ObjectId from string 113 | id, err := primitive.ObjectIDFromHex(v.Value) 114 | if err != nil { 115 | return err 116 | } 117 | enc, err := ectx.LookupEncoder(objectIDPrimitiveType) 118 | if err != nil { 119 | return err 120 | } 121 | return enc.EncodeValue(ectx, vw, reflect.ValueOf(id)) 122 | } 123 | 124 | // DecodeValue decodes BSON value to ObjectId value 125 | func (e *objectIDCodec) DecodeValue(ectx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { 126 | enc, err := ectx.LookupDecoder(objectIDPrimitiveType) 127 | if err != nil { 128 | return err 129 | } 130 | var id primitive.ObjectID 131 | if err = enc.DecodeValue(ectx, vr, reflect.ValueOf(&id).Elem()); err != nil { 132 | return err 133 | } 134 | oid := *pmongo.NewObjectId(id) 135 | if err != nil { 136 | return err 137 | } 138 | val.Set(reflect.ValueOf(oid)) 139 | return nil 140 | } 141 | 142 | // Register registers Google protocol buffers types codecs 143 | func Register(rb *bsoncodec.RegistryBuilder) *bsoncodec.RegistryBuilder { 144 | return rb.RegisterCodec(boolValueType, wrapperValueCodecRef). 145 | RegisterCodec(bytesValueType, wrapperValueCodecRef). 146 | RegisterCodec(doubleValueType, wrapperValueCodecRef). 147 | RegisterCodec(floatValueType, wrapperValueCodecRef). 148 | RegisterCodec(int32ValueType, wrapperValueCodecRef). 149 | RegisterCodec(int64ValueType, wrapperValueCodecRef). 150 | RegisterCodec(stringValueType, wrapperValueCodecRef). 151 | RegisterCodec(uint32ValueType, wrapperValueCodecRef). 152 | RegisterCodec(uint64ValueType, wrapperValueCodecRef). 153 | RegisterCodec(timestampType, timestampCodecRef). 154 | RegisterCodec(objectIDType, objectIDCodecRef) 155 | } 156 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/any.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/any"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "AnyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // `Any` contains an arbitrary serialized protocol buffer message along with a 43 | // URL that describes the type of the serialized message. 44 | // 45 | // Protobuf library provides support to pack/unpack Any values in the form 46 | // of utility functions or additional generated methods of the Any type. 47 | // 48 | // Example 1: Pack and unpack a message in C++. 49 | // 50 | // Foo foo = ...; 51 | // Any any; 52 | // any.PackFrom(foo); 53 | // ... 54 | // if (any.UnpackTo(&foo)) { 55 | // ... 56 | // } 57 | // 58 | // Example 2: Pack and unpack a message in Java. 59 | // 60 | // Foo foo = ...; 61 | // Any any = Any.pack(foo); 62 | // ... 63 | // if (any.is(Foo.class)) { 64 | // foo = any.unpack(Foo.class); 65 | // } 66 | // 67 | // Example 3: Pack and unpack a message in Python. 68 | // 69 | // foo = Foo(...) 70 | // any = Any() 71 | // any.Pack(foo) 72 | // ... 73 | // if any.Is(Foo.DESCRIPTOR): 74 | // any.Unpack(foo) 75 | // ... 76 | // 77 | // Example 4: Pack and unpack a message in Go 78 | // 79 | // foo := &pb.Foo{...} 80 | // any, err := ptypes.MarshalAny(foo) 81 | // ... 82 | // foo := &pb.Foo{} 83 | // if err := ptypes.UnmarshalAny(any, foo); err != nil { 84 | // ... 85 | // } 86 | // 87 | // The pack methods provided by protobuf library will by default use 88 | // 'type.googleapis.com/full.type.name' as the type URL and the unpack 89 | // methods only use the fully qualified type name after the last '/' 90 | // in the type URL, for example "foo.bar.com/x/y.z" will yield type 91 | // name "y.z". 92 | // 93 | // 94 | // JSON 95 | // ==== 96 | // The JSON representation of an `Any` value uses the regular 97 | // representation of the deserialized, embedded message, with an 98 | // additional field `@type` which contains the type URL. Example: 99 | // 100 | // package google.profile; 101 | // message Person { 102 | // string first_name = 1; 103 | // string last_name = 2; 104 | // } 105 | // 106 | // { 107 | // "@type": "type.googleapis.com/google.profile.Person", 108 | // "firstName": , 109 | // "lastName": 110 | // } 111 | // 112 | // If the embedded message type is well-known and has a custom JSON 113 | // representation, that representation will be embedded adding a field 114 | // `value` which holds the custom JSON in addition to the `@type` 115 | // field. Example (for message [google.protobuf.Duration][]): 116 | // 117 | // { 118 | // "@type": "type.googleapis.com/google.protobuf.Duration", 119 | // "value": "1.212s" 120 | // } 121 | // 122 | message Any { 123 | // A URL/resource name that uniquely identifies the type of the serialized 124 | // protocol buffer message. The last segment of the URL's path must represent 125 | // the fully qualified name of the type (as in 126 | // `path/google.protobuf.Duration`). The name should be in a canonical form 127 | // (e.g., leading "." is not accepted). 128 | // 129 | // In practice, teams usually precompile into the binary all types that they 130 | // expect it to use in the context of Any. However, for URLs which use the 131 | // scheme `http`, `https`, or no scheme, one can optionally set up a type 132 | // server that maps type URLs to message definitions as follows: 133 | // 134 | // * If no scheme is provided, `https` is assumed. 135 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][] 136 | // value in binary format, or produce an error. 137 | // * Applications are allowed to cache lookup results based on the 138 | // URL, or have them precompiled into a binary to avoid any 139 | // lookup. Therefore, binary compatibility needs to be preserved 140 | // on changes to types. (Use versioned type names to manage 141 | // breaking changes.) 142 | // 143 | // Note: this functionality is not currently available in the official 144 | // protobuf release, and it is not used for type URLs beginning with 145 | // type.googleapis.com. 146 | // 147 | // Schemes other than `http`, `https` (or the empty scheme) might be 148 | // used with implementation specific semantics. 149 | // 150 | string type_url = 1; 151 | 152 | // Must be a valid serialized protocol buffer of the above specified type. 153 | bytes value = 2; 154 | } 155 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/timestamp"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "TimestampProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Timestamp represents a point in time independent of any time zone 44 | // or calendar, represented as seconds and fractions of seconds at 45 | // nanosecond resolution in UTC Epoch time. It is encoded using the 46 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 47 | // backwards to year one. It is encoded assuming all minutes are 60 48 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 49 | // table is needed for interpretation. Range is from 50 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 51 | // By restricting to that range, we ensure that we can convert to 52 | // and from RFC 3339 date strings. 53 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 54 | // 55 | // # Examples 56 | // 57 | // Example 1: Compute Timestamp from POSIX `time()`. 58 | // 59 | // Timestamp timestamp; 60 | // timestamp.set_seconds(time(NULL)); 61 | // timestamp.set_nanos(0); 62 | // 63 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 64 | // 65 | // struct timeval tv; 66 | // gettimeofday(&tv, NULL); 67 | // 68 | // Timestamp timestamp; 69 | // timestamp.set_seconds(tv.tv_sec); 70 | // timestamp.set_nanos(tv.tv_usec * 1000); 71 | // 72 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 73 | // 74 | // FILETIME ft; 75 | // GetSystemTimeAsFileTime(&ft); 76 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 77 | // 78 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 79 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 80 | // Timestamp timestamp; 81 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 82 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 83 | // 84 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 85 | // 86 | // long millis = System.currentTimeMillis(); 87 | // 88 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 89 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 90 | // 91 | // 92 | // Example 5: Compute Timestamp from current time in Python. 93 | // 94 | // timestamp = Timestamp() 95 | // timestamp.GetCurrentTime() 96 | // 97 | // # JSON Mapping 98 | // 99 | // In JSON format, the Timestamp type is encoded as a string in the 100 | // [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the 101 | // format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" 102 | // where {year} is always expressed using four digits while {month}, {day}, 103 | // {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional 104 | // seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), 105 | // are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone 106 | // is required. A proto3 JSON serializer should always use UTC (as indicated by 107 | // "Z") when printing the Timestamp type and a proto3 JSON parser should be 108 | // able to accept both UTC and other timezones (as indicated by an offset). 109 | // 110 | // For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 111 | // 01:30 UTC on January 15, 2017. 112 | // 113 | // In JavaScript, one can convert a Date object to this format using the 114 | // standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] 115 | // method. In Python, a standard `datetime.datetime` object can be converted 116 | // to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) 117 | // with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one 118 | // can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( 119 | // http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime-- 120 | // ) to obtain a formatter capable of generating timestamps in this format. 121 | // 122 | // 123 | message Timestamp { 124 | 125 | // Represents seconds of UTC time since Unix epoch 126 | // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 127 | // 9999-12-31T23:59:59Z inclusive. 128 | int64 seconds = 1; 129 | 130 | // Non-negative fractions of a second at nanosecond resolution. Negative 131 | // second values with fractions must still have non-negative nanos values 132 | // that count forward in time. Must be from 0 to 999,999,999 133 | // inclusive. 134 | int32 nanos = 2; 135 | } 136 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/type.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | import "google/protobuf/any.proto"; 36 | import "google/protobuf/source_context.proto"; 37 | 38 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 39 | option cc_enable_arenas = true; 40 | option java_package = "com.google.protobuf"; 41 | option java_outer_classname = "TypeProto"; 42 | option java_multiple_files = true; 43 | option objc_class_prefix = "GPB"; 44 | option go_package = "google.golang.org/genproto/protobuf/ptype;ptype"; 45 | 46 | // A protocol buffer message type. 47 | message Type { 48 | // The fully qualified message name. 49 | string name = 1; 50 | // The list of fields. 51 | repeated Field fields = 2; 52 | // The list of types appearing in `oneof` definitions in this type. 53 | repeated string oneofs = 3; 54 | // The protocol buffer options. 55 | repeated Option options = 4; 56 | // The source context. 57 | SourceContext source_context = 5; 58 | // The source syntax. 59 | Syntax syntax = 6; 60 | } 61 | 62 | // A single field of a message type. 63 | message Field { 64 | // Basic field types. 65 | enum Kind { 66 | // Field type unknown. 67 | TYPE_UNKNOWN = 0; 68 | // Field type double. 69 | TYPE_DOUBLE = 1; 70 | // Field type float. 71 | TYPE_FLOAT = 2; 72 | // Field type int64. 73 | TYPE_INT64 = 3; 74 | // Field type uint64. 75 | TYPE_UINT64 = 4; 76 | // Field type int32. 77 | TYPE_INT32 = 5; 78 | // Field type fixed64. 79 | TYPE_FIXED64 = 6; 80 | // Field type fixed32. 81 | TYPE_FIXED32 = 7; 82 | // Field type bool. 83 | TYPE_BOOL = 8; 84 | // Field type string. 85 | TYPE_STRING = 9; 86 | // Field type group. Proto2 syntax only, and deprecated. 87 | TYPE_GROUP = 10; 88 | // Field type message. 89 | TYPE_MESSAGE = 11; 90 | // Field type bytes. 91 | TYPE_BYTES = 12; 92 | // Field type uint32. 93 | TYPE_UINT32 = 13; 94 | // Field type enum. 95 | TYPE_ENUM = 14; 96 | // Field type sfixed32. 97 | TYPE_SFIXED32 = 15; 98 | // Field type sfixed64. 99 | TYPE_SFIXED64 = 16; 100 | // Field type sint32. 101 | TYPE_SINT32 = 17; 102 | // Field type sint64. 103 | TYPE_SINT64 = 18; 104 | }; 105 | 106 | // Whether a field is optional, required, or repeated. 107 | enum Cardinality { 108 | // For fields with unknown cardinality. 109 | CARDINALITY_UNKNOWN = 0; 110 | // For optional fields. 111 | CARDINALITY_OPTIONAL = 1; 112 | // For required fields. Proto2 syntax only. 113 | CARDINALITY_REQUIRED = 2; 114 | // For repeated fields. 115 | CARDINALITY_REPEATED = 3; 116 | }; 117 | 118 | // The field type. 119 | Kind kind = 1; 120 | // The field cardinality. 121 | Cardinality cardinality = 2; 122 | // The field number. 123 | int32 number = 3; 124 | // The field name. 125 | string name = 4; 126 | // The field type URL, without the scheme, for message or enumeration 127 | // types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. 128 | string type_url = 6; 129 | // The index of the field type in `Type.oneofs`, for message or enumeration 130 | // types. The first type has index 1; zero means the type is not in the list. 131 | int32 oneof_index = 7; 132 | // Whether to use alternative packed wire representation. 133 | bool packed = 8; 134 | // The protocol buffer options. 135 | repeated Option options = 9; 136 | // The field JSON name. 137 | string json_name = 10; 138 | // The string value of the default value of this field. Proto2 syntax only. 139 | string default_value = 11; 140 | } 141 | 142 | // Enum type definition. 143 | message Enum { 144 | // Enum type name. 145 | string name = 1; 146 | // Enum value definitions. 147 | repeated EnumValue enumvalue = 2; 148 | // Protocol buffer options. 149 | repeated Option options = 3; 150 | // The source context. 151 | SourceContext source_context = 4; 152 | // The source syntax. 153 | Syntax syntax = 5; 154 | } 155 | 156 | // Enum value definition. 157 | message EnumValue { 158 | // Enum value name. 159 | string name = 1; 160 | // Enum value number. 161 | int32 number = 2; 162 | // Protocol buffer options. 163 | repeated Option options = 3; 164 | } 165 | 166 | // A protocol buffer option, which can be attached to a message, field, 167 | // enumeration, etc. 168 | message Option { 169 | // The option's name. For protobuf built-in options (options defined in 170 | // descriptor.proto), this is the short name. For example, `"map_entry"`. 171 | // For custom options, it should be the fully-qualified name. For example, 172 | // `"google.api.http"`. 173 | string name = 1; 174 | // The option's value packed in an Any message. If the value is a primitive, 175 | // the corresponding wrapper type defined in google/protobuf/wrappers.proto 176 | // should be used. If the value is an enum, it should be stored as an int32 177 | // value using the google.protobuf.Int32Value type. 178 | Any value = 2; 179 | } 180 | 181 | // The syntax in which a protocol buffer element is defined. 182 | enum Syntax { 183 | // Syntax `proto2`. 184 | SYNTAX_PROTO2 = 0; 185 | // Syntax `proto3`. 186 | SYNTAX_PROTO3 = 1; 187 | } 188 | -------------------------------------------------------------------------------- /test/codecs_test.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: codecs_test.proto 3 | 4 | package test 5 | 6 | import ( 7 | fmt "fmt" 8 | pmongo "github.com/amsokol/mongo-go-driver-protobuf/pmongo" 9 | proto "github.com/golang/protobuf/proto" 10 | timestamp "github.com/golang/protobuf/ptypes/timestamp" 11 | wrappers "github.com/golang/protobuf/ptypes/wrappers" 12 | math "math" 13 | ) 14 | 15 | // Reference imports to suppress errors if they are not otherwise used. 16 | var _ = proto.Marshal 17 | var _ = fmt.Errorf 18 | var _ = math.Inf 19 | 20 | // This is a compile-time assertion to ensure that this generated file 21 | // is compatible with the proto package it is being compiled against. 22 | // A compilation error at this line likely means your copy of the 23 | // proto package needs to be updated. 24 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 25 | 26 | type Data struct { 27 | BoolValue *wrappers.BoolValue `protobuf:"bytes,1,opt,name=boolValue,proto3" json:"boolValue,omitempty"` 28 | BytesValue *wrappers.BytesValue `protobuf:"bytes,2,opt,name=bytesValue,proto3" json:"bytesValue,omitempty"` 29 | DoubleValue *wrappers.DoubleValue `protobuf:"bytes,3,opt,name=doubleValue,proto3" json:"doubleValue,omitempty"` 30 | FloatValue *wrappers.FloatValue `protobuf:"bytes,4,opt,name=floatValue,proto3" json:"floatValue,omitempty"` 31 | Int32Value *wrappers.Int32Value `protobuf:"bytes,5,opt,name=int32Value,proto3" json:"int32Value,omitempty"` 32 | Int64Value *wrappers.Int64Value `protobuf:"bytes,6,opt,name=int64Value,proto3" json:"int64Value,omitempty"` 33 | StringValue *wrappers.StringValue `protobuf:"bytes,7,opt,name=stringValue,proto3" json:"stringValue,omitempty"` 34 | Uint32Value *wrappers.UInt32Value `protobuf:"bytes,8,opt,name=uint32Value,proto3" json:"uint32Value,omitempty"` 35 | Uint64Value *wrappers.UInt64Value `protobuf:"bytes,9,opt,name=uint64Value,proto3" json:"uint64Value,omitempty"` 36 | Timestamp *timestamp.Timestamp `protobuf:"bytes,10,opt,name=timestamp,proto3" json:"timestamp,omitempty"` 37 | Id *pmongo.ObjectId `protobuf:"bytes,11,opt,name=id,proto3" json:"id,omitempty"` 38 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 39 | XXX_unrecognized []byte `json:"-"` 40 | XXX_sizecache int32 `json:"-"` 41 | } 42 | 43 | func (m *Data) Reset() { *m = Data{} } 44 | func (m *Data) String() string { return proto.CompactTextString(m) } 45 | func (*Data) ProtoMessage() {} 46 | func (*Data) Descriptor() ([]byte, []int) { 47 | return fileDescriptor_b2b3e361c7bc6717, []int{0} 48 | } 49 | 50 | func (m *Data) XXX_Unmarshal(b []byte) error { 51 | return xxx_messageInfo_Data.Unmarshal(m, b) 52 | } 53 | func (m *Data) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 54 | return xxx_messageInfo_Data.Marshal(b, m, deterministic) 55 | } 56 | func (m *Data) XXX_Merge(src proto.Message) { 57 | xxx_messageInfo_Data.Merge(m, src) 58 | } 59 | func (m *Data) XXX_Size() int { 60 | return xxx_messageInfo_Data.Size(m) 61 | } 62 | func (m *Data) XXX_DiscardUnknown() { 63 | xxx_messageInfo_Data.DiscardUnknown(m) 64 | } 65 | 66 | var xxx_messageInfo_Data proto.InternalMessageInfo 67 | 68 | func (m *Data) GetBoolValue() *wrappers.BoolValue { 69 | if m != nil { 70 | return m.BoolValue 71 | } 72 | return nil 73 | } 74 | 75 | func (m *Data) GetBytesValue() *wrappers.BytesValue { 76 | if m != nil { 77 | return m.BytesValue 78 | } 79 | return nil 80 | } 81 | 82 | func (m *Data) GetDoubleValue() *wrappers.DoubleValue { 83 | if m != nil { 84 | return m.DoubleValue 85 | } 86 | return nil 87 | } 88 | 89 | func (m *Data) GetFloatValue() *wrappers.FloatValue { 90 | if m != nil { 91 | return m.FloatValue 92 | } 93 | return nil 94 | } 95 | 96 | func (m *Data) GetInt32Value() *wrappers.Int32Value { 97 | if m != nil { 98 | return m.Int32Value 99 | } 100 | return nil 101 | } 102 | 103 | func (m *Data) GetInt64Value() *wrappers.Int64Value { 104 | if m != nil { 105 | return m.Int64Value 106 | } 107 | return nil 108 | } 109 | 110 | func (m *Data) GetStringValue() *wrappers.StringValue { 111 | if m != nil { 112 | return m.StringValue 113 | } 114 | return nil 115 | } 116 | 117 | func (m *Data) GetUint32Value() *wrappers.UInt32Value { 118 | if m != nil { 119 | return m.Uint32Value 120 | } 121 | return nil 122 | } 123 | 124 | func (m *Data) GetUint64Value() *wrappers.UInt64Value { 125 | if m != nil { 126 | return m.Uint64Value 127 | } 128 | return nil 129 | } 130 | 131 | func (m *Data) GetTimestamp() *timestamp.Timestamp { 132 | if m != nil { 133 | return m.Timestamp 134 | } 135 | return nil 136 | } 137 | 138 | func (m *Data) GetId() *pmongo.ObjectId { 139 | if m != nil { 140 | return m.Id 141 | } 142 | return nil 143 | } 144 | 145 | func init() { 146 | proto.RegisterType((*Data)(nil), "test.Data") 147 | } 148 | 149 | func init() { proto.RegisterFile("codecs_test.proto", fileDescriptor_b2b3e361c7bc6717) } 150 | 151 | var fileDescriptor_b2b3e361c7bc6717 = []byte{ 152 | // 319 bytes of a gzipped FileDescriptorProto 153 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0xd2, 0xcf, 0x4b, 0xc3, 0x30, 154 | 0x14, 0xc0, 0x71, 0x36, 0xb7, 0xe9, 0xb2, 0x8b, 0x16, 0x84, 0x31, 0x45, 0x87, 0x27, 0x4f, 0x19, 155 | 0x6c, 0x22, 0x82, 0xe0, 0x41, 0x86, 0xb0, 0x93, 0x10, 0x7f, 0x5c, 0x25, 0x59, 0xb2, 0x12, 0x69, 156 | 0xfb, 0x4a, 0x93, 0x22, 0xfe, 0x17, 0xfe, 0xc9, 0x92, 0xa4, 0x69, 0x83, 0x23, 0xde, 0x46, 0xf7, 157 | 0xfd, 0x24, 0x2f, 0xf0, 0xd0, 0xc9, 0x16, 0xb8, 0xd8, 0xaa, 0x0f, 0x2d, 0x94, 0xc6, 0x65, 0x05, 158 | 0x1a, 0x92, 0x81, 0xf9, 0x3d, 0xbb, 0x4c, 0x01, 0xd2, 0x4c, 0x2c, 0xec, 0x37, 0x56, 0xef, 0x16, 159 | 0x5a, 0xe6, 0x42, 0x69, 0x9a, 0x97, 0x2e, 0x9b, 0x5d, 0xfc, 0x0d, 0xbe, 0x2a, 0x5a, 0x96, 0xa2, 160 | 0x52, 0xcd, 0xff, 0xa7, 0x65, 0x0e, 0x45, 0x0a, 0x0b, 0x60, 0x9f, 0x62, 0xab, 0x25, 0x77, 0x9f, 161 | 0xaf, 0x7e, 0x86, 0x68, 0xb0, 0xa6, 0x9a, 0x26, 0x77, 0x68, 0xcc, 0x00, 0xb2, 0x77, 0x9a, 0xd5, 162 | 0x62, 0xda, 0x9b, 0xf7, 0xae, 0x27, 0xcb, 0x19, 0x76, 0x67, 0x62, 0x7f, 0x26, 0x7e, 0xf4, 0x05, 163 | 0xe9, 0xe2, 0xe4, 0x1e, 0x21, 0xf6, 0xad, 0x85, 0x72, 0xb4, 0x6f, 0xe9, 0xd9, 0x3e, 0x6d, 0x13, 164 | 0x12, 0xe4, 0xc9, 0x03, 0x9a, 0x70, 0xa8, 0x59, 0x26, 0x9c, 0x3e, 0xb0, 0xfa, 0x7c, 0x4f, 0xaf, 165 | 0xbb, 0x86, 0x84, 0xc0, 0x5c, 0xbe, 0xcb, 0x80, 0x6a, 0xc7, 0x07, 0x91, 0xcb, 0x9f, 0xda, 0x84, 166 | 0x04, 0xb9, 0xc1, 0xb2, 0xd0, 0xab, 0xa5, 0xc3, 0xc3, 0x08, 0xde, 0xb4, 0x09, 0x09, 0xf2, 0x06, 167 | 0xdf, 0xde, 0x38, 0x3c, 0x8a, 0xe3, 0x26, 0x21, 0x41, 0x6e, 0x9e, 0xad, 0x74, 0x25, 0x8b, 0xd4, 168 | 0xe9, 0xc3, 0xc8, 0xb3, 0x5f, 0xba, 0x86, 0x84, 0xc0, 0xf8, 0x3a, 0x18, 0xfd, 0x28, 0xe2, 0xdf, 169 | 0x82, 0xd9, 0x43, 0xe0, 0xbd, 0x9f, 0x7e, 0xfc, 0x8f, 0xf7, 0xe3, 0x87, 0xc0, 0x6c, 0x4b, 0xbb, 170 | 0x80, 0x53, 0x14, 0xd9, 0x96, 0x57, 0x5f, 0x90, 0x2e, 0x4e, 0xe6, 0xa8, 0x2f, 0xf9, 0x74, 0x62, 171 | 0xc9, 0x31, 0x76, 0x4b, 0x89, 0x9f, 0xed, 0x52, 0x6e, 0x38, 0xe9, 0x4b, 0xce, 0x46, 0xf6, 0x80, 172 | 0xd5, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x39, 0xb1, 0xfa, 0xb9, 0x0c, 0x03, 0x00, 0x00, 173 | } 174 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/api.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | import "google/protobuf/source_context.proto"; 36 | import "google/protobuf/type.proto"; 37 | 38 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 39 | option java_package = "com.google.protobuf"; 40 | option java_outer_classname = "ApiProto"; 41 | option java_multiple_files = true; 42 | option objc_class_prefix = "GPB"; 43 | option go_package = "google.golang.org/genproto/protobuf/api;api"; 44 | 45 | // Api is a light-weight descriptor for an API Interface. 46 | // 47 | // Interfaces are also described as "protocol buffer services" in some contexts, 48 | // such as by the "service" keyword in a .proto file, but they are different 49 | // from API Services, which represent a concrete implementation of an interface 50 | // as opposed to simply a description of methods and bindings. They are also 51 | // sometimes simply referred to as "APIs" in other contexts, such as the name of 52 | // this message itself. See https://cloud.google.com/apis/design/glossary for 53 | // detailed terminology. 54 | message Api { 55 | 56 | // The fully qualified name of this interface, including package name 57 | // followed by the interface's simple name. 58 | string name = 1; 59 | 60 | // The methods of this interface, in unspecified order. 61 | repeated Method methods = 2; 62 | 63 | // Any metadata attached to the interface. 64 | repeated Option options = 3; 65 | 66 | // A version string for this interface. If specified, must have the form 67 | // `major-version.minor-version`, as in `1.10`. If the minor version is 68 | // omitted, it defaults to zero. If the entire version field is empty, the 69 | // major version is derived from the package name, as outlined below. If the 70 | // field is not empty, the version in the package name will be verified to be 71 | // consistent with what is provided here. 72 | // 73 | // The versioning schema uses [semantic 74 | // versioning](http://semver.org) where the major version number 75 | // indicates a breaking change and the minor version an additive, 76 | // non-breaking change. Both version numbers are signals to users 77 | // what to expect from different versions, and should be carefully 78 | // chosen based on the product plan. 79 | // 80 | // The major version is also reflected in the package name of the 81 | // interface, which must end in `v`, as in 82 | // `google.feature.v1`. For major versions 0 and 1, the suffix can 83 | // be omitted. Zero major versions must only be used for 84 | // experimental, non-GA interfaces. 85 | // 86 | // 87 | string version = 4; 88 | 89 | // Source context for the protocol buffer service represented by this 90 | // message. 91 | SourceContext source_context = 5; 92 | 93 | // Included interfaces. See [Mixin][]. 94 | repeated Mixin mixins = 6; 95 | 96 | // The source syntax of the service. 97 | Syntax syntax = 7; 98 | } 99 | 100 | // Method represents a method of an API interface. 101 | message Method { 102 | 103 | // The simple name of this method. 104 | string name = 1; 105 | 106 | // A URL of the input message type. 107 | string request_type_url = 2; 108 | 109 | // If true, the request is streamed. 110 | bool request_streaming = 3; 111 | 112 | // The URL of the output message type. 113 | string response_type_url = 4; 114 | 115 | // If true, the response is streamed. 116 | bool response_streaming = 5; 117 | 118 | // Any metadata attached to the method. 119 | repeated Option options = 6; 120 | 121 | // The source syntax of this method. 122 | Syntax syntax = 7; 123 | } 124 | 125 | // Declares an API Interface to be included in this interface. The including 126 | // interface must redeclare all the methods from the included interface, but 127 | // documentation and options are inherited as follows: 128 | // 129 | // - If after comment and whitespace stripping, the documentation 130 | // string of the redeclared method is empty, it will be inherited 131 | // from the original method. 132 | // 133 | // - Each annotation belonging to the service config (http, 134 | // visibility) which is not set in the redeclared method will be 135 | // inherited. 136 | // 137 | // - If an http annotation is inherited, the path pattern will be 138 | // modified as follows. Any version prefix will be replaced by the 139 | // version of the including interface plus the [root][] path if 140 | // specified. 141 | // 142 | // Example of a simple mixin: 143 | // 144 | // package google.acl.v1; 145 | // service AccessControl { 146 | // // Get the underlying ACL object. 147 | // rpc GetAcl(GetAclRequest) returns (Acl) { 148 | // option (google.api.http).get = "/v1/{resource=**}:getAcl"; 149 | // } 150 | // } 151 | // 152 | // package google.storage.v2; 153 | // service Storage { 154 | // rpc GetAcl(GetAclRequest) returns (Acl); 155 | // 156 | // // Get a data record. 157 | // rpc GetData(GetDataRequest) returns (Data) { 158 | // option (google.api.http).get = "/v2/{resource=**}"; 159 | // } 160 | // } 161 | // 162 | // Example of a mixin configuration: 163 | // 164 | // apis: 165 | // - name: google.storage.v2.Storage 166 | // mixins: 167 | // - name: google.acl.v1.AccessControl 168 | // 169 | // The mixin construct implies that all methods in `AccessControl` are 170 | // also declared with same name and request/response types in 171 | // `Storage`. A documentation generator or annotation processor will 172 | // see the effective `Storage.GetAcl` method after inherting 173 | // documentation and annotations as follows: 174 | // 175 | // service Storage { 176 | // // Get the underlying ACL object. 177 | // rpc GetAcl(GetAclRequest) returns (Acl) { 178 | // option (google.api.http).get = "/v2/{resource=**}:getAcl"; 179 | // } 180 | // ... 181 | // } 182 | // 183 | // Note how the version in the path pattern changed from `v1` to `v2`. 184 | // 185 | // If the `root` field in the mixin is specified, it should be a 186 | // relative path under which inherited HTTP paths are placed. Example: 187 | // 188 | // apis: 189 | // - name: google.storage.v2.Storage 190 | // mixins: 191 | // - name: google.acl.v1.AccessControl 192 | // root: acls 193 | // 194 | // This implies the following inherited HTTP annotation: 195 | // 196 | // service Storage { 197 | // // Get the underlying ACL object. 198 | // rpc GetAcl(GetAclRequest) returns (Acl) { 199 | // option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; 200 | // } 201 | // ... 202 | // } 203 | message Mixin { 204 | // The fully qualified name of the interface which is included. 205 | string name = 1; 206 | 207 | // If non-empty specifies a path under which inherited HTTP paths 208 | // are rooted. 209 | string root = 2; 210 | } 211 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/compiler/plugin.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // WARNING: The plugin interface is currently EXPERIMENTAL and is subject to 34 | // change. 35 | // 36 | // protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is 37 | // just a program that reads a CodeGeneratorRequest from stdin and writes a 38 | // CodeGeneratorResponse to stdout. 39 | // 40 | // Plugins written using C++ can use google/protobuf/compiler/plugin.h instead 41 | // of dealing with the raw protocol defined here. 42 | // 43 | // A plugin executable needs only to be placed somewhere in the path. The 44 | // plugin should be named "protoc-gen-$NAME", and will then be used when the 45 | // flag "--${NAME}_out" is passed to protoc. 46 | 47 | syntax = "proto2"; 48 | package google.protobuf.compiler; 49 | option java_package = "com.google.protobuf.compiler"; 50 | option java_outer_classname = "PluginProtos"; 51 | 52 | option go_package = "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go"; 53 | 54 | import "google/protobuf/descriptor.proto"; 55 | 56 | // The version number of protocol compiler. 57 | message Version { 58 | optional int32 major = 1; 59 | optional int32 minor = 2; 60 | optional int32 patch = 3; 61 | // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should 62 | // be empty for mainline stable releases. 63 | optional string suffix = 4; 64 | } 65 | 66 | // An encoded CodeGeneratorRequest is written to the plugin's stdin. 67 | message CodeGeneratorRequest { 68 | // The .proto files that were explicitly listed on the command-line. The 69 | // code generator should generate code only for these files. Each file's 70 | // descriptor will be included in proto_file, below. 71 | repeated string file_to_generate = 1; 72 | 73 | // The generator parameter passed on the command-line. 74 | optional string parameter = 2; 75 | 76 | // FileDescriptorProtos for all files in files_to_generate and everything 77 | // they import. The files will appear in topological order, so each file 78 | // appears before any file that imports it. 79 | // 80 | // protoc guarantees that all proto_files will be written after 81 | // the fields above, even though this is not technically guaranteed by the 82 | // protobuf wire format. This theoretically could allow a plugin to stream 83 | // in the FileDescriptorProtos and handle them one by one rather than read 84 | // the entire set into memory at once. However, as of this writing, this 85 | // is not similarly optimized on protoc's end -- it will store all fields in 86 | // memory at once before sending them to the plugin. 87 | // 88 | // Type names of fields and extensions in the FileDescriptorProto are always 89 | // fully qualified. 90 | repeated FileDescriptorProto proto_file = 15; 91 | 92 | // The version number of protocol compiler. 93 | optional Version compiler_version = 3; 94 | 95 | } 96 | 97 | // The plugin writes an encoded CodeGeneratorResponse to stdout. 98 | message CodeGeneratorResponse { 99 | // Error message. If non-empty, code generation failed. The plugin process 100 | // should exit with status code zero even if it reports an error in this way. 101 | // 102 | // This should be used to indicate errors in .proto files which prevent the 103 | // code generator from generating correct code. Errors which indicate a 104 | // problem in protoc itself -- such as the input CodeGeneratorRequest being 105 | // unparseable -- should be reported by writing a message to stderr and 106 | // exiting with a non-zero status code. 107 | optional string error = 1; 108 | 109 | // Represents a single generated file. 110 | message File { 111 | // The file name, relative to the output directory. The name must not 112 | // contain "." or ".." components and must be relative, not be absolute (so, 113 | // the file cannot lie outside the output directory). "/" must be used as 114 | // the path separator, not "\". 115 | // 116 | // If the name is omitted, the content will be appended to the previous 117 | // file. This allows the generator to break large files into small chunks, 118 | // and allows the generated text to be streamed back to protoc so that large 119 | // files need not reside completely in memory at one time. Note that as of 120 | // this writing protoc does not optimize for this -- it will read the entire 121 | // CodeGeneratorResponse before writing files to disk. 122 | optional string name = 1; 123 | 124 | // If non-empty, indicates that the named file should already exist, and the 125 | // content here is to be inserted into that file at a defined insertion 126 | // point. This feature allows a code generator to extend the output 127 | // produced by another code generator. The original generator may provide 128 | // insertion points by placing special annotations in the file that look 129 | // like: 130 | // @@protoc_insertion_point(NAME) 131 | // The annotation can have arbitrary text before and after it on the line, 132 | // which allows it to be placed in a comment. NAME should be replaced with 133 | // an identifier naming the point -- this is what other generators will use 134 | // as the insertion_point. Code inserted at this point will be placed 135 | // immediately above the line containing the insertion point (thus multiple 136 | // insertions to the same point will come out in the order they were added). 137 | // The double-@ is intended to make it unlikely that the generated code 138 | // could contain things that look like insertion points by accident. 139 | // 140 | // For example, the C++ code generator places the following line in the 141 | // .pb.h files that it generates: 142 | // // @@protoc_insertion_point(namespace_scope) 143 | // This line appears within the scope of the file's package namespace, but 144 | // outside of any particular class. Another plugin can then specify the 145 | // insertion_point "namespace_scope" to generate additional classes or 146 | // other declarations that should be placed in this scope. 147 | // 148 | // Note that if the line containing the insertion point begins with 149 | // whitespace, the same whitespace will be added to every line of the 150 | // inserted text. This is useful for languages like Python, where 151 | // indentation matters. In these languages, the insertion point comment 152 | // should be indented the same amount as any inserted code will need to be 153 | // in order to work correctly in that context. 154 | // 155 | // The code generator that generates the initial file and the one which 156 | // inserts into it must both run as part of a single invocation of protoc. 157 | // Code generators are executed in the order in which they appear on the 158 | // command line. 159 | // 160 | // If |insertion_point| is present, |name| must also be present. 161 | optional string insertion_point = 2; 162 | 163 | // The file contents. 164 | optional string content = 15; 165 | } 166 | repeated File file = 15; 167 | } 168 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/field_mask.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "FieldMaskProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask"; 41 | 42 | // `FieldMask` represents a set of symbolic field paths, for example: 43 | // 44 | // paths: "f.a" 45 | // paths: "f.b.d" 46 | // 47 | // Here `f` represents a field in some root message, `a` and `b` 48 | // fields in the message found in `f`, and `d` a field found in the 49 | // message in `f.b`. 50 | // 51 | // Field masks are used to specify a subset of fields that should be 52 | // returned by a get operation or modified by an update operation. 53 | // Field masks also have a custom JSON encoding (see below). 54 | // 55 | // # Field Masks in Projections 56 | // 57 | // When used in the context of a projection, a response message or 58 | // sub-message is filtered by the API to only contain those fields as 59 | // specified in the mask. For example, if the mask in the previous 60 | // example is applied to a response message as follows: 61 | // 62 | // f { 63 | // a : 22 64 | // b { 65 | // d : 1 66 | // x : 2 67 | // } 68 | // y : 13 69 | // } 70 | // z: 8 71 | // 72 | // The result will not contain specific values for fields x,y and z 73 | // (their value will be set to the default, and omitted in proto text 74 | // output): 75 | // 76 | // 77 | // f { 78 | // a : 22 79 | // b { 80 | // d : 1 81 | // } 82 | // } 83 | // 84 | // A repeated field is not allowed except at the last position of a 85 | // paths string. 86 | // 87 | // If a FieldMask object is not present in a get operation, the 88 | // operation applies to all fields (as if a FieldMask of all fields 89 | // had been specified). 90 | // 91 | // Note that a field mask does not necessarily apply to the 92 | // top-level response message. In case of a REST get operation, the 93 | // field mask applies directly to the response, but in case of a REST 94 | // list operation, the mask instead applies to each individual message 95 | // in the returned resource list. In case of a REST custom method, 96 | // other definitions may be used. Where the mask applies will be 97 | // clearly documented together with its declaration in the API. In 98 | // any case, the effect on the returned resource/resources is required 99 | // behavior for APIs. 100 | // 101 | // # Field Masks in Update Operations 102 | // 103 | // A field mask in update operations specifies which fields of the 104 | // targeted resource are going to be updated. The API is required 105 | // to only change the values of the fields as specified in the mask 106 | // and leave the others untouched. If a resource is passed in to 107 | // describe the updated values, the API ignores the values of all 108 | // fields not covered by the mask. 109 | // 110 | // If a repeated field is specified for an update operation, the existing 111 | // repeated values in the target resource will be overwritten by the new values. 112 | // Note that a repeated field is only allowed in the last position of a `paths` 113 | // string. 114 | // 115 | // If a sub-message is specified in the last position of the field mask for an 116 | // update operation, then the existing sub-message in the target resource is 117 | // overwritten. Given the target message: 118 | // 119 | // f { 120 | // b { 121 | // d : 1 122 | // x : 2 123 | // } 124 | // c : 1 125 | // } 126 | // 127 | // And an update message: 128 | // 129 | // f { 130 | // b { 131 | // d : 10 132 | // } 133 | // } 134 | // 135 | // then if the field mask is: 136 | // 137 | // paths: "f.b" 138 | // 139 | // then the result will be: 140 | // 141 | // f { 142 | // b { 143 | // d : 10 144 | // } 145 | // c : 1 146 | // } 147 | // 148 | // However, if the update mask was: 149 | // 150 | // paths: "f.b.d" 151 | // 152 | // then the result would be: 153 | // 154 | // f { 155 | // b { 156 | // d : 10 157 | // x : 2 158 | // } 159 | // c : 1 160 | // } 161 | // 162 | // In order to reset a field's value to the default, the field must 163 | // be in the mask and set to the default value in the provided resource. 164 | // Hence, in order to reset all fields of a resource, provide a default 165 | // instance of the resource and set all fields in the mask, or do 166 | // not provide a mask as described below. 167 | // 168 | // If a field mask is not present on update, the operation applies to 169 | // all fields (as if a field mask of all fields has been specified). 170 | // Note that in the presence of schema evolution, this may mean that 171 | // fields the client does not know and has therefore not filled into 172 | // the request will be reset to their default. If this is unwanted 173 | // behavior, a specific service may require a client to always specify 174 | // a field mask, producing an error if not. 175 | // 176 | // As with get operations, the location of the resource which 177 | // describes the updated values in the request message depends on the 178 | // operation kind. In any case, the effect of the field mask is 179 | // required to be honored by the API. 180 | // 181 | // ## Considerations for HTTP REST 182 | // 183 | // The HTTP kind of an update operation which uses a field mask must 184 | // be set to PATCH instead of PUT in order to satisfy HTTP semantics 185 | // (PUT must only be used for full updates). 186 | // 187 | // # JSON Encoding of Field Masks 188 | // 189 | // In JSON, a field mask is encoded as a single string where paths are 190 | // separated by a comma. Fields name in each path are converted 191 | // to/from lower-camel naming conventions. 192 | // 193 | // As an example, consider the following message declarations: 194 | // 195 | // message Profile { 196 | // User user = 1; 197 | // Photo photo = 2; 198 | // } 199 | // message User { 200 | // string display_name = 1; 201 | // string address = 2; 202 | // } 203 | // 204 | // In proto a field mask for `Profile` may look as such: 205 | // 206 | // mask { 207 | // paths: "user.display_name" 208 | // paths: "photo" 209 | // } 210 | // 211 | // In JSON, the same mask is represented as below: 212 | // 213 | // { 214 | // mask: "user.displayName,photo" 215 | // } 216 | // 217 | // # Field Masks and Oneof Fields 218 | // 219 | // Field masks treat fields in oneofs just as regular fields. Consider the 220 | // following message: 221 | // 222 | // message SampleMessage { 223 | // oneof test_oneof { 224 | // string name = 4; 225 | // SubMessage sub_message = 9; 226 | // } 227 | // } 228 | // 229 | // The field mask can be: 230 | // 231 | // mask { 232 | // paths: "name" 233 | // } 234 | // 235 | // Or: 236 | // 237 | // mask { 238 | // paths: "sub_message" 239 | // } 240 | // 241 | // Note that oneof type names ("test_oneof" in this case) cannot be used in 242 | // paths. 243 | // 244 | // ## Field Mask Verification 245 | // 246 | // The implementation of any API method which has a FieldMask type field in the 247 | // request should verify the included field paths, and return an 248 | // `INVALID_ARGUMENT` error if any path is duplicated or unmappable. 249 | message FieldMask { 250 | // The set of field mask paths. 251 | repeated string paths = 1; 252 | } 253 | -------------------------------------------------------------------------------- /examples/mongodb-rw/data.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: data.proto 3 | 4 | package main 5 | 6 | import ( 7 | fmt "fmt" 8 | pmongo "github.com/amsokol/mongo-go-driver-protobuf/pmongo" 9 | _ "github.com/amsokol/protoc-gen-gotag/tagger" 10 | proto "github.com/golang/protobuf/proto" 11 | timestamp "github.com/golang/protobuf/ptypes/timestamp" 12 | wrappers "github.com/golang/protobuf/ptypes/wrappers" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Data struct { 28 | Id *pmongo.ObjectId `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" bson:"_id,omitempty"` 29 | BoolValue bool `protobuf:"varint,2,opt,name=boolValue,proto3" json:"boolValue,omitempty"` 30 | BoolProtoValue *wrappers.BoolValue `protobuf:"bytes,3,opt,name=boolProtoValue,proto3" json:"boolProtoValue,omitempty"` 31 | BytesValue []byte `protobuf:"bytes,4,opt,name=bytesValue,proto3" json:"bytesValue,omitempty"` 32 | BytesProtoValue *wrappers.BytesValue `protobuf:"bytes,5,opt,name=bytesProtoValue,proto3" json:"bytesProtoValue,omitempty"` 33 | DoubleValue float64 `protobuf:"fixed64,6,opt,name=doubleValue,proto3" json:"doubleValue,omitempty"` 34 | DoubleProtoValue *wrappers.DoubleValue `protobuf:"bytes,7,opt,name=doubleProtoValue,proto3" json:"doubleProtoValue,omitempty"` 35 | FloatValue float32 `protobuf:"fixed32,8,opt,name=floatValue,proto3" json:"floatValue,omitempty"` 36 | FloatProtoValue *wrappers.FloatValue `protobuf:"bytes,9,opt,name=floatProtoValue,proto3" json:"floatProtoValue,omitempty"` 37 | Int32Value int32 `protobuf:"varint,10,opt,name=int32Value,proto3" json:"int32Value,omitempty"` 38 | Int32ProtoValue *wrappers.Int32Value `protobuf:"bytes,11,opt,name=int32ProtoValue,proto3" json:"int32ProtoValue,omitempty"` 39 | Int64Value int64 `protobuf:"varint,12,opt,name=int64Value,proto3" json:"int64Value,omitempty"` 40 | Int64ProtoValue *wrappers.Int64Value `protobuf:"bytes,13,opt,name=int64ProtoValue,proto3" json:"int64ProtoValue,omitempty"` 41 | StringValue string `protobuf:"bytes,14,opt,name=stringValue,proto3" json:"stringValue,omitempty"` 42 | StringProtoValue *wrappers.StringValue `protobuf:"bytes,15,opt,name=stringProtoValue,proto3" json:"stringProtoValue,omitempty"` 43 | Uint32Value uint32 `protobuf:"varint,16,opt,name=uint32Value,proto3" json:"uint32Value,omitempty"` 44 | Uint32ProtoValue *wrappers.UInt32Value `protobuf:"bytes,17,opt,name=uint32ProtoValue,proto3" json:"uint32ProtoValue,omitempty"` 45 | Uint64Value uint64 `protobuf:"varint,18,opt,name=uint64Value,proto3" json:"uint64Value,omitempty"` 46 | Uint64ProtoValue *wrappers.UInt64Value `protobuf:"bytes,19,opt,name=uint64ProtoValue,proto3" json:"uint64ProtoValue,omitempty"` 47 | Timestamp *timestamp.Timestamp `protobuf:"bytes,20,opt,name=timestamp,proto3" json:"timestamp,omitempty"` 48 | XXX_NoUnkeyedLiteral struct{} `json:"-" bson:"-"` 49 | XXX_unrecognized []byte `json:"-" bson:"-"` 50 | XXX_sizecache int32 `json:"-" bson:"-"` 51 | } 52 | 53 | func (m *Data) Reset() { *m = Data{} } 54 | func (m *Data) String() string { return proto.CompactTextString(m) } 55 | func (*Data) ProtoMessage() {} 56 | func (*Data) Descriptor() ([]byte, []int) { 57 | return fileDescriptor_871986018790d2fd, []int{0} 58 | } 59 | 60 | func (m *Data) XXX_Unmarshal(b []byte) error { 61 | return xxx_messageInfo_Data.Unmarshal(m, b) 62 | } 63 | func (m *Data) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 64 | return xxx_messageInfo_Data.Marshal(b, m, deterministic) 65 | } 66 | func (m *Data) XXX_Merge(src proto.Message) { 67 | xxx_messageInfo_Data.Merge(m, src) 68 | } 69 | func (m *Data) XXX_Size() int { 70 | return xxx_messageInfo_Data.Size(m) 71 | } 72 | func (m *Data) XXX_DiscardUnknown() { 73 | xxx_messageInfo_Data.DiscardUnknown(m) 74 | } 75 | 76 | var xxx_messageInfo_Data proto.InternalMessageInfo 77 | 78 | func (m *Data) GetId() *pmongo.ObjectId { 79 | if m != nil { 80 | return m.Id 81 | } 82 | return nil 83 | } 84 | 85 | func (m *Data) GetBoolValue() bool { 86 | if m != nil { 87 | return m.BoolValue 88 | } 89 | return false 90 | } 91 | 92 | func (m *Data) GetBoolProtoValue() *wrappers.BoolValue { 93 | if m != nil { 94 | return m.BoolProtoValue 95 | } 96 | return nil 97 | } 98 | 99 | func (m *Data) GetBytesValue() []byte { 100 | if m != nil { 101 | return m.BytesValue 102 | } 103 | return nil 104 | } 105 | 106 | func (m *Data) GetBytesProtoValue() *wrappers.BytesValue { 107 | if m != nil { 108 | return m.BytesProtoValue 109 | } 110 | return nil 111 | } 112 | 113 | func (m *Data) GetDoubleValue() float64 { 114 | if m != nil { 115 | return m.DoubleValue 116 | } 117 | return 0 118 | } 119 | 120 | func (m *Data) GetDoubleProtoValue() *wrappers.DoubleValue { 121 | if m != nil { 122 | return m.DoubleProtoValue 123 | } 124 | return nil 125 | } 126 | 127 | func (m *Data) GetFloatValue() float32 { 128 | if m != nil { 129 | return m.FloatValue 130 | } 131 | return 0 132 | } 133 | 134 | func (m *Data) GetFloatProtoValue() *wrappers.FloatValue { 135 | if m != nil { 136 | return m.FloatProtoValue 137 | } 138 | return nil 139 | } 140 | 141 | func (m *Data) GetInt32Value() int32 { 142 | if m != nil { 143 | return m.Int32Value 144 | } 145 | return 0 146 | } 147 | 148 | func (m *Data) GetInt32ProtoValue() *wrappers.Int32Value { 149 | if m != nil { 150 | return m.Int32ProtoValue 151 | } 152 | return nil 153 | } 154 | 155 | func (m *Data) GetInt64Value() int64 { 156 | if m != nil { 157 | return m.Int64Value 158 | } 159 | return 0 160 | } 161 | 162 | func (m *Data) GetInt64ProtoValue() *wrappers.Int64Value { 163 | if m != nil { 164 | return m.Int64ProtoValue 165 | } 166 | return nil 167 | } 168 | 169 | func (m *Data) GetStringValue() string { 170 | if m != nil { 171 | return m.StringValue 172 | } 173 | return "" 174 | } 175 | 176 | func (m *Data) GetStringProtoValue() *wrappers.StringValue { 177 | if m != nil { 178 | return m.StringProtoValue 179 | } 180 | return nil 181 | } 182 | 183 | func (m *Data) GetUint32Value() uint32 { 184 | if m != nil { 185 | return m.Uint32Value 186 | } 187 | return 0 188 | } 189 | 190 | func (m *Data) GetUint32ProtoValue() *wrappers.UInt32Value { 191 | if m != nil { 192 | return m.Uint32ProtoValue 193 | } 194 | return nil 195 | } 196 | 197 | func (m *Data) GetUint64Value() uint64 { 198 | if m != nil { 199 | return m.Uint64Value 200 | } 201 | return 0 202 | } 203 | 204 | func (m *Data) GetUint64ProtoValue() *wrappers.UInt64Value { 205 | if m != nil { 206 | return m.Uint64ProtoValue 207 | } 208 | return nil 209 | } 210 | 211 | func (m *Data) GetTimestamp() *timestamp.Timestamp { 212 | if m != nil { 213 | return m.Timestamp 214 | } 215 | return nil 216 | } 217 | 218 | func init() { 219 | proto.RegisterType((*Data)(nil), "main.Data") 220 | } 221 | 222 | func init() { proto.RegisterFile("data.proto", fileDescriptor_871986018790d2fd) } 223 | 224 | var fileDescriptor_871986018790d2fd = []byte{ 225 | // 485 bytes of a gzipped FileDescriptorProto 226 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x94, 0xcf, 0x6f, 0xd3, 0x30, 227 | 0x14, 0xc7, 0xe5, 0xb6, 0x1b, 0xad, 0xbb, 0x1f, 0xc5, 0x0c, 0xa9, 0x94, 0x69, 0x58, 0x15, 0x07, 228 | 0x1f, 0x58, 0x2a, 0x6d, 0xd3, 0x84, 0xe0, 0x56, 0x0d, 0xc4, 0x4e, 0xa0, 0xc7, 0x8f, 0x2b, 0x72, 229 | 0x16, 0x2f, 0x32, 0x4a, 0xe2, 0x28, 0x71, 0x84, 0x7a, 0xe7, 0xaf, 0xe0, 0xc0, 0x3f, 0xc0, 0x3f, 230 | 0x89, 0x6c, 0x27, 0xad, 0x49, 0x94, 0x9d, 0xa2, 0xf7, 0xcd, 0xfb, 0xbc, 0x8f, 0xde, 0x8b, 0x5a, 231 | 0x8c, 0x23, 0xae, 0x79, 0x90, 0x17, 0x4a, 0x2b, 0x32, 0x4a, 0xb9, 0xcc, 0x16, 0x2f, 0x62, 0xa5, 232 | 0xe2, 0x44, 0xac, 0x6c, 0x16, 0x56, 0xf7, 0x2b, 0x2d, 0x53, 0x51, 0x6a, 0x9e, 0xe6, 0xae, 0x6d, 233 | 0x71, 0xd6, 0x6e, 0xf8, 0x59, 0xf0, 0x3c, 0x17, 0x45, 0x59, 0xbf, 0x7f, 0x69, 0x1f, 0x77, 0xe7, 234 | 0xb1, 0xc8, 0xce, 0x63, 0xa5, 0x79, 0xbc, 0xd2, 0x3c, 0x8e, 0x45, 0x51, 0x3f, 0xea, 0xae, 0xa7, 235 | 0x79, 0xaa, 0xb2, 0x58, 0xad, 0x54, 0xf8, 0x43, 0xdc, 0x69, 0x19, 0xb9, 0x78, 0xf9, 0x77, 0x8c, 236 | 0x47, 0x37, 0x5c, 0x73, 0xf2, 0x16, 0x0f, 0x64, 0x34, 0x47, 0x14, 0xb1, 0xe9, 0xc5, 0x2c, 0x70, 237 | 0xcd, 0xc1, 0x47, 0xdb, 0x7c, 0x1b, 0xad, 0x9f, 0xfd, 0xfe, 0xf5, 0x67, 0x78, 0x12, 0x96, 0x2a, 238 | 0x7b, 0xb3, 0xfc, 0x2e, 0xa3, 0x57, 0x2a, 0x95, 0x5a, 0xa4, 0xb9, 0xde, 0x2c, 0x61, 0x20, 0x23, 239 | 0x72, 0x8a, 0x27, 0xa1, 0x52, 0xc9, 0x37, 0x9e, 0x54, 0x62, 0x3e, 0xa0, 0x88, 0x8d, 0x61, 0x17, 240 | 0x90, 0x35, 0x3e, 0x32, 0xc5, 0x27, 0x23, 0x74, 0x2d, 0x43, 0xab, 0x59, 0x04, 0x6e, 0xb3, 0xa0, 241 | 0xd9, 0x2c, 0x58, 0x37, 0x0c, 0xb4, 0x08, 0x72, 0x86, 0x71, 0xb8, 0xd1, 0xa2, 0x74, 0xfc, 0x88, 242 | 0x22, 0x76, 0x00, 0x5e, 0x42, 0xde, 0xe1, 0x63, 0x5b, 0x79, 0x92, 0x3d, 0x2b, 0x79, 0xde, 0x95, 243 | 0x6c, 0x29, 0x68, 0x33, 0x84, 0xe2, 0x69, 0xa4, 0xaa, 0x30, 0x11, 0x6e, 0xc4, 0x3e, 0x45, 0x0c, 244 | 0x81, 0x1f, 0x91, 0x0f, 0x78, 0xe6, 0x4a, 0xcf, 0xf4, 0xc8, 0x9a, 0x4e, 0x3b, 0xa6, 0x9b, 0x1d, 245 | 0x07, 0x1d, 0xca, 0xac, 0x74, 0x9f, 0x28, 0xae, 0xdd, 0x8c, 0x31, 0x45, 0x6c, 0x00, 0x5e, 0x62, 246 | 0x56, 0xb2, 0x95, 0x27, 0x9a, 0xf4, 0xac, 0xf4, 0x7e, 0x4b, 0x41, 0x9b, 0x31, 0x1a, 0x99, 0xe9, 247 | 0xcb, 0x0b, 0x37, 0x01, 0x53, 0xc4, 0xf6, 0xc0, 0x4b, 0x8c, 0xc6, 0x56, 0x9e, 0x66, 0xda, 0xa3, 248 | 0xb9, 0xdd, 0x52, 0xd0, 0x66, 0x6a, 0xcd, 0xf5, 0x95, 0x9b, 0x70, 0x40, 0x11, 0x1b, 0x82, 0x97, 249 | 0xd4, 0x9a, 0xeb, 0x2b, 0x4f, 0x73, 0xd8, 0xaf, 0xa9, 0x29, 0x68, 0x33, 0xe6, 0x03, 0x95, 0xba, 250 | 0x90, 0x59, 0xec, 0x46, 0x1c, 0x51, 0xc4, 0x26, 0xe0, 0x47, 0xe6, 0x03, 0xb9, 0xd2, 0x33, 0x1d, 251 | 0xf7, 0x7c, 0xa0, 0xcf, 0x3b, 0x0e, 0x3a, 0x94, 0x71, 0x55, 0xde, 0xe9, 0x66, 0x14, 0xb1, 0x43, 252 | 0xf0, 0x23, 0xe3, 0xaa, 0xda, 0xc7, 0x7b, 0xdc, 0xe3, 0xfa, 0xea, 0x5d, 0xaf, 0x43, 0x35, 0xae, 253 | 0xe6, 0x7e, 0x84, 0x22, 0x36, 0x02, 0x3f, 0x6a, 0x5c, 0xff, 0x5d, 0xf0, 0xc9, 0x03, 0xae, 0xe6, 254 | 0x84, 0x1d, 0x8a, 0xbc, 0xc6, 0x93, 0xed, 0x7f, 0xcc, 0xfc, 0xa4, 0xe7, 0xa7, 0xf8, 0xa5, 0xe9, 255 | 0x80, 0x5d, 0x73, 0xb8, 0x6f, 0x5f, 0x5f, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xf3, 0x38, 0xfe, 256 | 0x15, 0xc6, 0x04, 0x00, 0x00, 257 | } 258 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /proto/third_party/google/protobuf/descriptor.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // The messages in this file describe the definitions found in .proto files. 36 | // A valid .proto file can be translated directly to a FileDescriptorProto 37 | // without any other information (e.g. without reading its imports). 38 | 39 | 40 | syntax = "proto2"; 41 | 42 | package google.protobuf; 43 | option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor"; 44 | option java_package = "com.google.protobuf"; 45 | option java_outer_classname = "DescriptorProtos"; 46 | option csharp_namespace = "Google.Protobuf.Reflection"; 47 | option objc_class_prefix = "GPB"; 48 | option cc_enable_arenas = true; 49 | 50 | // descriptor.proto must be optimized for speed because reflection-based 51 | // algorithms don't work during bootstrapping. 52 | option optimize_for = SPEED; 53 | 54 | // The protocol compiler can output a FileDescriptorSet containing the .proto 55 | // files it parses. 56 | message FileDescriptorSet { 57 | repeated FileDescriptorProto file = 1; 58 | } 59 | 60 | // Describes a complete .proto file. 61 | message FileDescriptorProto { 62 | optional string name = 1; // file name, relative to root of source tree 63 | optional string package = 2; // e.g. "foo", "foo.bar", etc. 64 | 65 | // Names of files imported by this file. 66 | repeated string dependency = 3; 67 | // Indexes of the public imported files in the dependency list above. 68 | repeated int32 public_dependency = 10; 69 | // Indexes of the weak imported files in the dependency list. 70 | // For Google-internal migration only. Do not use. 71 | repeated int32 weak_dependency = 11; 72 | 73 | // All top-level definitions in this file. 74 | repeated DescriptorProto message_type = 4; 75 | repeated EnumDescriptorProto enum_type = 5; 76 | repeated ServiceDescriptorProto service = 6; 77 | repeated FieldDescriptorProto extension = 7; 78 | 79 | optional FileOptions options = 8; 80 | 81 | // This field contains optional information about the original source code. 82 | // You may safely remove this entire field without harming runtime 83 | // functionality of the descriptors -- the information is needed only by 84 | // development tools. 85 | optional SourceCodeInfo source_code_info = 9; 86 | 87 | // The syntax of the proto file. 88 | // The supported values are "proto2" and "proto3". 89 | optional string syntax = 12; 90 | } 91 | 92 | // Describes a message type. 93 | message DescriptorProto { 94 | optional string name = 1; 95 | 96 | repeated FieldDescriptorProto field = 2; 97 | repeated FieldDescriptorProto extension = 6; 98 | 99 | repeated DescriptorProto nested_type = 3; 100 | repeated EnumDescriptorProto enum_type = 4; 101 | 102 | message ExtensionRange { 103 | optional int32 start = 1; 104 | optional int32 end = 2; 105 | 106 | optional ExtensionRangeOptions options = 3; 107 | } 108 | repeated ExtensionRange extension_range = 5; 109 | 110 | repeated OneofDescriptorProto oneof_decl = 8; 111 | 112 | optional MessageOptions options = 7; 113 | 114 | // Range of reserved tag numbers. Reserved tag numbers may not be used by 115 | // fields or extension ranges in the same message. Reserved ranges may 116 | // not overlap. 117 | message ReservedRange { 118 | optional int32 start = 1; // Inclusive. 119 | optional int32 end = 2; // Exclusive. 120 | } 121 | repeated ReservedRange reserved_range = 9; 122 | // Reserved field names, which may not be used by fields in the same message. 123 | // A given name may only be reserved once. 124 | repeated string reserved_name = 10; 125 | } 126 | 127 | message ExtensionRangeOptions { 128 | // The parser stores options it doesn't recognize here. See above. 129 | repeated UninterpretedOption uninterpreted_option = 999; 130 | 131 | // Clients can define custom options in extensions of this message. See above. 132 | extensions 1000 to max; 133 | } 134 | 135 | // Describes a field within a message. 136 | message FieldDescriptorProto { 137 | enum Type { 138 | // 0 is reserved for errors. 139 | // Order is weird for historical reasons. 140 | TYPE_DOUBLE = 1; 141 | TYPE_FLOAT = 2; 142 | // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if 143 | // negative values are likely. 144 | TYPE_INT64 = 3; 145 | TYPE_UINT64 = 4; 146 | // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if 147 | // negative values are likely. 148 | TYPE_INT32 = 5; 149 | TYPE_FIXED64 = 6; 150 | TYPE_FIXED32 = 7; 151 | TYPE_BOOL = 8; 152 | TYPE_STRING = 9; 153 | // Tag-delimited aggregate. 154 | // Group type is deprecated and not supported in proto3. However, Proto3 155 | // implementations should still be able to parse the group wire format and 156 | // treat group fields as unknown fields. 157 | TYPE_GROUP = 10; 158 | TYPE_MESSAGE = 11; // Length-delimited aggregate. 159 | 160 | // New in version 2. 161 | TYPE_BYTES = 12; 162 | TYPE_UINT32 = 13; 163 | TYPE_ENUM = 14; 164 | TYPE_SFIXED32 = 15; 165 | TYPE_SFIXED64 = 16; 166 | TYPE_SINT32 = 17; // Uses ZigZag encoding. 167 | TYPE_SINT64 = 18; // Uses ZigZag encoding. 168 | }; 169 | 170 | enum Label { 171 | // 0 is reserved for errors 172 | LABEL_OPTIONAL = 1; 173 | LABEL_REQUIRED = 2; 174 | LABEL_REPEATED = 3; 175 | }; 176 | 177 | optional string name = 1; 178 | optional int32 number = 3; 179 | optional Label label = 4; 180 | 181 | // If type_name is set, this need not be set. If both this and type_name 182 | // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. 183 | optional Type type = 5; 184 | 185 | // For message and enum types, this is the name of the type. If the name 186 | // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping 187 | // rules are used to find the type (i.e. first the nested types within this 188 | // message are searched, then within the parent, on up to the root 189 | // namespace). 190 | optional string type_name = 6; 191 | 192 | // For extensions, this is the name of the type being extended. It is 193 | // resolved in the same manner as type_name. 194 | optional string extendee = 2; 195 | 196 | // For numeric types, contains the original text representation of the value. 197 | // For booleans, "true" or "false". 198 | // For strings, contains the default text contents (not escaped in any way). 199 | // For bytes, contains the C escaped value. All bytes >= 128 are escaped. 200 | // TODO(kenton): Base-64 encode? 201 | optional string default_value = 7; 202 | 203 | // If set, gives the index of a oneof in the containing type's oneof_decl 204 | // list. This field is a member of that oneof. 205 | optional int32 oneof_index = 9; 206 | 207 | // JSON name of this field. The value is set by protocol compiler. If the 208 | // user has set a "json_name" option on this field, that option's value 209 | // will be used. Otherwise, it's deduced from the field's name by converting 210 | // it to camelCase. 211 | optional string json_name = 10; 212 | 213 | optional FieldOptions options = 8; 214 | } 215 | 216 | // Describes a oneof. 217 | message OneofDescriptorProto { 218 | optional string name = 1; 219 | optional OneofOptions options = 2; 220 | } 221 | 222 | // Describes an enum type. 223 | message EnumDescriptorProto { 224 | optional string name = 1; 225 | 226 | repeated EnumValueDescriptorProto value = 2; 227 | 228 | optional EnumOptions options = 3; 229 | 230 | // Range of reserved numeric values. Reserved values may not be used by 231 | // entries in the same enum. Reserved ranges may not overlap. 232 | // 233 | // Note that this is distinct from DescriptorProto.ReservedRange in that it 234 | // is inclusive such that it can appropriately represent the entire int32 235 | // domain. 236 | message EnumReservedRange { 237 | optional int32 start = 1; // Inclusive. 238 | optional int32 end = 2; // Inclusive. 239 | } 240 | 241 | // Range of reserved numeric values. Reserved numeric values may not be used 242 | // by enum values in the same enum declaration. Reserved ranges may not 243 | // overlap. 244 | repeated EnumReservedRange reserved_range = 4; 245 | 246 | // Reserved enum value names, which may not be reused. A given name may only 247 | // be reserved once. 248 | repeated string reserved_name = 5; 249 | } 250 | 251 | // Describes a value within an enum. 252 | message EnumValueDescriptorProto { 253 | optional string name = 1; 254 | optional int32 number = 2; 255 | 256 | optional EnumValueOptions options = 3; 257 | } 258 | 259 | // Describes a service. 260 | message ServiceDescriptorProto { 261 | optional string name = 1; 262 | repeated MethodDescriptorProto method = 2; 263 | 264 | optional ServiceOptions options = 3; 265 | } 266 | 267 | // Describes a method of a service. 268 | message MethodDescriptorProto { 269 | optional string name = 1; 270 | 271 | // Input and output type names. These are resolved in the same way as 272 | // FieldDescriptorProto.type_name, but must refer to a message type. 273 | optional string input_type = 2; 274 | optional string output_type = 3; 275 | 276 | optional MethodOptions options = 4; 277 | 278 | // Identifies if client streams multiple client messages 279 | optional bool client_streaming = 5 [default=false]; 280 | // Identifies if server streams multiple server messages 281 | optional bool server_streaming = 6 [default=false]; 282 | } 283 | 284 | 285 | // =================================================================== 286 | // Options 287 | 288 | // Each of the definitions above may have "options" attached. These are 289 | // just annotations which may cause code to be generated slightly differently 290 | // or may contain hints for code that manipulates protocol messages. 291 | // 292 | // Clients may define custom options as extensions of the *Options messages. 293 | // These extensions may not yet be known at parsing time, so the parser cannot 294 | // store the values in them. Instead it stores them in a field in the *Options 295 | // message called uninterpreted_option. This field must have the same name 296 | // across all *Options messages. We then use this field to populate the 297 | // extensions when we build a descriptor, at which point all protos have been 298 | // parsed and so all extensions are known. 299 | // 300 | // Extension numbers for custom options may be chosen as follows: 301 | // * For options which will only be used within a single application or 302 | // organization, or for experimental options, use field numbers 50000 303 | // through 99999. It is up to you to ensure that you do not use the 304 | // same number for multiple options. 305 | // * For options which will be published and used publicly by multiple 306 | // independent entities, e-mail protobuf-global-extension-registry@google.com 307 | // to reserve extension numbers. Simply provide your project name (e.g. 308 | // Objective-C plugin) and your project website (if available) -- there's no 309 | // need to explain how you intend to use them. Usually you only need one 310 | // extension number. You can declare multiple options with only one extension 311 | // number by putting them in a sub-message. See the Custom Options section of 312 | // the docs for examples: 313 | // https://developers.google.com/protocol-buffers/docs/proto#options 314 | // If this turns out to be popular, a web service will be set up 315 | // to automatically assign option numbers. 316 | 317 | 318 | message FileOptions { 319 | 320 | // Sets the Java package where classes generated from this .proto will be 321 | // placed. By default, the proto package is used, but this is often 322 | // inappropriate because proto packages do not normally start with backwards 323 | // domain names. 324 | optional string java_package = 1; 325 | 326 | 327 | // If set, all the classes from the .proto file are wrapped in a single 328 | // outer class with the given name. This applies to both Proto1 329 | // (equivalent to the old "--one_java_file" option) and Proto2 (where 330 | // a .proto always translates to a single class, but you may want to 331 | // explicitly choose the class name). 332 | optional string java_outer_classname = 8; 333 | 334 | // If set true, then the Java code generator will generate a separate .java 335 | // file for each top-level message, enum, and service defined in the .proto 336 | // file. Thus, these types will *not* be nested inside the outer class 337 | // named by java_outer_classname. However, the outer class will still be 338 | // generated to contain the file's getDescriptor() method as well as any 339 | // top-level extensions defined in the file. 340 | optional bool java_multiple_files = 10 [default=false]; 341 | 342 | // This option does nothing. 343 | optional bool java_generate_equals_and_hash = 20 [deprecated=true]; 344 | 345 | // If set true, then the Java2 code generator will generate code that 346 | // throws an exception whenever an attempt is made to assign a non-UTF-8 347 | // byte sequence to a string field. 348 | // Message reflection will do the same. 349 | // However, an extension field still accepts non-UTF-8 byte sequences. 350 | // This option has no effect on when used with the lite runtime. 351 | optional bool java_string_check_utf8 = 27 [default=false]; 352 | 353 | 354 | // Generated classes can be optimized for speed or code size. 355 | enum OptimizeMode { 356 | SPEED = 1; // Generate complete code for parsing, serialization, 357 | // etc. 358 | CODE_SIZE = 2; // Use ReflectionOps to implement these methods. 359 | LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. 360 | } 361 | optional OptimizeMode optimize_for = 9 [default=SPEED]; 362 | 363 | // Sets the Go package where structs generated from this .proto will be 364 | // placed. If omitted, the Go package will be derived from the following: 365 | // - The basename of the package import path, if provided. 366 | // - Otherwise, the package statement in the .proto file, if present. 367 | // - Otherwise, the basename of the .proto file, without extension. 368 | optional string go_package = 11; 369 | 370 | 371 | 372 | // Should generic services be generated in each language? "Generic" services 373 | // are not specific to any particular RPC system. They are generated by the 374 | // main code generators in each language (without additional plugins). 375 | // Generic services were the only kind of service generation supported by 376 | // early versions of google.protobuf. 377 | // 378 | // Generic services are now considered deprecated in favor of using plugins 379 | // that generate code specific to your particular RPC system. Therefore, 380 | // these default to false. Old code which depends on generic services should 381 | // explicitly set them to true. 382 | optional bool cc_generic_services = 16 [default=false]; 383 | optional bool java_generic_services = 17 [default=false]; 384 | optional bool py_generic_services = 18 [default=false]; 385 | optional bool php_generic_services = 42 [default=false]; 386 | 387 | // Is this file deprecated? 388 | // Depending on the target platform, this can emit Deprecated annotations 389 | // for everything in the file, or it will be completely ignored; in the very 390 | // least, this is a formalization for deprecating files. 391 | optional bool deprecated = 23 [default=false]; 392 | 393 | // Enables the use of arenas for the proto messages in this file. This applies 394 | // only to generated classes for C++. 395 | optional bool cc_enable_arenas = 31 [default=false]; 396 | 397 | 398 | // Sets the objective c class prefix which is prepended to all objective c 399 | // generated classes from this .proto. There is no default. 400 | optional string objc_class_prefix = 36; 401 | 402 | // Namespace for generated classes; defaults to the package. 403 | optional string csharp_namespace = 37; 404 | 405 | // By default Swift generators will take the proto package and CamelCase it 406 | // replacing '.' with underscore and use that to prefix the types/symbols 407 | // defined. When this options is provided, they will use this value instead 408 | // to prefix the types/symbols defined. 409 | optional string swift_prefix = 39; 410 | 411 | // Sets the php class prefix which is prepended to all php generated classes 412 | // from this .proto. Default is empty. 413 | optional string php_class_prefix = 40; 414 | 415 | // Use this option to change the namespace of php generated classes. Default 416 | // is empty. When this option is empty, the package name will be used for 417 | // determining the namespace. 418 | optional string php_namespace = 41; 419 | 420 | 421 | // Use this option to change the namespace of php generated metadata classes. 422 | // Default is empty. When this option is empty, the proto file name will be used 423 | // for determining the namespace. 424 | optional string php_metadata_namespace = 44; 425 | 426 | // Use this option to change the package of ruby generated classes. Default 427 | // is empty. When this option is not set, the package name will be used for 428 | // determining the ruby package. 429 | optional string ruby_package = 45; 430 | 431 | // The parser stores options it doesn't recognize here. 432 | // See the documentation for the "Options" section above. 433 | repeated UninterpretedOption uninterpreted_option = 999; 434 | 435 | // Clients can define custom options in extensions of this message. 436 | // See the documentation for the "Options" section above. 437 | extensions 1000 to max; 438 | 439 | reserved 38; 440 | } 441 | 442 | message MessageOptions { 443 | // Set true to use the old proto1 MessageSet wire format for extensions. 444 | // This is provided for backwards-compatibility with the MessageSet wire 445 | // format. You should not use this for any other reason: It's less 446 | // efficient, has fewer features, and is more complicated. 447 | // 448 | // The message must be defined exactly as follows: 449 | // message Foo { 450 | // option message_set_wire_format = true; 451 | // extensions 4 to max; 452 | // } 453 | // Note that the message cannot have any defined fields; MessageSets only 454 | // have extensions. 455 | // 456 | // All extensions of your type must be singular messages; e.g. they cannot 457 | // be int32s, enums, or repeated messages. 458 | // 459 | // Because this is an option, the above two restrictions are not enforced by 460 | // the protocol compiler. 461 | optional bool message_set_wire_format = 1 [default=false]; 462 | 463 | // Disables the generation of the standard "descriptor()" accessor, which can 464 | // conflict with a field of the same name. This is meant to make migration 465 | // from proto1 easier; new code should avoid fields named "descriptor". 466 | optional bool no_standard_descriptor_accessor = 2 [default=false]; 467 | 468 | // Is this message deprecated? 469 | // Depending on the target platform, this can emit Deprecated annotations 470 | // for the message, or it will be completely ignored; in the very least, 471 | // this is a formalization for deprecating messages. 472 | optional bool deprecated = 3 [default=false]; 473 | 474 | // Whether the message is an automatically generated map entry type for the 475 | // maps field. 476 | // 477 | // For maps fields: 478 | // map map_field = 1; 479 | // The parsed descriptor looks like: 480 | // message MapFieldEntry { 481 | // option map_entry = true; 482 | // optional KeyType key = 1; 483 | // optional ValueType value = 2; 484 | // } 485 | // repeated MapFieldEntry map_field = 1; 486 | // 487 | // Implementations may choose not to generate the map_entry=true message, but 488 | // use a native map in the target language to hold the keys and values. 489 | // The reflection APIs in such implementions still need to work as 490 | // if the field is a repeated message field. 491 | // 492 | // NOTE: Do not set the option in .proto files. Always use the maps syntax 493 | // instead. The option should only be implicitly set by the proto compiler 494 | // parser. 495 | optional bool map_entry = 7; 496 | 497 | reserved 8; // javalite_serializable 498 | reserved 9; // javanano_as_lite 499 | 500 | // The parser stores options it doesn't recognize here. See above. 501 | repeated UninterpretedOption uninterpreted_option = 999; 502 | 503 | // Clients can define custom options in extensions of this message. See above. 504 | extensions 1000 to max; 505 | } 506 | 507 | message FieldOptions { 508 | // The ctype option instructs the C++ code generator to use a different 509 | // representation of the field than it normally would. See the specific 510 | // options below. This option is not yet implemented in the open source 511 | // release -- sorry, we'll try to include it in a future version! 512 | optional CType ctype = 1 [default = STRING]; 513 | enum CType { 514 | // Default mode. 515 | STRING = 0; 516 | 517 | CORD = 1; 518 | 519 | STRING_PIECE = 2; 520 | } 521 | // The packed option can be enabled for repeated primitive fields to enable 522 | // a more efficient representation on the wire. Rather than repeatedly 523 | // writing the tag and type for each element, the entire array is encoded as 524 | // a single length-delimited blob. In proto3, only explicit setting it to 525 | // false will avoid using packed encoding. 526 | optional bool packed = 2; 527 | 528 | // The jstype option determines the JavaScript type used for values of the 529 | // field. The option is permitted only for 64 bit integral and fixed types 530 | // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING 531 | // is represented as JavaScript string, which avoids loss of precision that 532 | // can happen when a large value is converted to a floating point JavaScript. 533 | // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to 534 | // use the JavaScript "number" type. The behavior of the default option 535 | // JS_NORMAL is implementation dependent. 536 | // 537 | // This option is an enum to permit additional types to be added, e.g. 538 | // goog.math.Integer. 539 | optional JSType jstype = 6 [default = JS_NORMAL]; 540 | enum JSType { 541 | // Use the default type. 542 | JS_NORMAL = 0; 543 | 544 | // Use JavaScript strings. 545 | JS_STRING = 1; 546 | 547 | // Use JavaScript numbers. 548 | JS_NUMBER = 2; 549 | } 550 | 551 | // Should this field be parsed lazily? Lazy applies only to message-type 552 | // fields. It means that when the outer message is initially parsed, the 553 | // inner message's contents will not be parsed but instead stored in encoded 554 | // form. The inner message will actually be parsed when it is first accessed. 555 | // 556 | // This is only a hint. Implementations are free to choose whether to use 557 | // eager or lazy parsing regardless of the value of this option. However, 558 | // setting this option true suggests that the protocol author believes that 559 | // using lazy parsing on this field is worth the additional bookkeeping 560 | // overhead typically needed to implement it. 561 | // 562 | // This option does not affect the public interface of any generated code; 563 | // all method signatures remain the same. Furthermore, thread-safety of the 564 | // interface is not affected by this option; const methods remain safe to 565 | // call from multiple threads concurrently, while non-const methods continue 566 | // to require exclusive access. 567 | // 568 | // 569 | // Note that implementations may choose not to check required fields within 570 | // a lazy sub-message. That is, calling IsInitialized() on the outer message 571 | // may return true even if the inner message has missing required fields. 572 | // This is necessary because otherwise the inner message would have to be 573 | // parsed in order to perform the check, defeating the purpose of lazy 574 | // parsing. An implementation which chooses not to check required fields 575 | // must be consistent about it. That is, for any particular sub-message, the 576 | // implementation must either *always* check its required fields, or *never* 577 | // check its required fields, regardless of whether or not the message has 578 | // been parsed. 579 | optional bool lazy = 5 [default=false]; 580 | 581 | // Is this field deprecated? 582 | // Depending on the target platform, this can emit Deprecated annotations 583 | // for accessors, or it will be completely ignored; in the very least, this 584 | // is a formalization for deprecating fields. 585 | optional bool deprecated = 3 [default=false]; 586 | 587 | // For Google-internal migration only. Do not use. 588 | optional bool weak = 10 [default=false]; 589 | 590 | 591 | // The parser stores options it doesn't recognize here. See above. 592 | repeated UninterpretedOption uninterpreted_option = 999; 593 | 594 | // Clients can define custom options in extensions of this message. See above. 595 | extensions 1000 to max; 596 | 597 | reserved 4; // removed jtype 598 | } 599 | 600 | message OneofOptions { 601 | // The parser stores options it doesn't recognize here. See above. 602 | repeated UninterpretedOption uninterpreted_option = 999; 603 | 604 | // Clients can define custom options in extensions of this message. See above. 605 | extensions 1000 to max; 606 | } 607 | 608 | message EnumOptions { 609 | 610 | // Set this option to true to allow mapping different tag names to the same 611 | // value. 612 | optional bool allow_alias = 2; 613 | 614 | // Is this enum deprecated? 615 | // Depending on the target platform, this can emit Deprecated annotations 616 | // for the enum, or it will be completely ignored; in the very least, this 617 | // is a formalization for deprecating enums. 618 | optional bool deprecated = 3 [default=false]; 619 | 620 | reserved 5; // javanano_as_lite 621 | 622 | // The parser stores options it doesn't recognize here. See above. 623 | repeated UninterpretedOption uninterpreted_option = 999; 624 | 625 | // Clients can define custom options in extensions of this message. See above. 626 | extensions 1000 to max; 627 | } 628 | 629 | message EnumValueOptions { 630 | // Is this enum value deprecated? 631 | // Depending on the target platform, this can emit Deprecated annotations 632 | // for the enum value, or it will be completely ignored; in the very least, 633 | // this is a formalization for deprecating enum values. 634 | optional bool deprecated = 1 [default=false]; 635 | 636 | // The parser stores options it doesn't recognize here. See above. 637 | repeated UninterpretedOption uninterpreted_option = 999; 638 | 639 | // Clients can define custom options in extensions of this message. See above. 640 | extensions 1000 to max; 641 | } 642 | 643 | message ServiceOptions { 644 | 645 | // Note: Field numbers 1 through 32 are reserved for Google's internal RPC 646 | // framework. We apologize for hoarding these numbers to ourselves, but 647 | // we were already using them long before we decided to release Protocol 648 | // Buffers. 649 | 650 | // Is this service deprecated? 651 | // Depending on the target platform, this can emit Deprecated annotations 652 | // for the service, or it will be completely ignored; in the very least, 653 | // this is a formalization for deprecating services. 654 | optional bool deprecated = 33 [default=false]; 655 | 656 | // The parser stores options it doesn't recognize here. See above. 657 | repeated UninterpretedOption uninterpreted_option = 999; 658 | 659 | // Clients can define custom options in extensions of this message. See above. 660 | extensions 1000 to max; 661 | } 662 | 663 | message MethodOptions { 664 | 665 | // Note: Field numbers 1 through 32 are reserved for Google's internal RPC 666 | // framework. We apologize for hoarding these numbers to ourselves, but 667 | // we were already using them long before we decided to release Protocol 668 | // Buffers. 669 | 670 | // Is this method deprecated? 671 | // Depending on the target platform, this can emit Deprecated annotations 672 | // for the method, or it will be completely ignored; in the very least, 673 | // this is a formalization for deprecating methods. 674 | optional bool deprecated = 33 [default=false]; 675 | 676 | // Is this method side-effect-free (or safe in HTTP parlance), or idempotent, 677 | // or neither? HTTP based RPC implementation may choose GET verb for safe 678 | // methods, and PUT verb for idempotent methods instead of the default POST. 679 | enum IdempotencyLevel { 680 | IDEMPOTENCY_UNKNOWN = 0; 681 | NO_SIDE_EFFECTS = 1; // implies idempotent 682 | IDEMPOTENT = 2; // idempotent, but may have side effects 683 | } 684 | optional IdempotencyLevel idempotency_level = 685 | 34 [default=IDEMPOTENCY_UNKNOWN]; 686 | 687 | // The parser stores options it doesn't recognize here. See above. 688 | repeated UninterpretedOption uninterpreted_option = 999; 689 | 690 | // Clients can define custom options in extensions of this message. See above. 691 | extensions 1000 to max; 692 | } 693 | 694 | 695 | // A message representing a option the parser does not recognize. This only 696 | // appears in options protos created by the compiler::Parser class. 697 | // DescriptorPool resolves these when building Descriptor objects. Therefore, 698 | // options protos in descriptor objects (e.g. returned by Descriptor::options(), 699 | // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions 700 | // in them. 701 | message UninterpretedOption { 702 | // The name of the uninterpreted option. Each string represents a segment in 703 | // a dot-separated name. is_extension is true iff a segment represents an 704 | // extension (denoted with parentheses in options specs in .proto files). 705 | // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents 706 | // "foo.(bar.baz).qux". 707 | message NamePart { 708 | required string name_part = 1; 709 | required bool is_extension = 2; 710 | } 711 | repeated NamePart name = 2; 712 | 713 | // The value of the uninterpreted option, in whatever type the tokenizer 714 | // identified it as during parsing. Exactly one of these should be set. 715 | optional string identifier_value = 3; 716 | optional uint64 positive_int_value = 4; 717 | optional int64 negative_int_value = 5; 718 | optional double double_value = 6; 719 | optional bytes string_value = 7; 720 | optional string aggregate_value = 8; 721 | } 722 | 723 | // =================================================================== 724 | // Optional source code info 725 | 726 | // Encapsulates information about the original source file from which a 727 | // FileDescriptorProto was generated. 728 | message SourceCodeInfo { 729 | // A Location identifies a piece of source code in a .proto file which 730 | // corresponds to a particular definition. This information is intended 731 | // to be useful to IDEs, code indexers, documentation generators, and similar 732 | // tools. 733 | // 734 | // For example, say we have a file like: 735 | // message Foo { 736 | // optional string foo = 1; 737 | // } 738 | // Let's look at just the field definition: 739 | // optional string foo = 1; 740 | // ^ ^^ ^^ ^ ^^^ 741 | // a bc de f ghi 742 | // We have the following locations: 743 | // span path represents 744 | // [a,i) [ 4, 0, 2, 0 ] The whole field definition. 745 | // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). 746 | // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). 747 | // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). 748 | // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). 749 | // 750 | // Notes: 751 | // - A location may refer to a repeated field itself (i.e. not to any 752 | // particular index within it). This is used whenever a set of elements are 753 | // logically enclosed in a single code segment. For example, an entire 754 | // extend block (possibly containing multiple extension definitions) will 755 | // have an outer location whose path refers to the "extensions" repeated 756 | // field without an index. 757 | // - Multiple locations may have the same path. This happens when a single 758 | // logical declaration is spread out across multiple places. The most 759 | // obvious example is the "extend" block again -- there may be multiple 760 | // extend blocks in the same scope, each of which will have the same path. 761 | // - A location's span is not always a subset of its parent's span. For 762 | // example, the "extendee" of an extension declaration appears at the 763 | // beginning of the "extend" block and is shared by all extensions within 764 | // the block. 765 | // - Just because a location's span is a subset of some other location's span 766 | // does not mean that it is a descendent. For example, a "group" defines 767 | // both a type and a field in a single declaration. Thus, the locations 768 | // corresponding to the type and field and their components will overlap. 769 | // - Code which tries to interpret locations should probably be designed to 770 | // ignore those that it doesn't understand, as more types of locations could 771 | // be recorded in the future. 772 | repeated Location location = 1; 773 | message Location { 774 | // Identifies which part of the FileDescriptorProto was defined at this 775 | // location. 776 | // 777 | // Each element is a field number or an index. They form a path from 778 | // the root FileDescriptorProto to the place where the definition. For 779 | // example, this path: 780 | // [ 4, 3, 2, 7, 1 ] 781 | // refers to: 782 | // file.message_type(3) // 4, 3 783 | // .field(7) // 2, 7 784 | // .name() // 1 785 | // This is because FileDescriptorProto.message_type has field number 4: 786 | // repeated DescriptorProto message_type = 4; 787 | // and DescriptorProto.field has field number 2: 788 | // repeated FieldDescriptorProto field = 2; 789 | // and FieldDescriptorProto.name has field number 1: 790 | // optional string name = 1; 791 | // 792 | // Thus, the above path gives the location of a field name. If we removed 793 | // the last element: 794 | // [ 4, 3, 2, 7 ] 795 | // this path refers to the whole field declaration (from the beginning 796 | // of the label to the terminating semicolon). 797 | repeated int32 path = 1 [packed=true]; 798 | 799 | // Always has exactly three or four elements: start line, start column, 800 | // end line (optional, otherwise assumed same as start line), end column. 801 | // These are packed into a single field for efficiency. Note that line 802 | // and column numbers are zero-based -- typically you will want to add 803 | // 1 to each before displaying to a user. 804 | repeated int32 span = 2 [packed=true]; 805 | 806 | // If this SourceCodeInfo represents a complete declaration, these are any 807 | // comments appearing before and after the declaration which appear to be 808 | // attached to the declaration. 809 | // 810 | // A series of line comments appearing on consecutive lines, with no other 811 | // tokens appearing on those lines, will be treated as a single comment. 812 | // 813 | // leading_detached_comments will keep paragraphs of comments that appear 814 | // before (but not connected to) the current element. Each paragraph, 815 | // separated by empty lines, will be one comment element in the repeated 816 | // field. 817 | // 818 | // Only the comment content is provided; comment markers (e.g. //) are 819 | // stripped out. For block comments, leading whitespace and an asterisk 820 | // will be stripped from the beginning of each line other than the first. 821 | // Newlines are included in the output. 822 | // 823 | // Examples: 824 | // 825 | // optional int32 foo = 1; // Comment attached to foo. 826 | // // Comment attached to bar. 827 | // optional int32 bar = 2; 828 | // 829 | // optional string baz = 3; 830 | // // Comment attached to baz. 831 | // // Another line attached to baz. 832 | // 833 | // // Comment attached to qux. 834 | // // 835 | // // Another line attached to qux. 836 | // optional double qux = 4; 837 | // 838 | // // Detached comment for corge. This is not leading or trailing comments 839 | // // to qux or corge because there are blank lines separating it from 840 | // // both. 841 | // 842 | // // Detached comment for corge paragraph 2. 843 | // 844 | // optional string corge = 5; 845 | // /* Block comment attached 846 | // * to corge. Leading asterisks 847 | // * will be removed. */ 848 | // /* Block comment attached to 849 | // * grault. */ 850 | // optional int32 grault = 6; 851 | // 852 | // // ignored detached comments. 853 | optional string leading_comments = 3; 854 | optional string trailing_comments = 4; 855 | repeated string leading_detached_comments = 6; 856 | } 857 | } 858 | 859 | // Describes the relationship between generated code and its original source 860 | // file. A GeneratedCodeInfo message is associated with only one generated 861 | // source file, but may contain references to different source .proto files. 862 | message GeneratedCodeInfo { 863 | // An Annotation connects some span of text in generated code to an element 864 | // of its generating .proto file. 865 | repeated Annotation annotation = 1; 866 | message Annotation { 867 | // Identifies the element in the original source .proto file. This field 868 | // is formatted the same as SourceCodeInfo.Location.path. 869 | repeated int32 path = 1 [packed=true]; 870 | 871 | // Identifies the filesystem path to the original source .proto. 872 | optional string source_file = 2; 873 | 874 | // Identifies the starting offset in bytes in the generated code 875 | // that relates to the identified object. 876 | optional int32 begin = 3; 877 | 878 | // Identifies the ending offset in bytes in the generated code that 879 | // relates to the identified offset. The end offset should be one past 880 | // the last relevant byte (so the length of the text = end - begin). 881 | optional int32 end = 4; 882 | } 883 | } 884 | --------------------------------------------------------------------------------