Update dependencies

This commit is contained in:
Alexander Neumann
2019-04-24 12:32:52 +02:00
parent c7762453cf
commit ca8c3b4fd5
286 changed files with 28160 additions and 15888 deletions

View File

@@ -186,7 +186,6 @@ func (p *Buffer) DecodeVarint() (x uint64, err error) {
if b&0x80 == 0 {
goto done
}
// x -= 0x80 << 63 // Always zero.
return 0, errOverflow

63
vendor/github.com/golang/protobuf/proto/deprecated.go generated vendored Normal file
View File

@@ -0,0 +1,63 @@
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2018 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package proto
import "errors"
// Deprecated: do not use.
type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
// Deprecated: do not use.
func GetStats() Stats { return Stats{} }
// Deprecated: do not use.
func MarshalMessageSet(interface{}) ([]byte, error) {
return nil, errors.New("proto: not implemented")
}
// Deprecated: do not use.
func UnmarshalMessageSet([]byte, interface{}) error {
return errors.New("proto: not implemented")
}
// Deprecated: do not use.
func MarshalMessageSetJSON(interface{}) ([]byte, error) {
return nil, errors.New("proto: not implemented")
}
// Deprecated: do not use.
func UnmarshalMessageSetJSON([]byte, interface{}) error {
return errors.New("proto: not implemented")
}
// Deprecated: do not use.
func RegisterMessageSetType(Message, int32, string) {}

View File

@@ -246,7 +246,8 @@ func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
return false
}
m1, m2 := e1.value, e2.value
m1 := extensionAsLegacyType(e1.value)
m2 := extensionAsLegacyType(e2.value)
if m1 == nil && m2 == nil {
// Both have only encoded form.

View File

@@ -185,9 +185,25 @@ type Extension struct {
// extension will have only enc set. When such an extension is
// accessed using GetExtension (or GetExtensions) desc and value
// will be set.
desc *ExtensionDesc
desc *ExtensionDesc
// value is a concrete value for the extension field. Let the type of
// desc.ExtensionType be the "API type" and the type of Extension.value
// be the "storage type". The API type and storage type are the same except:
// * For scalars (except []byte), the API type uses *T,
// while the storage type uses T.
// * For repeated fields, the API type uses []T, while the storage type
// uses *[]T.
//
// The reason for the divergence is so that the storage type more naturally
// matches what is expected of when retrieving the values through the
// protobuf reflection APIs.
//
// The value may only be populated if desc is also populated.
value interface{}
enc []byte
// enc is the raw bytes for the extension field.
enc []byte
}
// SetRawExtension is for testing only.
@@ -334,7 +350,7 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
// descriptors with the same field number.
return nil, errors.New("proto: descriptor conflict")
}
return e.value, nil
return extensionAsLegacyType(e.value), nil
}
if extension.ExtensionType == nil {
@@ -349,11 +365,11 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
// Remember the decoded version and drop the encoded version.
// That way it is safe to mutate what we return.
e.value = v
e.value = extensionAsStorageType(v)
e.desc = extension
e.enc = nil
emap[extension.Field] = e
return e.value, nil
return extensionAsLegacyType(e.value), nil
}
// defaultExtensionValue returns the default value for extension.
@@ -488,7 +504,7 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
}
typ := reflect.TypeOf(extension.ExtensionType)
if typ != reflect.TypeOf(value) {
return errors.New("proto: bad extension value type")
return fmt.Errorf("proto: bad extension value type. got: %T, want: %T", value, extension.ExtensionType)
}
// nil extension values need to be caught early, because the
// encoder can't distinguish an ErrNil due to a nil extension
@@ -500,7 +516,7 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
}
extmap := epb.extensionsWrite()
extmap[extension.Field] = Extension{desc: extension, value: value}
extmap[extension.Field] = Extension{desc: extension, value: extensionAsStorageType(value)}
return nil
}
@@ -541,3 +557,51 @@ func RegisterExtension(desc *ExtensionDesc) {
func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc {
return extensionMaps[reflect.TypeOf(pb).Elem()]
}
// extensionAsLegacyType converts an value in the storage type as the API type.
// See Extension.value.
func extensionAsLegacyType(v interface{}) interface{} {
switch rv := reflect.ValueOf(v); rv.Kind() {
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
// Represent primitive types as a pointer to the value.
rv2 := reflect.New(rv.Type())
rv2.Elem().Set(rv)
v = rv2.Interface()
case reflect.Ptr:
// Represent slice types as the value itself.
switch rv.Type().Elem().Kind() {
case reflect.Slice:
if rv.IsNil() {
v = reflect.Zero(rv.Type().Elem()).Interface()
} else {
v = rv.Elem().Interface()
}
}
}
return v
}
// extensionAsStorageType converts an value in the API type as the storage type.
// See Extension.value.
func extensionAsStorageType(v interface{}) interface{} {
switch rv := reflect.ValueOf(v); rv.Kind() {
case reflect.Ptr:
// Represent slice types as the value itself.
switch rv.Type().Elem().Kind() {
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
if rv.IsNil() {
v = reflect.Zero(rv.Type().Elem()).Interface()
} else {
v = rv.Elem().Interface()
}
}
case reflect.Slice:
// Represent slice types as a pointer to the value.
if rv.Type().Elem().Kind() != reflect.Uint8 {
rv2 := reflect.New(rv.Type())
rv2.Elem().Set(rv)
v = rv2.Interface()
}
}
return v
}

View File

@@ -341,26 +341,6 @@ type Message interface {
ProtoMessage()
}
// Stats records allocation details about the protocol buffer encoders
// and decoders. Useful for tuning the library itself.
type Stats struct {
Emalloc uint64 // mallocs in encode
Dmalloc uint64 // mallocs in decode
Encode uint64 // number of encodes
Decode uint64 // number of decodes
Chit uint64 // number of cache hits
Cmiss uint64 // number of cache misses
Size uint64 // number of sizes
}
// Set to true to enable stats collection.
const collectStats = false
var stats Stats
// GetStats returns a copy of the global Stats structure.
func GetStats() Stats { return stats }
// A Buffer is a buffer manager for marshaling and unmarshaling
// protocol buffers. It may be reused between invocations to
// reduce memory usage. It is not necessary to use a Buffer;
@@ -960,13 +940,19 @@ func isProto3Zero(v reflect.Value) bool {
return false
}
// ProtoPackageIsVersion2 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the proto package.
const ProtoPackageIsVersion2 = true
const (
// ProtoPackageIsVersion3 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the proto package.
ProtoPackageIsVersion3 = true
// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the proto package.
const ProtoPackageIsVersion1 = true
// ProtoPackageIsVersion2 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the proto package.
ProtoPackageIsVersion2 = true
// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the proto package.
ProtoPackageIsVersion1 = true
)
// InternalMessageInfo is a type used internally by generated .pb.go files.
// This type is not intended to be used by non-generated code.

View File

@@ -36,13 +36,7 @@ package proto
*/
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"reflect"
"sort"
"sync"
)
// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
@@ -145,46 +139,9 @@ func skipVarint(buf []byte) []byte {
return buf[i+1:]
}
// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
func MarshalMessageSet(exts interface{}) ([]byte, error) {
return marshalMessageSet(exts, false)
}
// marshaMessageSet implements above function, with the opt to turn on / off deterministic during Marshal.
func marshalMessageSet(exts interface{}, deterministic bool) ([]byte, error) {
switch exts := exts.(type) {
case *XXX_InternalExtensions:
var u marshalInfo
siz := u.sizeMessageSet(exts)
b := make([]byte, 0, siz)
return u.appendMessageSet(b, exts, deterministic)
case map[int32]Extension:
// This is an old-style extension map.
// Wrap it in a new-style XXX_InternalExtensions.
ie := XXX_InternalExtensions{
p: &struct {
mu sync.Mutex
extensionMap map[int32]Extension
}{
extensionMap: exts,
},
}
var u marshalInfo
siz := u.sizeMessageSet(&ie)
b := make([]byte, 0, siz)
return u.appendMessageSet(b, &ie, deterministic)
default:
return nil, errors.New("proto: not an extension map")
}
}
// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
// unmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
// It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
func UnmarshalMessageSet(buf []byte, exts interface{}) error {
func unmarshalMessageSet(buf []byte, exts interface{}) error {
var m map[int32]Extension
switch exts := exts.(type) {
case *XXX_InternalExtensions:
@@ -222,93 +179,3 @@ func UnmarshalMessageSet(buf []byte, exts interface{}) error {
}
return nil
}
// MarshalMessageSetJSON encodes the extension map represented by m in JSON format.
// It is called by generated MarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
func MarshalMessageSetJSON(exts interface{}) ([]byte, error) {
var m map[int32]Extension
switch exts := exts.(type) {
case *XXX_InternalExtensions:
var mu sync.Locker
m, mu = exts.extensionsRead()
if m != nil {
// Keep the extensions map locked until we're done marshaling to prevent
// races between marshaling and unmarshaling the lazily-{en,de}coded
// values.
mu.Lock()
defer mu.Unlock()
}
case map[int32]Extension:
m = exts
default:
return nil, errors.New("proto: not an extension map")
}
var b bytes.Buffer
b.WriteByte('{')
// Process the map in key order for deterministic output.
ids := make([]int32, 0, len(m))
for id := range m {
ids = append(ids, id)
}
sort.Sort(int32Slice(ids)) // int32Slice defined in text.go
for i, id := range ids {
ext := m[id]
msd, ok := messageSetMap[id]
if !ok {
// Unknown type; we can't render it, so skip it.
continue
}
if i > 0 && b.Len() > 1 {
b.WriteByte(',')
}
fmt.Fprintf(&b, `"[%s]":`, msd.name)
x := ext.value
if x == nil {
x = reflect.New(msd.t.Elem()).Interface()
if err := Unmarshal(ext.enc, x.(Message)); err != nil {
return nil, err
}
}
d, err := json.Marshal(x)
if err != nil {
return nil, err
}
b.Write(d)
}
b.WriteByte('}')
return b.Bytes(), nil
}
// UnmarshalMessageSetJSON decodes the extension map encoded in buf in JSON format.
// It is called by generated UnmarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
func UnmarshalMessageSetJSON(buf []byte, exts interface{}) error {
// Common-case fast path.
if len(buf) == 0 || bytes.Equal(buf, []byte("{}")) {
return nil
}
// This is fairly tricky, and it's not clear that it is needed.
return errors.New("TODO: UnmarshalMessageSetJSON not yet implemented")
}
// A global registry of types that can be used in a MessageSet.
var messageSetMap = make(map[int32]messageSetDesc)
type messageSetDesc struct {
t reflect.Type // pointer to struct
name string
}
// RegisterMessageSetType is called from the generated code.
func RegisterMessageSetType(m Message, fieldNum int32, name string) {
messageSetMap[fieldNum] = messageSetDesc{
t: reflect.TypeOf(m),
name: name,
}
}

View File

@@ -79,10 +79,13 @@ func toPointer(i *Message) pointer {
// toAddrPointer converts an interface to a pointer that points to
// the interface data.
func toAddrPointer(i *interface{}, isptr bool) pointer {
func toAddrPointer(i *interface{}, isptr, deref bool) pointer {
v := reflect.ValueOf(*i)
u := reflect.New(v.Type())
u.Elem().Set(v)
if deref {
u = u.Elem()
}
return pointer{v: u}
}

View File

@@ -85,16 +85,21 @@ func toPointer(i *Message) pointer {
// toAddrPointer converts an interface to a pointer that points to
// the interface data.
func toAddrPointer(i *interface{}, isptr bool) pointer {
func toAddrPointer(i *interface{}, isptr, deref bool) (p pointer) {
// Super-tricky - read or get the address of data word of interface value.
if isptr {
// The interface is of pointer type, thus it is a direct interface.
// The data word is the pointer data itself. We take its address.
return pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)}
p = pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)}
} else {
// The interface is not of pointer type. The data word is the pointer
// to the data.
p = pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
}
// The interface is not of pointer type. The data word is the pointer
// to the data.
return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
if deref {
p.p = *(*unsafe.Pointer)(p.p)
}
return p
}
// valToPointer converts v to a pointer. v must be of pointer type.

View File

@@ -334,9 +334,6 @@ func GetProperties(t reflect.Type) *StructProperties {
sprop, ok := propertiesMap[t]
propertiesMu.RUnlock()
if ok {
if collectStats {
stats.Chit++
}
return sprop
}
@@ -346,17 +343,20 @@ func GetProperties(t reflect.Type) *StructProperties {
return sprop
}
type (
oneofFuncsIface interface {
XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
}
oneofWrappersIface interface {
XXX_OneofWrappers() []interface{}
}
)
// getPropertiesLocked requires that propertiesMu is held.
func getPropertiesLocked(t reflect.Type) *StructProperties {
if prop, ok := propertiesMap[t]; ok {
if collectStats {
stats.Chit++
}
return prop
}
if collectStats {
stats.Cmiss++
}
prop := new(StructProperties)
// in case of recursive protos, fill this in now.
@@ -391,13 +391,14 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
// Re-order prop.order.
sort.Sort(prop)
type oneofMessage interface {
XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
var oots []interface{}
switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) {
case oneofFuncsIface:
_, _, _, oots = m.XXX_OneofFuncs()
case oneofWrappersIface:
oots = m.XXX_OneofWrappers()
}
if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
var oots []interface{}
_, _, _, oots = om.XXX_OneofFuncs()
if len(oots) > 0 {
// Interpret oneof metadata.
prop.OneofTypes = make(map[string]*OneofProperties)
for _, oot := range oots {

View File

@@ -87,6 +87,7 @@ type marshalElemInfo struct {
sizer sizer
marshaler marshaler
isptr bool // elem is pointer typed, thus interface of this type is a direct interface (extension only)
deref bool // dereference the pointer before operating on it; implies isptr
}
var (
@@ -320,8 +321,11 @@ func (u *marshalInfo) computeMarshalInfo() {
// get oneof implementers
var oneofImplementers []interface{}
if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) {
case oneofFuncsIface:
_, _, _, oneofImplementers = m.XXX_OneofFuncs()
case oneofWrappersIface:
oneofImplementers = m.XXX_OneofWrappers()
}
n := t.NumField()
@@ -407,13 +411,22 @@ func (u *marshalInfo) getExtElemInfo(desc *ExtensionDesc) *marshalElemInfo {
panic("tag is not an integer")
}
wt := wiretype(tags[0])
if t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct {
t = t.Elem()
}
sizer, marshaler := typeMarshaler(t, tags, false, false)
var deref bool
if t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 {
t = reflect.PtrTo(t)
deref = true
}
e = &marshalElemInfo{
wiretag: uint64(tag)<<3 | wt,
tagsize: SizeVarint(uint64(tag) << 3),
sizer: sizer,
marshaler: marshaler,
isptr: t.Kind() == reflect.Ptr,
deref: deref,
}
// update cache
@@ -448,7 +461,7 @@ func (fi *marshalFieldInfo) computeMarshalFieldInfo(f *reflect.StructField) {
func (fi *marshalFieldInfo) computeOneofFieldInfo(f *reflect.StructField, oneofImplementers []interface{}) {
fi.field = toField(f)
fi.wiretag = 1<<31 - 1 // Use a large tag number, make oneofs sorted at the end. This tag will not appear on the wire.
fi.wiretag = math.MaxInt32 // Use a large tag number, make oneofs sorted at the end. This tag will not appear on the wire.
fi.isPointer = true
fi.sizer, fi.marshaler = makeOneOfMarshaler(fi, f)
fi.oneofElems = make(map[reflect.Type]*marshalElemInfo)
@@ -476,10 +489,6 @@ func (fi *marshalFieldInfo) computeOneofFieldInfo(f *reflect.StructField, oneofI
}
}
type oneofMessage interface {
XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
}
// wiretype returns the wire encoding of the type.
func wiretype(encoding string) uint64 {
switch encoding {
@@ -2310,8 +2319,8 @@ func makeMapMarshaler(f *reflect.StructField) (sizer, marshaler) {
for _, k := range m.MapKeys() {
ki := k.Interface()
vi := m.MapIndex(k).Interface()
kaddr := toAddrPointer(&ki, false) // pointer to key
vaddr := toAddrPointer(&vi, valIsPtr) // pointer to value
kaddr := toAddrPointer(&ki, false, false) // pointer to key
vaddr := toAddrPointer(&vi, valIsPtr, false) // pointer to value
siz := keySizer(kaddr, 1) + valSizer(vaddr, 1) // tag of key = 1 (size=1), tag of val = 2 (size=1)
n += siz + SizeVarint(uint64(siz)) + tagsize
}
@@ -2329,8 +2338,8 @@ func makeMapMarshaler(f *reflect.StructField) (sizer, marshaler) {
for _, k := range keys {
ki := k.Interface()
vi := m.MapIndex(k).Interface()
kaddr := toAddrPointer(&ki, false) // pointer to key
vaddr := toAddrPointer(&vi, valIsPtr) // pointer to value
kaddr := toAddrPointer(&ki, false, false) // pointer to key
vaddr := toAddrPointer(&vi, valIsPtr, false) // pointer to value
b = appendVarint(b, tag)
siz := keySizer(kaddr, 1) + valCachedSizer(vaddr, 1) // tag of key = 1 (size=1), tag of val = 2 (size=1)
b = appendVarint(b, uint64(siz))
@@ -2399,7 +2408,7 @@ func (u *marshalInfo) sizeExtensions(ext *XXX_InternalExtensions) int {
// the last time this function was called.
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
n += ei.sizer(p, ei.tagsize)
}
mu.Unlock()
@@ -2434,7 +2443,7 @@ func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, de
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
if !nerr.Merge(err) {
return b, err
@@ -2465,7 +2474,7 @@ func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, de
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
if !nerr.Merge(err) {
return b, err
@@ -2510,7 +2519,7 @@ func (u *marshalInfo) sizeMessageSet(ext *XXX_InternalExtensions) int {
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
n += ei.sizer(p, 1) // message, tag = 3 (size=1)
}
mu.Unlock()
@@ -2553,7 +2562,7 @@ func (u *marshalInfo) appendMessageSet(b []byte, ext *XXX_InternalExtensions, de
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
b, err = ei.marshaler(b, p, 3<<3|WireBytes, deterministic)
if !nerr.Merge(err) {
return b, err
@@ -2591,7 +2600,7 @@ func (u *marshalInfo) appendMessageSet(b []byte, ext *XXX_InternalExtensions, de
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
b, err = ei.marshaler(b, p, 3<<3|WireBytes, deterministic)
b = append(b, 1<<3|WireEndGroup)
if !nerr.Merge(err) {
@@ -2621,7 +2630,7 @@ func (u *marshalInfo) sizeV1Extensions(m map[int32]Extension) int {
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
n += ei.sizer(p, ei.tagsize)
}
return n
@@ -2656,7 +2665,7 @@ func (u *marshalInfo) appendV1Extensions(b []byte, m map[int32]Extension, determ
ei := u.getExtElemInfo(e.desc)
v := e.value
p := toAddrPointer(&v, ei.isptr)
p := toAddrPointer(&v, ei.isptr, ei.deref)
b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
if !nerr.Merge(err) {
return b, err

View File

@@ -136,7 +136,7 @@ func (u *unmarshalInfo) unmarshal(m pointer, b []byte) error {
u.computeUnmarshalInfo()
}
if u.isMessageSet {
return UnmarshalMessageSet(b, m.offset(u.extensions).toExtensions())
return unmarshalMessageSet(b, m.offset(u.extensions).toExtensions())
}
var reqMask uint64 // bitmask of required fields we've seen.
var errLater error
@@ -362,46 +362,48 @@ func (u *unmarshalInfo) computeUnmarshalInfo() {
}
// Find any types associated with oneof fields.
// TODO: XXX_OneofFuncs returns more info than we need. Get rid of some of it?
fn := reflect.Zero(reflect.PtrTo(t)).MethodByName("XXX_OneofFuncs")
if fn.IsValid() {
res := fn.Call(nil)[3] // last return value from XXX_OneofFuncs: []interface{}
for i := res.Len() - 1; i >= 0; i-- {
v := res.Index(i) // interface{}
tptr := reflect.ValueOf(v.Interface()).Type() // *Msg_X
typ := tptr.Elem() // Msg_X
var oneofImplementers []interface{}
switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) {
case oneofFuncsIface:
_, _, _, oneofImplementers = m.XXX_OneofFuncs()
case oneofWrappersIface:
oneofImplementers = m.XXX_OneofWrappers()
}
for _, v := range oneofImplementers {
tptr := reflect.TypeOf(v) // *Msg_X
typ := tptr.Elem() // Msg_X
f := typ.Field(0) // oneof implementers have one field
baseUnmarshal := fieldUnmarshaler(&f)
tags := strings.Split(f.Tag.Get("protobuf"), ",")
fieldNum, err := strconv.Atoi(tags[1])
if err != nil {
panic("protobuf tag field not an integer: " + tags[1])
}
var name string
for _, tag := range tags {
if strings.HasPrefix(tag, "name=") {
name = strings.TrimPrefix(tag, "name=")
break
}
}
// Find the oneof field that this struct implements.
// Might take O(n^2) to process all of the oneofs, but who cares.
for _, of := range oneofFields {
if tptr.Implements(of.ityp) {
// We have found the corresponding interface for this struct.
// That lets us know where this struct should be stored
// when we encounter it during unmarshaling.
unmarshal := makeUnmarshalOneof(typ, of.ityp, baseUnmarshal)
u.setTag(fieldNum, of.field, unmarshal, 0, name)
}
f := typ.Field(0) // oneof implementers have one field
baseUnmarshal := fieldUnmarshaler(&f)
tags := strings.Split(f.Tag.Get("protobuf"), ",")
fieldNum, err := strconv.Atoi(tags[1])
if err != nil {
panic("protobuf tag field not an integer: " + tags[1])
}
var name string
for _, tag := range tags {
if strings.HasPrefix(tag, "name=") {
name = strings.TrimPrefix(tag, "name=")
break
}
}
// Find the oneof field that this struct implements.
// Might take O(n^2) to process all of the oneofs, but who cares.
for _, of := range oneofFields {
if tptr.Implements(of.ityp) {
// We have found the corresponding interface for this struct.
// That lets us know where this struct should be stored
// when we encounter it during unmarshaling.
unmarshal := makeUnmarshalOneof(typ, of.ityp, baseUnmarshal)
u.setTag(fieldNum, of.field, unmarshal, 0, name)
}
}
}
// Get extension ranges, if any.
fn = reflect.Zero(reflect.PtrTo(t)).MethodByName("ExtensionRangeArray")
fn := reflect.Zero(reflect.PtrTo(t)).MethodByName("ExtensionRangeArray")
if fn.IsValid() {
if !u.extensions.IsValid() && !u.oldExtensions.IsValid() {
panic("a message with extensions, but no extensions field in " + t.Name())
@@ -1948,7 +1950,7 @@ func encodeVarint(b []byte, x uint64) []byte {
// If there is an error, it returns 0,0.
func decodeVarint(b []byte) (uint64, int) {
var x, y uint64
if len(b) <= 0 {
if len(b) == 0 {
goto bad
}
x = uint64(b[0])

File diff suppressed because it is too large Load Diff

View File

@@ -417,6 +417,17 @@ message FileOptions {
// determining the namespace.
optional string php_namespace = 41;
// Use this option to change the namespace of php generated metadata classes.
// Default is empty. When this option is empty, the proto file name will be used
// for determining the namespace.
optional string php_metadata_namespace = 44;
// Use this option to change the package of ruby generated classes. Default
// is empty. When this option is not set, the package name will be used for
// determining the ruby package.
optional string ruby_package = 45;
// The parser stores options it doesn't recognize here.
// See the documentation for the "Options" section above.
repeated UninterpretedOption uninterpreted_option = 999;

View File

@@ -43,6 +43,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"go/ast"
"go/build"
"go/parser"
"go/printer"
@@ -67,7 +68,7 @@ import (
// It is incremented whenever an incompatibility between the generated code and
// proto package is introduced; the generated code references
// a constant, proto.ProtoPackageIsVersionN (where N is generatedCodeVersion).
const generatedCodeVersion = 2
const generatedCodeVersion = 3
// A Plugin provides functionality to add to the output during Go code generation,
// such as to produce RPC stubs.
@@ -271,7 +272,6 @@ type FileDescriptor struct {
// This is used for supporting public imports.
exported map[Object][]symbol
fingerprint string // Fingerprint of this file's contents.
importPath GoImportPath // Import path of this file's package.
packageName GoPackageName // Name of this file's Go package.
@@ -282,8 +282,8 @@ type FileDescriptor struct {
// to the compressed bytes of this descriptor. It is not exported, so
// it is only valid inside the generated package.
func (d *FileDescriptor) VarName() string {
name := strings.Map(badToUnderscore, baseName(d.GetName()))
return fmt.Sprintf("fileDescriptor_%s_%s", name, d.fingerprint)
h := sha256.Sum256([]byte(d.GetName()))
return fmt.Sprintf("fileDescriptor_%s", hex.EncodeToString(h[:8]))
}
// goPackageOption interprets the file's go_package option.
@@ -340,7 +340,7 @@ func (d *FileDescriptor) addExport(obj Object, sym symbol) {
type symbol interface {
// GenerateAlias should generate an appropriate alias
// for the symbol from the named package.
GenerateAlias(g *Generator, pkg GoPackageName)
GenerateAlias(g *Generator, filename string, pkg GoPackageName)
}
type messageSymbol struct {
@@ -356,7 +356,8 @@ type getterSymbol struct {
genType bool // whether typ contains a generated type (message/group/enum)
}
func (ms *messageSymbol) GenerateAlias(g *Generator, pkg GoPackageName) {
func (ms *messageSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) {
g.P("// ", ms.sym, " from public import ", filename)
g.P("type ", ms.sym, " = ", pkg, ".", ms.sym)
for _, name := range ms.oneofTypes {
g.P("type ", name, " = ", pkg, ".", name)
@@ -368,8 +369,9 @@ type enumSymbol struct {
proto3 bool // Whether this came from a proto3 file.
}
func (es enumSymbol) GenerateAlias(g *Generator, pkg GoPackageName) {
func (es enumSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) {
s := es.name
g.P("// ", s, " from public import ", filename)
g.P("type ", s, " = ", pkg, ".", s)
g.P("var ", s, "_name = ", pkg, ".", s, "_name")
g.P("var ", s, "_value = ", pkg, ".", s, "_value")
@@ -381,7 +383,7 @@ type constOrVarSymbol struct {
cast string // if non-empty, a type cast is required (used for enums)
}
func (cs constOrVarSymbol) GenerateAlias(g *Generator, pkg GoPackageName) {
func (cs constOrVarSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) {
v := string(pkg) + "." + cs.sym
if cs.cast != "" {
v = cs.cast + "(" + v + ")"
@@ -418,6 +420,7 @@ type Generator struct {
packageNames map[GoImportPath]GoPackageName // Imported package names in the current file.
usedPackages map[GoImportPath]bool // Packages used in current file.
usedPackageNames map[GoPackageName]bool // Package names used in the current file.
addedImports map[GoImportPath]bool // Additional imports to emit.
typeNameToObject map[string]Object // Key is a fully-qualified name in input syntax.
init []string // Lines to emit in the init function.
indent string
@@ -532,7 +535,7 @@ func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
return name
}
name := cleanPackageName(baseName(string(importPath)))
for i, orig := 1, name; g.usedPackageNames[name]; i++ {
for i, orig := 1, name; g.usedPackageNames[name] || isGoPredeclaredIdentifier[string(name)]; i++ {
name = orig + GoPackageName(strconv.Itoa(i))
}
g.packageNames[importPath] = name
@@ -540,6 +543,13 @@ func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
return name
}
// AddImport adds a package to the generated file's import section.
// It returns the name used for the package.
func (g *Generator) AddImport(importPath GoImportPath) GoPackageName {
g.addedImports[importPath] = true
return g.GoPackageName(importPath)
}
var globalPackageNames = map[GoPackageName]bool{
"fmt": true,
"math": true,
@@ -585,9 +595,51 @@ var isGoKeyword = map[string]bool{
"var": true,
}
var isGoPredeclaredIdentifier = map[string]bool{
"append": true,
"bool": true,
"byte": true,
"cap": true,
"close": true,
"complex": true,
"complex128": true,
"complex64": true,
"copy": true,
"delete": true,
"error": true,
"false": true,
"float32": true,
"float64": true,
"imag": true,
"int": true,
"int16": true,
"int32": true,
"int64": true,
"int8": true,
"iota": true,
"len": true,
"make": true,
"new": true,
"nil": true,
"panic": true,
"print": true,
"println": true,
"real": true,
"recover": true,
"rune": true,
"string": true,
"true": true,
"uint": true,
"uint16": true,
"uint32": true,
"uint64": true,
"uint8": true,
"uintptr": true,
}
func cleanPackageName(name string) GoPackageName {
name = strings.Map(badToUnderscore, name)
// Identifier must not be keyword: insert _.
// Identifier must not be keyword or predeclared identifier: insert _.
if isGoKeyword[name] {
name = "_" + name
}
@@ -724,27 +776,10 @@ func (g *Generator) WrapTypes() {
if fd == nil {
g.Fail("could not find file named", fileName)
}
fingerprint, err := fingerprintProto(fd.FileDescriptorProto)
if err != nil {
g.Error(err)
}
fd.fingerprint = fingerprint
g.genFiles = append(g.genFiles, fd)
}
}
// fingerprintProto returns a fingerprint for a message.
// The fingerprint is intended to prevent conflicts between generated fileds,
// not to provide cryptographic security.
func fingerprintProto(m proto.Message) (string, error) {
b, err := proto.Marshal(m)
if err != nil {
return "", err
}
h := sha256.Sum256(b)
return hex.EncodeToString(h[:8]), nil
}
// Scan the descriptors in this file. For each one, build the slice of nested descriptors
func (g *Generator) buildNestedDescriptors(descs []*Descriptor) {
for _, desc := range descs {
@@ -938,39 +973,6 @@ func (g *Generator) ObjectNamed(typeName string) Object {
if !ok {
g.Fail("can't find object with type", typeName)
}
// If the file of this object isn't a direct dependency of the current file,
// or in the current file, then this object has been publicly imported into
// a dependency of the current file.
// We should return the ImportedDescriptor object for it instead.
direct := *o.File().Name == *g.file.Name
if !direct {
for _, dep := range g.file.Dependency {
if *g.fileByName(dep).Name == *o.File().Name {
direct = true
break
}
}
}
if !direct {
found := false
Loop:
for _, dep := range g.file.Dependency {
df := g.fileByName(*g.fileByName(dep).Name)
for _, td := range df.imp {
if td.o == o {
// Found it!
o = td
found = true
break Loop
}
}
}
if !found {
log.Printf("protoc-gen-go: WARNING: failed finding publicly imported dependency for %v, used in %v", typeName, *g.file.Name)
}
}
return o
}
@@ -1124,6 +1126,7 @@ func (g *Generator) generate(file *FileDescriptor) {
g.usedPackages = make(map[GoImportPath]bool)
g.packageNames = make(map[GoImportPath]GoPackageName)
g.usedPackageNames = make(map[GoPackageName]bool)
g.addedImports = make(map[GoImportPath]bool)
for name := range globalPackageNames {
g.usedPackageNames[name] = true
}
@@ -1152,12 +1155,11 @@ func (g *Generator) generate(file *FileDescriptor) {
g.generateExtension(ext)
}
g.generateInitFunction()
g.generateFileDescriptor(file)
// Run the plugins before the imports so we know which imports are necessary.
g.runPlugins(file)
g.generateFileDescriptor(file)
// Generate header and imports last, though they appear first in the output.
rem := g.Buffer
remAnno := g.annotations
@@ -1183,7 +1185,7 @@ func (g *Generator) generate(file *FileDescriptor) {
// make a copy independent of g; we'll need it after Reset.
original = append([]byte(nil), original...)
}
ast, err := parser.ParseFile(fset, "", original, parser.ParseComments)
fileAST, err := parser.ParseFile(fset, "", original, parser.ParseComments)
if err != nil {
// Print out the bad code with line numbers.
// This should never happen in practice, but it can while changing generated code,
@@ -1195,8 +1197,9 @@ func (g *Generator) generate(file *FileDescriptor) {
}
g.Fail("bad Go source code was generated:", err.Error(), "\n"+src.String())
}
ast.SortImports(fset, fileAST)
g.Reset()
err = (&printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8}).Fprint(g, fset, ast)
err = (&printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8}).Fprint(g, fset, fileAST)
if err != nil {
g.Fail("generated Go source code could not be reformatted:", err.Error())
}
@@ -1225,28 +1228,10 @@ func (g *Generator) generateHeader() {
g.P("// source: ", g.file.Name)
}
g.P()
importPath, _, _ := g.file.goPackageOption()
if importPath == "" {
g.P("package ", g.file.packageName)
} else {
g.P("package ", g.file.packageName, " // import ", GoImportPath(g.ImportPrefix)+importPath)
}
g.PrintComments(strconv.Itoa(packagePath))
g.P()
g.P("package ", g.file.packageName)
g.P()
if loc, ok := g.file.comments[strconv.Itoa(packagePath)]; ok {
g.P("/*")
// not using g.PrintComments because this is a /* */ comment block.
text := strings.TrimSuffix(loc.GetLeadingComments(), "\n")
for _, line := range strings.Split(text, "\n") {
line = strings.TrimPrefix(line, " ")
// ensure we don't escape from the block comment
line = strings.Replace(line, "*/", "* /", -1)
g.P(line)
}
g.P("*/")
g.P()
}
}
// deprecationComment is the standard comment added to deprecated
@@ -1277,7 +1262,7 @@ func (g *Generator) makeComments(path string) (string, bool) {
w := new(bytes.Buffer)
nl := ""
for _, line := range strings.Split(strings.TrimSuffix(loc.GetLeadingComments(), "\n"), "\n") {
fmt.Fprintf(w, "%s// %s", nl, strings.TrimPrefix(line, " "))
fmt.Fprintf(w, "%s//%s", nl, line)
nl = "\n"
}
return w.String(), true
@@ -1299,17 +1284,7 @@ func (g *Generator) weak(i int32) bool {
// Generate the imports
func (g *Generator) generateImports() {
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the fmt and math packages.
g.P("import "+g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
g.P("import " + g.Pkg["fmt"] + ` "fmt"`)
g.P("import " + g.Pkg["math"] + ` "math"`)
var (
imports = make(map[GoImportPath]bool)
strongImports = make(map[GoImportPath]bool)
importPaths []string
)
imports := make(map[GoImportPath]GoPackageName)
for i, s := range g.file.Dependency {
fd := g.fileByName(s)
importPath := fd.importPath
@@ -1317,32 +1292,37 @@ func (g *Generator) generateImports() {
if importPath == g.file.importPath {
continue
}
if !imports[importPath] {
importPaths = append(importPaths, string(importPath))
// Do not import weak imports.
if g.weak(int32(i)) {
continue
}
imports[importPath] = true
if !g.weak(int32(i)) {
strongImports[importPath] = true
}
}
sort.Strings(importPaths)
for i := range importPaths {
importPath := GoImportPath(importPaths[i])
packageName := g.GoPackageName(importPath)
fullPath := GoImportPath(g.ImportPrefix) + importPath
// Skip weak imports.
if !strongImports[importPath] {
g.P("// skipping weak import ", packageName, " ", fullPath)
// Do not import a package twice.
if _, ok := imports[importPath]; ok {
continue
}
// We need to import all the dependencies, even if we don't reference them,
// because other code and tools depend on having the full transitive closure
// of protocol buffer types in the binary.
packageName := g.GoPackageName(importPath)
if _, ok := g.usedPackages[importPath]; !ok {
packageName = "_"
}
g.P("import ", packageName, " ", fullPath)
imports[importPath] = packageName
}
for importPath := range g.addedImports {
imports[importPath] = g.GoPackageName(importPath)
}
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the fmt and math packages.
g.P("import (")
g.P(g.Pkg["fmt"] + ` "fmt"`)
g.P(g.Pkg["math"] + ` "math"`)
g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
for importPath, packageName := range imports {
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
}
g.P(")")
g.P()
// TODO: may need to worry about uniqueness across plugins
for _, p := range plugins {
@@ -1357,24 +1337,19 @@ func (g *Generator) generateImports() {
}
func (g *Generator) generateImported(id *ImportedDescriptor) {
tn := id.TypeName()
sn := tn[len(tn)-1]
df := id.o.File()
filename := *df.Name
if df.importPath == g.file.importPath {
// Don't generate type aliases for files in the same Go package as this one.
g.P("// Ignoring public import of ", sn, " from ", filename)
g.P()
return
}
if !supportTypeAliases {
g.Fail(fmt.Sprintf("%s: public imports require at least go1.9", filename))
}
g.P("// ", sn, " from public import ", filename)
g.usedPackages[df.importPath] = true
for _, sym := range df.exported[id.o] {
sym.GenerateAlias(g, g.GoPackageName(df.importPath))
sym.GenerateAlias(g, filename, g.GoPackageName(df.importPath))
}
g.P()
@@ -1410,6 +1385,7 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
g.file.addExport(enum, constOrVarSymbol{name, "const", ccTypeName})
}
g.P(")")
g.P()
g.P("var ", ccTypeName, "_name = map[int32]string{")
generated := make(map[int32]bool) // avoid duplicate values
for _, e := range enum.Value {
@@ -1421,11 +1397,13 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
generated[*e.Number] = true
}
g.P("}")
g.P()
g.P("var ", ccTypeName, "_value = map[string]int32{")
for _, e := range enum.Value {
g.P(strconv.Quote(*e.Name), ": ", e.Number, ",")
}
g.P("}")
g.P()
if !enum.proto3() {
g.P("func (x ", ccTypeName, ") Enum() *", ccTypeName, " {")
@@ -1433,11 +1411,13 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
g.P("*p = x")
g.P("return p")
g.P("}")
g.P()
}
g.P("func (x ", ccTypeName, ") String() string {")
g.P("return ", g.Pkg["proto"], ".EnumName(", ccTypeName, "_name, int32(x))")
g.P("}")
g.P()
if !enum.proto3() {
g.P("func (x *", ccTypeName, ") UnmarshalJSON(data []byte) error {")
@@ -1448,6 +1428,7 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
g.P("*x = ", ccTypeName, "(value)")
g.P("return nil")
g.P("}")
g.P()
}
var indexes []string
@@ -1459,11 +1440,13 @@ func (g *Generator) generateEnum(enum *EnumDescriptor) {
g.P("func (", ccTypeName, ") EnumDescriptor() ([]byte, []int) {")
g.P("return ", g.file.VarName(), ", []int{", strings.Join(indexes, ", "), "}")
g.P("}")
g.P()
if enum.file.GetPackage() == "google.protobuf" && enum.GetName() == "NullValue" {
g.P("func (", ccTypeName, `) XXX_WellKnownType() string { return "`, enum.GetName(), `" }`)
g.P()
}
g.P()
g.generateEnumRegistration(enum)
}
// The tag is a string like "varint,2,opt,name=fieldname,def=7" that
@@ -1520,6 +1503,18 @@ func (g *Generator) goTag(message *Descriptor, field *descriptor.FieldDescriptor
g.Fail("unknown enum type", CamelCaseSlice(obj.TypeName()))
}
defaultValue = enum.integerValueAsString(defaultValue)
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
if def := defaultValue; def != "inf" && def != "-inf" && def != "nan" {
if f, err := strconv.ParseFloat(defaultValue, 32); err == nil {
defaultValue = fmt.Sprint(float32(f))
}
}
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
if def := defaultValue; def != "inf" && def != "-inf" && def != "nan" {
if f, err := strconv.ParseFloat(defaultValue, 64); err == nil {
defaultValue = fmt.Sprint(f)
}
}
}
defaultValue = ",def=" + defaultValue
}
@@ -1557,7 +1552,7 @@ func (g *Generator) goTag(message *Descriptor, field *descriptor.FieldDescriptor
name = name[i+1:]
}
}
if json := field.GetJsonName(); json != "" && json != name {
if json := field.GetJsonName(); field.Extendee == nil && json != "" && json != name {
// TODO: escaping might be needed, in which case
// perhaps this should be in its own "json" tag.
name += ",json=" + json
@@ -1661,11 +1656,16 @@ func (g *Generator) GoType(message *Descriptor, field *descriptor.FieldDescripto
}
func (g *Generator) RecordTypeUse(t string) {
if _, ok := g.typeNameToObject[t]; ok {
// Call ObjectNamed to get the true object to record the use.
obj := g.ObjectNamed(t)
g.usedPackages[obj.GoImportPath()] = true
if _, ok := g.typeNameToObject[t]; !ok {
return
}
importPath := g.ObjectNamed(t).GoImportPath()
if importPath == g.outputImportPath {
// Don't record use of objects in our package.
return
}
g.AddImport(importPath)
g.usedPackages[importPath] = true
}
// Method names that may be generated. Fields with these names get an
@@ -1765,7 +1765,7 @@ func (g *Generator) defaultConstantName(goMessageType, protoFieldName string) st
// oneofField - field containing list of subfields:
// - oneofSubField - a field within the oneof
// msgCtx contais the context for the generator functions.
// msgCtx contains the context for the generator functions.
type msgCtx struct {
goName string // Go struct name of the message, e.g. MessageName
message *Descriptor // The descriptor for the message
@@ -1869,216 +1869,15 @@ type oneofSubField struct {
fieldNumber int // Actual field number, as defined in proto, e.g. 12
getterDef string // Default for getters, e.g. "nil", `""` or "Default_MessageType_FieldName"
protoDef string // Default value as defined in the proto file, e.g "yoshi" or "5"
}
// wireTypeName returns a textual wire type, needed for oneof sub fields in generated code.
func (f *oneofSubField) wireTypeName() string {
switch f.protoType {
case descriptor.FieldDescriptorProto_TYPE_FIXED64,
descriptor.FieldDescriptorProto_TYPE_SFIXED64,
descriptor.FieldDescriptorProto_TYPE_DOUBLE:
return "WireFixed64"
case descriptor.FieldDescriptorProto_TYPE_FIXED32,
descriptor.FieldDescriptorProto_TYPE_SFIXED32,
descriptor.FieldDescriptorProto_TYPE_FLOAT:
return "WireFixed32"
case descriptor.FieldDescriptorProto_TYPE_GROUP:
return "WireStartGroup"
case descriptor.FieldDescriptorProto_TYPE_MESSAGE,
descriptor.FieldDescriptorProto_TYPE_STRING,
descriptor.FieldDescriptorProto_TYPE_BYTES:
return "WireBytes"
default: // All others are Varints
return "WireVarint"
}
deprecated string // Deprecation comment, if any.
}
// typedNil prints a nil casted to the pointer to this field.
// - for XXX_OneofFuncs
// - for XXX_OneofWrappers
func (f *oneofSubField) typedNil(g *Generator) {
g.P("(*", f.oneofTypeName, ")(nil),")
}
// marshalCase prints the case matching this oneof subfield in the marshalling code.
func (f *oneofSubField) marshalCase(g *Generator) {
g.P("case *", f.oneofTypeName, ":")
wire := f.wireTypeName()
var pre, post string
val := "x." + f.goName // overridden for TYPE_BOOL
switch f.protoType {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
pre = "b.EncodeFixed64(" + g.Pkg["math"] + ".Float64bits("
post = "))"
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
pre = "b.EncodeFixed32(uint64(" + g.Pkg["math"] + ".Float32bits("
post = ")))"
case descriptor.FieldDescriptorProto_TYPE_INT64, descriptor.FieldDescriptorProto_TYPE_UINT64:
pre, post = "b.EncodeVarint(uint64(", "))"
case descriptor.FieldDescriptorProto_TYPE_INT32, descriptor.FieldDescriptorProto_TYPE_UINT32, descriptor.FieldDescriptorProto_TYPE_ENUM:
pre, post = "b.EncodeVarint(uint64(", "))"
case descriptor.FieldDescriptorProto_TYPE_FIXED64, descriptor.FieldDescriptorProto_TYPE_SFIXED64:
pre, post = "b.EncodeFixed64(uint64(", "))"
case descriptor.FieldDescriptorProto_TYPE_FIXED32, descriptor.FieldDescriptorProto_TYPE_SFIXED32:
pre, post = "b.EncodeFixed32(uint64(", "))"
case descriptor.FieldDescriptorProto_TYPE_BOOL:
g.P("t := uint64(0)")
g.P("if ", val, " { t = 1 }")
val = "t"
pre, post = "b.EncodeVarint(", ")"
case descriptor.FieldDescriptorProto_TYPE_STRING:
pre, post = "b.EncodeStringBytes(", ")"
case descriptor.FieldDescriptorProto_TYPE_GROUP:
pre, post = "b.Marshal(", ")"
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
pre, post = "b.EncodeMessage(", ")"
case descriptor.FieldDescriptorProto_TYPE_BYTES:
pre, post = "b.EncodeRawBytes(", ")"
case descriptor.FieldDescriptorProto_TYPE_SINT32:
pre, post = "b.EncodeZigzag32(uint64(", "))"
case descriptor.FieldDescriptorProto_TYPE_SINT64:
pre, post = "b.EncodeZigzag64(uint64(", "))"
default:
g.Fail("unhandled oneof field type ", f.protoType.String())
}
g.P("b.EncodeVarint(", f.fieldNumber, "<<3|", g.Pkg["proto"], ".", wire, ")")
if t := f.protoType; t != descriptor.FieldDescriptorProto_TYPE_GROUP && t != descriptor.FieldDescriptorProto_TYPE_MESSAGE {
g.P(pre, val, post)
} else {
g.P("if err := ", pre, val, post, "; err != nil {")
g.P("return err")
g.P("}")
}
if f.protoType == descriptor.FieldDescriptorProto_TYPE_GROUP {
g.P("b.EncodeVarint(", f.fieldNumber, "<<3|", g.Pkg["proto"], ".WireEndGroup)")
}
}
// unmarshalCase prints the case matching this oneof subfield in the unmarshalling code.
func (f *oneofSubField) unmarshalCase(g *Generator, origOneofName string, oneofName string) {
g.P("case ", f.fieldNumber, ": // ", origOneofName, ".", f.getProtoName())
g.P("if wire != ", g.Pkg["proto"], ".", f.wireTypeName(), " {")
g.P("return true, ", g.Pkg["proto"], ".ErrInternalBadWireType")
g.P("}")
lhs := "x, err" // overridden for TYPE_MESSAGE and TYPE_GROUP
var dec, cast, cast2 string
switch f.protoType {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
dec, cast = "b.DecodeFixed64()", g.Pkg["math"]+".Float64frombits"
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
dec, cast, cast2 = "b.DecodeFixed32()", "uint32", g.Pkg["math"]+".Float32frombits"
case descriptor.FieldDescriptorProto_TYPE_INT64:
dec, cast = "b.DecodeVarint()", "int64"
case descriptor.FieldDescriptorProto_TYPE_UINT64:
dec = "b.DecodeVarint()"
case descriptor.FieldDescriptorProto_TYPE_INT32:
dec, cast = "b.DecodeVarint()", "int32"
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
dec = "b.DecodeFixed64()"
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
dec, cast = "b.DecodeFixed32()", "uint32"
case descriptor.FieldDescriptorProto_TYPE_BOOL:
dec = "b.DecodeVarint()"
// handled specially below
case descriptor.FieldDescriptorProto_TYPE_STRING:
dec = "b.DecodeStringBytes()"
case descriptor.FieldDescriptorProto_TYPE_GROUP:
g.P("msg := new(", f.goType[1:], ")") // drop star
lhs = "err"
dec = "b.DecodeGroup(msg)"
// handled specially below
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
g.P("msg := new(", f.goType[1:], ")") // drop star
lhs = "err"
dec = "b.DecodeMessage(msg)"
// handled specially below
case descriptor.FieldDescriptorProto_TYPE_BYTES:
dec = "b.DecodeRawBytes(true)"
case descriptor.FieldDescriptorProto_TYPE_UINT32:
dec, cast = "b.DecodeVarint()", "uint32"
case descriptor.FieldDescriptorProto_TYPE_ENUM:
dec, cast = "b.DecodeVarint()", f.goType
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
dec, cast = "b.DecodeFixed32()", "int32"
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
dec, cast = "b.DecodeFixed64()", "int64"
case descriptor.FieldDescriptorProto_TYPE_SINT32:
dec, cast = "b.DecodeZigzag32()", "int32"
case descriptor.FieldDescriptorProto_TYPE_SINT64:
dec, cast = "b.DecodeZigzag64()", "int64"
default:
g.Fail("unhandled oneof field type ", f.protoType.String())
}
g.P(lhs, " := ", dec)
val := "x"
if cast != "" {
val = cast + "(" + val + ")"
}
if cast2 != "" {
val = cast2 + "(" + val + ")"
}
switch f.protoType {
case descriptor.FieldDescriptorProto_TYPE_BOOL:
val += " != 0"
case descriptor.FieldDescriptorProto_TYPE_GROUP,
descriptor.FieldDescriptorProto_TYPE_MESSAGE:
val = "msg"
}
g.P("m.", oneofName, " = &", f.oneofTypeName, "{", val, "}")
g.P("return true, err")
}
// sizerCase prints the case matching this oneof subfield in the sizer code.
func (f *oneofSubField) sizerCase(g *Generator) {
g.P("case *", f.oneofTypeName, ":")
val := "x." + f.goName
var varint, fixed string
switch f.protoType {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
fixed = "8"
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
fixed = "4"
case descriptor.FieldDescriptorProto_TYPE_INT64, descriptor.FieldDescriptorProto_TYPE_UINT64, descriptor.FieldDescriptorProto_TYPE_INT32, descriptor.FieldDescriptorProto_TYPE_UINT32, descriptor.FieldDescriptorProto_TYPE_ENUM:
varint = val
case descriptor.FieldDescriptorProto_TYPE_FIXED64, descriptor.FieldDescriptorProto_TYPE_SFIXED64:
fixed = "8"
case descriptor.FieldDescriptorProto_TYPE_FIXED32, descriptor.FieldDescriptorProto_TYPE_SFIXED32:
fixed = "4"
case descriptor.FieldDescriptorProto_TYPE_BOOL:
fixed = "1"
case descriptor.FieldDescriptorProto_TYPE_STRING:
fixed = "len(" + val + ")"
varint = fixed
case descriptor.FieldDescriptorProto_TYPE_GROUP:
fixed = g.Pkg["proto"] + ".Size(" + val + ")"
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
g.P("s := ", g.Pkg["proto"], ".Size(", val, ")")
fixed = "s"
varint = fixed
case descriptor.FieldDescriptorProto_TYPE_BYTES:
fixed = "len(" + val + ")"
varint = fixed
case descriptor.FieldDescriptorProto_TYPE_SINT32:
varint = "(uint32(" + val + ") << 1) ^ uint32((int32(" + val + ") >> 31))"
case descriptor.FieldDescriptorProto_TYPE_SINT64:
varint = "uint64(" + val + " << 1) ^ uint64((int64(" + val + ") >> 63))"
default:
g.Fail("unhandled oneof field type ", f.protoType.String())
}
// Tag and wire varint is known statically,
// so don't generate code for that part of the size computation.
tagAndWireSize := proto.SizeVarint(uint64(f.fieldNumber << 3)) // wire doesn't affect varint size
g.P("n += ", tagAndWireSize, " // tag and wire")
if varint != "" {
g.P("n += ", g.Pkg["proto"], ".SizeVarint(uint64(", varint, "))")
}
if fixed != "" {
g.P("n += ", fixed)
}
if f.protoType == descriptor.FieldDescriptorProto_TYPE_GROUP {
g.P("n += ", tagAndWireSize, " // tag and wire")
}
}
// getProtoDef returns the default value explicitly stated in the proto file, e.g "yoshi" or "5".
func (f *oneofSubField) getProtoDef() string {
return f.protoDef
@@ -2138,6 +1937,9 @@ func (f *oneofField) getter(g *Generator, mc *msgCtx) {
g.P()
// Getters for each oneof
for _, sf := range f.subFields {
if sf.deprecated != "" {
g.P(sf.deprecated)
}
g.P("func (m *", mc.goName, ") ", Annotate(mc.message.file, sf.fullPath, sf.getterName), "() "+sf.goType+" {")
g.P("if x, ok := m.", f.getterName, "().(*", sf.oneofTypeName, "); ok {")
g.P("return x.", sf.goName)
@@ -2215,6 +2017,14 @@ func (g *Generator) generateDefaultConstants(mc *msgCtx, topLevelFields []topLev
def = "float32(" + def + ")"
}
kind = "var "
case df.getProtoType() == descriptor.FieldDescriptorProto_TYPE_FLOAT:
if f, err := strconv.ParseFloat(def, 32); err == nil {
def = fmt.Sprint(float32(f))
}
case df.getProtoType() == descriptor.FieldDescriptorProto_TYPE_DOUBLE:
if f, err := strconv.ParseFloat(def, 64); err == nil {
def = fmt.Sprint(f)
}
case df.getProtoType() == descriptor.FieldDescriptorProto_TYPE_ENUM:
// Must be an enum. Need to construct the prefixed name.
obj := g.ObjectNamed(df.getProtoTypeName())
@@ -2263,17 +2073,11 @@ func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelFiel
if len(ofields) == 0 {
return
}
enc := "_" + mc.goName + "_OneofMarshaler"
dec := "_" + mc.goName + "_OneofUnmarshaler"
size := "_" + mc.goName + "_OneofSizer"
encSig := "(msg " + g.Pkg["proto"] + ".Message, b *" + g.Pkg["proto"] + ".Buffer) error"
decSig := "(msg " + g.Pkg["proto"] + ".Message, tag, wire int, b *" + g.Pkg["proto"] + ".Buffer) (bool, error)"
sizeSig := "(msg " + g.Pkg["proto"] + ".Message) (n int)"
// OneofFuncs
g.P("// XXX_OneofFuncs is for the internal use of the proto package.")
g.P("func (*", mc.goName, ") XXX_OneofFuncs() (func", encSig, ", func", decSig, ", func", sizeSig, ", []interface{}) {")
g.P("return ", enc, ", ", dec, ", ", size, ", []interface{}{")
g.P("// XXX_OneofWrappers is for the internal use of the proto package.")
g.P("func (*", mc.goName, ") XXX_OneofWrappers() []interface{} {")
g.P("return []interface{}{")
for _, of := range ofields {
for _, sf := range of.subFields {
sf.typedNil(g)
@@ -2282,59 +2086,6 @@ func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelFiel
g.P("}")
g.P("}")
g.P()
// marshaler
g.P("func ", enc, encSig, " {")
g.P("m := msg.(*", mc.goName, ")")
for _, of := range ofields {
g.P("// ", of.getProtoName())
g.P("switch x := m.", of.goName, ".(type) {")
for _, sf := range of.subFields {
// also fills in field.wire
sf.marshalCase(g)
}
g.P("case nil:")
g.P("default:")
g.P(" return ", g.Pkg["fmt"], `.Errorf("`, mc.goName, ".", of.goName, ` has unexpected type %T", x)`)
g.P("}")
}
g.P("return nil")
g.P("}")
g.P()
// unmarshaler
g.P("func ", dec, decSig, " {")
g.P("m := msg.(*", mc.goName, ")")
g.P("switch tag {")
for _, of := range ofields {
for _, sf := range of.subFields {
sf.unmarshalCase(g, of.getProtoName(), of.goName)
}
}
g.P("default:")
g.P("return false, nil")
g.P("}")
g.P("}")
g.P()
// sizer
g.P("func ", size, sizeSig, " {")
g.P("m := msg.(*", mc.goName, ")")
for _, of := range ofields {
g.P("// ", of.getProtoName())
g.P("switch x := m.", of.goName, ".(type) {")
for _, sf := range of.subFields {
// also fills in field.wire
sf.sizerCase(g)
}
g.P("case nil:")
g.P("default:")
g.P("panic(", g.Pkg["fmt"], ".Sprintf(\"proto: unexpected type %T in oneof\", x))")
g.P("}")
}
g.P("return n")
g.P("}")
g.P()
}
// generateMessageStruct adds the actual struct with it's members (but not methods) to the output.
@@ -2386,25 +2137,16 @@ func (g *Generator) generateCommonMethods(mc *msgCtx) {
g.P("func (*", mc.goName, ") Descriptor() ([]byte, []int) {")
g.P("return ", g.file.VarName(), ", []int{", strings.Join(indexes, ", "), "}")
g.P("}")
g.P()
// TODO: Revisit the decision to use a XXX_WellKnownType method
// if we change proto.MessageName to work with multiple equivalents.
if mc.message.file.GetPackage() == "google.protobuf" && wellKnownTypes[mc.message.GetName()] {
g.P("func (*", mc.goName, `) XXX_WellKnownType() string { return "`, mc.message.GetName(), `" }`)
g.P()
}
// Extension support methods
if len(mc.message.ExtensionRange) > 0 {
// message_set_wire_format only makes sense when extensions are defined.
if opts := mc.message.Options; opts != nil && opts.GetMessageSetWireFormat() {
g.P()
g.P("func (m *", mc.goName, ") MarshalJSON() ([]byte, error) {")
g.P("return ", g.Pkg["proto"], ".MarshalMessageSetJSON(&m.XXX_InternalExtensions)")
g.P("}")
g.P("func (m *", mc.goName, ") UnmarshalJSON(buf []byte) error {")
g.P("return ", g.Pkg["proto"], ".UnmarshalMessageSetJSON(buf, &m.XXX_InternalExtensions)")
g.P("}")
}
g.P()
g.P("var extRange_", mc.goName, " = []", g.Pkg["proto"], ".ExtensionRange{")
for _, r := range mc.message.ExtensionRange {
@@ -2415,6 +2157,7 @@ func (g *Generator) generateCommonMethods(mc *msgCtx) {
g.P("func (*", mc.goName, ") ExtensionRangeArray() []", g.Pkg["proto"], ".ExtensionRange {")
g.P("return extRange_", mc.goName)
g.P("}")
g.P()
}
// TODO: It does not scale to keep adding another method for every
@@ -2432,8 +2175,8 @@ func (g *Generator) generateCommonMethods(mc *msgCtx) {
g.P("return xxx_messageInfo_", mc.goName, ".Marshal(b, m, deterministic)")
g.P("}")
g.P("func (dst *", mc.goName, ") XXX_Merge(src ", g.Pkg["proto"], ".Message) {")
g.P("xxx_messageInfo_", mc.goName, ".Merge(dst, src)")
g.P("func (m *", mc.goName, ") XXX_Merge(src ", g.Pkg["proto"], ".Message) {")
g.P("xxx_messageInfo_", mc.goName, ".Merge(m, src)")
g.P("}")
g.P("func (m *", mc.goName, ") XXX_Size() int {") // avoid name clash with "Size" field in some message
@@ -2503,8 +2246,7 @@ func (g *Generator) generateMessage(message *Descriptor) {
if oneof && oFields[*field.OneofIndex] == nil {
odp := message.OneofDecl[int(*field.OneofIndex)]
base := CamelCase(odp.GetName())
names := allocNames(base, "Get"+base)
fname, gname := names[0], names[1]
fname := allocNames(base)[0]
// This is the first field of a oneof we haven't seen before.
// Generate the union field.
@@ -2522,7 +2264,7 @@ func (g *Generator) generateMessage(message *Descriptor) {
of := oneofField{
fieldCommon: fieldCommon{
goName: fname,
getterName: gname,
getterName: "Get"+fname,
goType: dname,
tags: tag,
protoName: odp.GetName(),
@@ -2564,6 +2306,11 @@ func (g *Generator) generateMessage(message *Descriptor) {
}
}
fieldDeprecated := ""
if field.GetOptions().GetDeprecated() {
fieldDeprecated = deprecationComment
}
dvalue := g.getterDefault(field, goTypeName)
if oneof {
tname := goTypeName + "_" + fieldName
@@ -2607,17 +2354,13 @@ func (g *Generator) generateMessage(message *Descriptor) {
getterDef: dvalue,
protoDef: field.GetDefaultValue(),
oneofTypeName: tname,
deprecated: fieldDeprecated,
}
oneofField.subFields = append(oneofField.subFields, &sf)
g.RecordTypeUse(field.GetTypeName())
continue
}
fieldDeprecated := ""
if field.GetOptions().GetDeprecated() {
fieldDeprecated = deprecationComment
}
fieldFullPath := fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i)
c, ok := g.makeComments(fieldFullPath)
if ok {
@@ -2663,27 +2406,24 @@ func (g *Generator) generateMessage(message *Descriptor) {
g.generateOneofFuncs(mc, topLevelFields)
g.P()
if !message.group {
var oneofTypes []string
for _, f := range topLevelFields {
if of, ok := f.(*oneofField); ok {
for _, osf := range of.subFields {
oneofTypes = append(oneofTypes, osf.oneofTypeName)
}
var oneofTypes []string
for _, f := range topLevelFields {
if of, ok := f.(*oneofField); ok {
for _, osf := range of.subFields {
oneofTypes = append(oneofTypes, osf.oneofTypeName)
}
}
opts := message.Options
ms := &messageSymbol{
sym: goTypeName,
hasExtensions: len(message.ExtensionRange) > 0,
isMessageSet: opts != nil && opts.GetMessageSetWireFormat(),
oneofTypes: oneofTypes,
}
g.file.addExport(message, ms)
}
opts := message.Options
ms := &messageSymbol{
sym: goTypeName,
hasExtensions: len(message.ExtensionRange) > 0,
isMessageSet: opts != nil && opts.GetMessageSetWireFormat(),
oneofTypes: oneofTypes,
}
g.file.addExport(message, ms)
for _, ext := range message.ext {
g.generateExtension(ext)
}
@@ -2811,10 +2551,8 @@ func (g *Generator) generateExtension(ext *ExtensionDescriptor) {
// In addition, the situation for when to apply this special case is implemented
// differently in other languages:
// https://github.com/google/protobuf/blob/aff10976/src/google/protobuf/text_format.cc#L1560
mset := false
if extDesc.GetOptions().GetMessageSetWireFormat() && typeName[len(typeName)-1] == "message_set_extension" {
typeName = typeName[:len(typeName)-1]
mset = true
}
// For text formatting, the package must be exactly what the .proto file declares,
@@ -2835,26 +2573,12 @@ func (g *Generator) generateExtension(ext *ExtensionDescriptor) {
g.P("}")
g.P()
if mset {
// Generate a bit more code to register with message_set.go.
g.addInitf("%s.RegisterMessageSetType((%s)(nil), %d, %q)", g.Pkg["proto"], fieldType, *field.Number, extName)
}
g.addInitf("%s.RegisterExtension(%s)", g.Pkg["proto"], ext.DescName())
g.file.addExport(ext, constOrVarSymbol{ccTypeName, "var", ""})
}
func (g *Generator) generateInitFunction() {
for _, enum := range g.file.enum {
g.generateEnumRegistration(enum)
}
for _, d := range g.file.desc {
for _, ext := range d.ext {
g.generateExtensionRegistration(ext)
}
}
for _, ext := range g.file.ext {
g.generateExtensionRegistration(ext)
}
if len(g.init) == 0 {
return
}
@@ -2918,10 +2642,6 @@ func (g *Generator) generateEnumRegistration(enum *EnumDescriptor) {
g.addInitf("%s.RegisterEnum(%q, %[3]s_name, %[3]s_value)", g.Pkg["proto"], pkg+ccTypeName, ccTypeName)
}
func (g *Generator) generateExtensionRegistration(ext *ExtensionDescriptor) {
g.addInitf("%s.RegisterExtension(%s)", g.Pkg["proto"], ext.DescName())
}
// And now lots of helper functions.
// Is c an ASCII lower-case letter?

View File

@@ -1,11 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/any.proto
package any // import "github.com/golang/protobuf/ptypes/any"
package any
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -16,7 +18,7 @@ var _ = math.Inf
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// `Any` contains an arbitrary serialized protocol buffer message along with a
// URL that describes the type of the serialized message.
@@ -99,17 +101,18 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// }
//
type Any struct {
// A URL/resource name whose content describes the type of the
// serialized protocol buffer message.
// A URL/resource name that uniquely identifies the type of the serialized
// protocol buffer message. The last segment of the URL's path must represent
// the fully qualified name of the type (as in
// `path/google.protobuf.Duration`). The name should be in a canonical form
// (e.g., leading "." is not accepted).
//
// For URLs which use the scheme `http`, `https`, or no scheme, the
// following restrictions and interpretations apply:
// In practice, teams usually precompile into the binary all types that they
// expect it to use in the context of Any. However, for URLs which use the
// scheme `http`, `https`, or no scheme, one can optionally set up a type
// server that maps type URLs to message definitions as follows:
//
// * If no scheme is provided, `https` is assumed.
// * The last segment of the URL's path must represent the fully
// qualified name of the type (as in `path/google.protobuf.Duration`).
// The name should be in a canonical form (e.g., leading "." is
// not accepted).
// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
// value in binary format, or produce an error.
// * Applications are allowed to cache lookup results based on the
@@ -118,6 +121,10 @@ type Any struct {
// on changes to types. (Use versioned type names to manage
// breaking changes.)
//
// Note: this functionality is not currently available in the official
// protobuf release, and it is not used for type URLs beginning with
// type.googleapis.com.
//
// Schemes other than `http`, `https` (or the empty scheme) might be
// used with implementation specific semantics.
//
@@ -133,17 +140,19 @@ func (m *Any) Reset() { *m = Any{} }
func (m *Any) String() string { return proto.CompactTextString(m) }
func (*Any) ProtoMessage() {}
func (*Any) Descriptor() ([]byte, []int) {
return fileDescriptor_any_744b9ca530f228db, []int{0}
return fileDescriptor_b53526c13ae22eb4, []int{0}
}
func (*Any) XXX_WellKnownType() string { return "Any" }
func (m *Any) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Any.Unmarshal(m, b)
}
func (m *Any) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Any.Marshal(b, m, deterministic)
}
func (dst *Any) XXX_Merge(src proto.Message) {
xxx_messageInfo_Any.Merge(dst, src)
func (m *Any) XXX_Merge(src proto.Message) {
xxx_messageInfo_Any.Merge(m, src)
}
func (m *Any) XXX_Size() int {
return xxx_messageInfo_Any.Size(m)
@@ -172,9 +181,9 @@ func init() {
proto.RegisterType((*Any)(nil), "google.protobuf.Any")
}
func init() { proto.RegisterFile("google/protobuf/any.proto", fileDescriptor_any_744b9ca530f228db) }
func init() { proto.RegisterFile("google/protobuf/any.proto", fileDescriptor_b53526c13ae22eb4) }
var fileDescriptor_any_744b9ca530f228db = []byte{
var fileDescriptor_b53526c13ae22eb4 = []byte{
// 185 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4c, 0xcf, 0xcf, 0x4f,
0xcf, 0x49, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x4f, 0xcc, 0xab, 0xd4,

View File

@@ -120,17 +120,18 @@ option objc_class_prefix = "GPB";
// }
//
message Any {
// A URL/resource name whose content describes the type of the
// serialized protocol buffer message.
// A URL/resource name that uniquely identifies the type of the serialized
// protocol buffer message. The last segment of the URL's path must represent
// the fully qualified name of the type (as in
// `path/google.protobuf.Duration`). The name should be in a canonical form
// (e.g., leading "." is not accepted).
//
// For URLs which use the scheme `http`, `https`, or no scheme, the
// following restrictions and interpretations apply:
// In practice, teams usually precompile into the binary all types that they
// expect it to use in the context of Any. However, for URLs which use the
// scheme `http`, `https`, or no scheme, one can optionally set up a type
// server that maps type URLs to message definitions as follows:
//
// * If no scheme is provided, `https` is assumed.
// * The last segment of the URL's path must represent the fully
// qualified name of the type (as in `path/google.protobuf.Duration`).
// The name should be in a canonical form (e.g., leading "." is
// not accepted).
// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
// value in binary format, or produce an error.
// * Applications are allowed to cache lookup results based on the
@@ -139,6 +140,10 @@ message Any {
// on changes to types. (Use versioned type names to manage
// breaking changes.)
//
// Note: this functionality is not currently available in the official
// protobuf release, and it is not used for type URLs beginning with
// type.googleapis.com.
//
// Schemes other than `http`, `https` (or the empty scheme) might be
// used with implementation specific semantics.
//

View File

@@ -82,7 +82,7 @@ func Duration(p *durpb.Duration) (time.Duration, error) {
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
}
if p.Nanos != 0 {
d += time.Duration(p.Nanos)
d += time.Duration(p.Nanos) * time.Nanosecond
if (d < 0) != (p.Nanos < 0) {
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
}

View File

@@ -1,11 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/duration.proto
package duration // import "github.com/golang/protobuf/ptypes/duration"
package duration
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -16,7 +18,7 @@ var _ = math.Inf
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// A Duration represents a signed, fixed-length span of time represented
// as a count of seconds and fractions of seconds at nanosecond
@@ -99,17 +101,19 @@ func (m *Duration) Reset() { *m = Duration{} }
func (m *Duration) String() string { return proto.CompactTextString(m) }
func (*Duration) ProtoMessage() {}
func (*Duration) Descriptor() ([]byte, []int) {
return fileDescriptor_duration_e7d612259e3f0613, []int{0}
return fileDescriptor_23597b2ebd7ac6c5, []int{0}
}
func (*Duration) XXX_WellKnownType() string { return "Duration" }
func (m *Duration) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Duration.Unmarshal(m, b)
}
func (m *Duration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Duration.Marshal(b, m, deterministic)
}
func (dst *Duration) XXX_Merge(src proto.Message) {
xxx_messageInfo_Duration.Merge(dst, src)
func (m *Duration) XXX_Merge(src proto.Message) {
xxx_messageInfo_Duration.Merge(m, src)
}
func (m *Duration) XXX_Size() int {
return xxx_messageInfo_Duration.Size(m)
@@ -138,11 +142,9 @@ func init() {
proto.RegisterType((*Duration)(nil), "google.protobuf.Duration")
}
func init() {
proto.RegisterFile("google/protobuf/duration.proto", fileDescriptor_duration_e7d612259e3f0613)
}
func init() { proto.RegisterFile("google/protobuf/duration.proto", fileDescriptor_23597b2ebd7ac6c5) }
var fileDescriptor_duration_e7d612259e3f0613 = []byte{
var fileDescriptor_23597b2ebd7ac6c5 = []byte{
// 190 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xcf, 0xcf, 0x4f,
0xcf, 0x49, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x4f, 0x29, 0x2d, 0x4a,

View File

@@ -1,11 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/struct.proto
package structpb // import "github.com/golang/protobuf/ptypes/struct"
package structpb
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -16,7 +18,7 @@ var _ = math.Inf
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// `NullValue` is a singleton enumeration to represent the null value for the
// `Value` type union.
@@ -32,6 +34,7 @@ const (
var NullValue_name = map[int32]string{
0: "NULL_VALUE",
}
var NullValue_value = map[string]int32{
"NULL_VALUE": 0,
}
@@ -39,9 +42,11 @@ var NullValue_value = map[string]int32{
func (x NullValue) String() string {
return proto.EnumName(NullValue_name, int32(x))
}
func (NullValue) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_struct_3a5a94e0c7801b27, []int{0}
return fileDescriptor_df322afd6c9fb402, []int{0}
}
func (NullValue) XXX_WellKnownType() string { return "NullValue" }
// `Struct` represents a structured data value, consisting of fields
@@ -64,17 +69,19 @@ func (m *Struct) Reset() { *m = Struct{} }
func (m *Struct) String() string { return proto.CompactTextString(m) }
func (*Struct) ProtoMessage() {}
func (*Struct) Descriptor() ([]byte, []int) {
return fileDescriptor_struct_3a5a94e0c7801b27, []int{0}
return fileDescriptor_df322afd6c9fb402, []int{0}
}
func (*Struct) XXX_WellKnownType() string { return "Struct" }
func (m *Struct) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Struct.Unmarshal(m, b)
}
func (m *Struct) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Struct.Marshal(b, m, deterministic)
}
func (dst *Struct) XXX_Merge(src proto.Message) {
xxx_messageInfo_Struct.Merge(dst, src)
func (m *Struct) XXX_Merge(src proto.Message) {
xxx_messageInfo_Struct.Merge(m, src)
}
func (m *Struct) XXX_Size() int {
return xxx_messageInfo_Struct.Size(m)
@@ -118,17 +125,19 @@ func (m *Value) Reset() { *m = Value{} }
func (m *Value) String() string { return proto.CompactTextString(m) }
func (*Value) ProtoMessage() {}
func (*Value) Descriptor() ([]byte, []int) {
return fileDescriptor_struct_3a5a94e0c7801b27, []int{1}
return fileDescriptor_df322afd6c9fb402, []int{1}
}
func (*Value) XXX_WellKnownType() string { return "Value" }
func (m *Value) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Value.Unmarshal(m, b)
}
func (m *Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Value.Marshal(b, m, deterministic)
}
func (dst *Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Value.Merge(dst, src)
func (m *Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Value.Merge(m, src)
}
func (m *Value) XXX_Size() int {
return xxx_messageInfo_Value.Size(m)
@@ -228,9 +237,9 @@ func (m *Value) GetListValue() *ListValue {
return nil
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*Value) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _Value_OneofMarshaler, _Value_OneofUnmarshaler, _Value_OneofSizer, []interface{}{
// XXX_OneofWrappers is for the internal use of the proto package.
func (*Value) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*Value_NullValue)(nil),
(*Value_NumberValue)(nil),
(*Value_StringValue)(nil),
@@ -240,129 +249,6 @@ func (*Value) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error,
}
}
func _Value_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*Value)
// kind
switch x := m.Kind.(type) {
case *Value_NullValue:
b.EncodeVarint(1<<3 | proto.WireVarint)
b.EncodeVarint(uint64(x.NullValue))
case *Value_NumberValue:
b.EncodeVarint(2<<3 | proto.WireFixed64)
b.EncodeFixed64(math.Float64bits(x.NumberValue))
case *Value_StringValue:
b.EncodeVarint(3<<3 | proto.WireBytes)
b.EncodeStringBytes(x.StringValue)
case *Value_BoolValue:
t := uint64(0)
if x.BoolValue {
t = 1
}
b.EncodeVarint(4<<3 | proto.WireVarint)
b.EncodeVarint(t)
case *Value_StructValue:
b.EncodeVarint(5<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.StructValue); err != nil {
return err
}
case *Value_ListValue:
b.EncodeVarint(6<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ListValue); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("Value.Kind has unexpected type %T", x)
}
return nil
}
func _Value_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*Value)
switch tag {
case 1: // kind.null_value
if wire != proto.WireVarint {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeVarint()
m.Kind = &Value_NullValue{NullValue(x)}
return true, err
case 2: // kind.number_value
if wire != proto.WireFixed64 {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeFixed64()
m.Kind = &Value_NumberValue{math.Float64frombits(x)}
return true, err
case 3: // kind.string_value
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeStringBytes()
m.Kind = &Value_StringValue{x}
return true, err
case 4: // kind.bool_value
if wire != proto.WireVarint {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeVarint()
m.Kind = &Value_BoolValue{x != 0}
return true, err
case 5: // kind.struct_value
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Struct)
err := b.DecodeMessage(msg)
m.Kind = &Value_StructValue{msg}
return true, err
case 6: // kind.list_value
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ListValue)
err := b.DecodeMessage(msg)
m.Kind = &Value_ListValue{msg}
return true, err
default:
return false, nil
}
}
func _Value_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Value)
// kind
switch x := m.Kind.(type) {
case *Value_NullValue:
n += 1 // tag and wire
n += proto.SizeVarint(uint64(x.NullValue))
case *Value_NumberValue:
n += 1 // tag and wire
n += 8
case *Value_StringValue:
n += 1 // tag and wire
n += proto.SizeVarint(uint64(len(x.StringValue)))
n += len(x.StringValue)
case *Value_BoolValue:
n += 1 // tag and wire
n += 1
case *Value_StructValue:
s := proto.Size(x.StructValue)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *Value_ListValue:
s := proto.Size(x.ListValue)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
// `ListValue` is a wrapper around a repeated field of values.
//
// The JSON representation for `ListValue` is JSON array.
@@ -378,17 +264,19 @@ func (m *ListValue) Reset() { *m = ListValue{} }
func (m *ListValue) String() string { return proto.CompactTextString(m) }
func (*ListValue) ProtoMessage() {}
func (*ListValue) Descriptor() ([]byte, []int) {
return fileDescriptor_struct_3a5a94e0c7801b27, []int{2}
return fileDescriptor_df322afd6c9fb402, []int{2}
}
func (*ListValue) XXX_WellKnownType() string { return "ListValue" }
func (m *ListValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ListValue.Unmarshal(m, b)
}
func (m *ListValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ListValue.Marshal(b, m, deterministic)
}
func (dst *ListValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_ListValue.Merge(dst, src)
func (m *ListValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_ListValue.Merge(m, src)
}
func (m *ListValue) XXX_Size() int {
return xxx_messageInfo_ListValue.Size(m)
@@ -407,18 +295,16 @@ func (m *ListValue) GetValues() []*Value {
}
func init() {
proto.RegisterEnum("google.protobuf.NullValue", NullValue_name, NullValue_value)
proto.RegisterType((*Struct)(nil), "google.protobuf.Struct")
proto.RegisterMapType((map[string]*Value)(nil), "google.protobuf.Struct.FieldsEntry")
proto.RegisterType((*Value)(nil), "google.protobuf.Value")
proto.RegisterType((*ListValue)(nil), "google.protobuf.ListValue")
proto.RegisterEnum("google.protobuf.NullValue", NullValue_name, NullValue_value)
}
func init() {
proto.RegisterFile("google/protobuf/struct.proto", fileDescriptor_struct_3a5a94e0c7801b27)
}
func init() { proto.RegisterFile("google/protobuf/struct.proto", fileDescriptor_df322afd6c9fb402) }
var fileDescriptor_struct_3a5a94e0c7801b27 = []byte{
var fileDescriptor_df322afd6c9fb402 = []byte{
// 417 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x8b, 0xd3, 0x40,
0x14, 0xc7, 0x3b, 0xc9, 0x36, 0x98, 0x17, 0x59, 0x97, 0x11, 0xb4, 0xac, 0xa2, 0xa1, 0x7b, 0x09,

View File

@@ -111,11 +111,9 @@ func TimestampNow() *tspb.Timestamp {
// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
// It returns an error if the resulting Timestamp is invalid.
func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
seconds := t.Unix()
nanos := int32(t.Sub(time.Unix(seconds, 0)))
ts := &tspb.Timestamp{
Seconds: seconds,
Nanos: nanos,
Seconds: t.Unix(),
Nanos: int32(t.Nanosecond()),
}
if err := validateTimestamp(ts); err != nil {
return nil, err

View File

@@ -1,11 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/timestamp.proto
package timestamp // import "github.com/golang/protobuf/ptypes/timestamp"
package timestamp
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -16,7 +18,7 @@ var _ = math.Inf
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// A Timestamp represents a point in time independent of any time zone
// or calendar, represented as seconds and fractions of seconds at
@@ -81,7 +83,9 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
// is required, though only UTC (as indicated by "Z") is presently supported.
// is required. A proto3 JSON serializer should always use UTC (as indicated by
// "Z") when printing the Timestamp type and a proto3 JSON parser should be
// able to accept both UTC and other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
// 01:30 UTC on January 15, 2017.
@@ -92,8 +96,8 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
// can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--)
// to obtain a formatter capable of generating timestamps in this format.
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
// ) to obtain a formatter capable of generating timestamps in this format.
//
//
type Timestamp struct {
@@ -115,17 +119,19 @@ func (m *Timestamp) Reset() { *m = Timestamp{} }
func (m *Timestamp) String() string { return proto.CompactTextString(m) }
func (*Timestamp) ProtoMessage() {}
func (*Timestamp) Descriptor() ([]byte, []int) {
return fileDescriptor_timestamp_b826e8e5fba671a8, []int{0}
return fileDescriptor_292007bbfe81227e, []int{0}
}
func (*Timestamp) XXX_WellKnownType() string { return "Timestamp" }
func (m *Timestamp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Timestamp.Unmarshal(m, b)
}
func (m *Timestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Timestamp.Marshal(b, m, deterministic)
}
func (dst *Timestamp) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timestamp.Merge(dst, src)
func (m *Timestamp) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timestamp.Merge(m, src)
}
func (m *Timestamp) XXX_Size() int {
return xxx_messageInfo_Timestamp.Size(m)
@@ -154,11 +160,9 @@ func init() {
proto.RegisterType((*Timestamp)(nil), "google.protobuf.Timestamp")
}
func init() {
proto.RegisterFile("google/protobuf/timestamp.proto", fileDescriptor_timestamp_b826e8e5fba671a8)
}
func init() { proto.RegisterFile("google/protobuf/timestamp.proto", fileDescriptor_292007bbfe81227e) }
var fileDescriptor_timestamp_b826e8e5fba671a8 = []byte{
var fileDescriptor_292007bbfe81227e = []byte{
// 191 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xcf, 0xcf, 0x4f,
0xcf, 0x49, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x2f, 0xc9, 0xcc, 0x4d,

View File

@@ -103,7 +103,9 @@ option objc_class_prefix = "GPB";
// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
// is required, though only UTC (as indicated by "Z") is presently supported.
// is required. A proto3 JSON serializer should always use UTC (as indicated by
// "Z") when printing the Timestamp type and a proto3 JSON parser should be
// able to accept both UTC and other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
// 01:30 UTC on January 15, 2017.
@@ -114,8 +116,8 @@ option objc_class_prefix = "GPB";
// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
// can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--)
// to obtain a formatter capable of generating timestamps in this format.
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
// ) to obtain a formatter capable of generating timestamps in this format.
//
//
message Timestamp {

View File

@@ -1,11 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/wrappers.proto
package wrappers // import "github.com/golang/protobuf/ptypes/wrappers"
package wrappers
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -16,7 +18,7 @@ var _ = math.Inf
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Wrapper message for `double`.
//
@@ -33,17 +35,19 @@ func (m *DoubleValue) Reset() { *m = DoubleValue{} }
func (m *DoubleValue) String() string { return proto.CompactTextString(m) }
func (*DoubleValue) ProtoMessage() {}
func (*DoubleValue) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{0}
return fileDescriptor_5377b62bda767935, []int{0}
}
func (*DoubleValue) XXX_WellKnownType() string { return "DoubleValue" }
func (m *DoubleValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_DoubleValue.Unmarshal(m, b)
}
func (m *DoubleValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_DoubleValue.Marshal(b, m, deterministic)
}
func (dst *DoubleValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_DoubleValue.Merge(dst, src)
func (m *DoubleValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_DoubleValue.Merge(m, src)
}
func (m *DoubleValue) XXX_Size() int {
return xxx_messageInfo_DoubleValue.Size(m)
@@ -76,17 +80,19 @@ func (m *FloatValue) Reset() { *m = FloatValue{} }
func (m *FloatValue) String() string { return proto.CompactTextString(m) }
func (*FloatValue) ProtoMessage() {}
func (*FloatValue) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{1}
return fileDescriptor_5377b62bda767935, []int{1}
}
func (*FloatValue) XXX_WellKnownType() string { return "FloatValue" }
func (m *FloatValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_FloatValue.Unmarshal(m, b)
}
func (m *FloatValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_FloatValue.Marshal(b, m, deterministic)
}
func (dst *FloatValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_FloatValue.Merge(dst, src)
func (m *FloatValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_FloatValue.Merge(m, src)
}
func (m *FloatValue) XXX_Size() int {
return xxx_messageInfo_FloatValue.Size(m)
@@ -119,17 +125,19 @@ func (m *Int64Value) Reset() { *m = Int64Value{} }
func (m *Int64Value) String() string { return proto.CompactTextString(m) }
func (*Int64Value) ProtoMessage() {}
func (*Int64Value) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{2}
return fileDescriptor_5377b62bda767935, []int{2}
}
func (*Int64Value) XXX_WellKnownType() string { return "Int64Value" }
func (m *Int64Value) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Int64Value.Unmarshal(m, b)
}
func (m *Int64Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Int64Value.Marshal(b, m, deterministic)
}
func (dst *Int64Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Int64Value.Merge(dst, src)
func (m *Int64Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Int64Value.Merge(m, src)
}
func (m *Int64Value) XXX_Size() int {
return xxx_messageInfo_Int64Value.Size(m)
@@ -162,17 +170,19 @@ func (m *UInt64Value) Reset() { *m = UInt64Value{} }
func (m *UInt64Value) String() string { return proto.CompactTextString(m) }
func (*UInt64Value) ProtoMessage() {}
func (*UInt64Value) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{3}
return fileDescriptor_5377b62bda767935, []int{3}
}
func (*UInt64Value) XXX_WellKnownType() string { return "UInt64Value" }
func (m *UInt64Value) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UInt64Value.Unmarshal(m, b)
}
func (m *UInt64Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UInt64Value.Marshal(b, m, deterministic)
}
func (dst *UInt64Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_UInt64Value.Merge(dst, src)
func (m *UInt64Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_UInt64Value.Merge(m, src)
}
func (m *UInt64Value) XXX_Size() int {
return xxx_messageInfo_UInt64Value.Size(m)
@@ -205,17 +215,19 @@ func (m *Int32Value) Reset() { *m = Int32Value{} }
func (m *Int32Value) String() string { return proto.CompactTextString(m) }
func (*Int32Value) ProtoMessage() {}
func (*Int32Value) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{4}
return fileDescriptor_5377b62bda767935, []int{4}
}
func (*Int32Value) XXX_WellKnownType() string { return "Int32Value" }
func (m *Int32Value) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Int32Value.Unmarshal(m, b)
}
func (m *Int32Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Int32Value.Marshal(b, m, deterministic)
}
func (dst *Int32Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Int32Value.Merge(dst, src)
func (m *Int32Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_Int32Value.Merge(m, src)
}
func (m *Int32Value) XXX_Size() int {
return xxx_messageInfo_Int32Value.Size(m)
@@ -248,17 +260,19 @@ func (m *UInt32Value) Reset() { *m = UInt32Value{} }
func (m *UInt32Value) String() string { return proto.CompactTextString(m) }
func (*UInt32Value) ProtoMessage() {}
func (*UInt32Value) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{5}
return fileDescriptor_5377b62bda767935, []int{5}
}
func (*UInt32Value) XXX_WellKnownType() string { return "UInt32Value" }
func (m *UInt32Value) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UInt32Value.Unmarshal(m, b)
}
func (m *UInt32Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UInt32Value.Marshal(b, m, deterministic)
}
func (dst *UInt32Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_UInt32Value.Merge(dst, src)
func (m *UInt32Value) XXX_Merge(src proto.Message) {
xxx_messageInfo_UInt32Value.Merge(m, src)
}
func (m *UInt32Value) XXX_Size() int {
return xxx_messageInfo_UInt32Value.Size(m)
@@ -291,17 +305,19 @@ func (m *BoolValue) Reset() { *m = BoolValue{} }
func (m *BoolValue) String() string { return proto.CompactTextString(m) }
func (*BoolValue) ProtoMessage() {}
func (*BoolValue) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{6}
return fileDescriptor_5377b62bda767935, []int{6}
}
func (*BoolValue) XXX_WellKnownType() string { return "BoolValue" }
func (m *BoolValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_BoolValue.Unmarshal(m, b)
}
func (m *BoolValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_BoolValue.Marshal(b, m, deterministic)
}
func (dst *BoolValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_BoolValue.Merge(dst, src)
func (m *BoolValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_BoolValue.Merge(m, src)
}
func (m *BoolValue) XXX_Size() int {
return xxx_messageInfo_BoolValue.Size(m)
@@ -334,17 +350,19 @@ func (m *StringValue) Reset() { *m = StringValue{} }
func (m *StringValue) String() string { return proto.CompactTextString(m) }
func (*StringValue) ProtoMessage() {}
func (*StringValue) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{7}
return fileDescriptor_5377b62bda767935, []int{7}
}
func (*StringValue) XXX_WellKnownType() string { return "StringValue" }
func (m *StringValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_StringValue.Unmarshal(m, b)
}
func (m *StringValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_StringValue.Marshal(b, m, deterministic)
}
func (dst *StringValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_StringValue.Merge(dst, src)
func (m *StringValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_StringValue.Merge(m, src)
}
func (m *StringValue) XXX_Size() int {
return xxx_messageInfo_StringValue.Size(m)
@@ -377,17 +395,19 @@ func (m *BytesValue) Reset() { *m = BytesValue{} }
func (m *BytesValue) String() string { return proto.CompactTextString(m) }
func (*BytesValue) ProtoMessage() {}
func (*BytesValue) Descriptor() ([]byte, []int) {
return fileDescriptor_wrappers_16c7c35c009f3253, []int{8}
return fileDescriptor_5377b62bda767935, []int{8}
}
func (*BytesValue) XXX_WellKnownType() string { return "BytesValue" }
func (m *BytesValue) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_BytesValue.Unmarshal(m, b)
}
func (m *BytesValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_BytesValue.Marshal(b, m, deterministic)
}
func (dst *BytesValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_BytesValue.Merge(dst, src)
func (m *BytesValue) XXX_Merge(src proto.Message) {
xxx_messageInfo_BytesValue.Merge(m, src)
}
func (m *BytesValue) XXX_Size() int {
return xxx_messageInfo_BytesValue.Size(m)
@@ -417,11 +437,9 @@ func init() {
proto.RegisterType((*BytesValue)(nil), "google.protobuf.BytesValue")
}
func init() {
proto.RegisterFile("google/protobuf/wrappers.proto", fileDescriptor_wrappers_16c7c35c009f3253)
}
func init() { proto.RegisterFile("google/protobuf/wrappers.proto", fileDescriptor_5377b62bda767935) }
var fileDescriptor_wrappers_16c7c35c009f3253 = []byte{
var fileDescriptor_5377b62bda767935 = []byte{
// 259 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xcf, 0xcf, 0x4f,
0xcf, 0x49, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x2f, 0x2f, 0x4a, 0x2c,