code
stringlengths
12
335k
docstring
stringlengths
20
20.8k
func_name
stringlengths
1
105
language
stringclasses
1 value
repo
stringclasses
498 values
path
stringlengths
5
172
url
stringlengths
43
235
license
stringclasses
4 values
func Merge(dst, src Message) { if m, ok := dst.(Merger); ok { m.Merge(src) return } in := reflect.ValueOf(src) out := reflect.ValueOf(dst) if out.IsNil() { panic("proto: nil destination") } if in.Type() != out.Type() { panic(fmt.Sprintf("proto.Merge(%T, %T) type mismatch", dst, src)) } if in.IsNil() { return // Merge from nil src is a noop } if m, ok := dst.(generatedMerger); ok { m.XXX_Merge(src) return } mergeStruct(out.Elem(), in.Elem()) }
Merge merges src into dst. Required and optional fields that are set in src will be set to that value in dst. Elements of repeated fields will be appended. Merge panics if src and dst are not the same type, or if dst is nil.
Merge
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/clone.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/clone.go
Apache-2.0
func mergeAny(out, in reflect.Value, viaPtr bool, prop *Properties) { if in.Type() == protoMessageType { if !in.IsNil() { if out.IsNil() { out.Set(reflect.ValueOf(Clone(in.Interface().(Message)))) } else { Merge(out.Interface().(Message), in.Interface().(Message)) } } return } switch in.Kind() { case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, reflect.String, reflect.Uint32, reflect.Uint64: if !viaPtr && isProto3Zero(in) { return } out.Set(in) case reflect.Interface: // Probably a oneof field; copy non-nil values. if in.IsNil() { return } // Allocate destination if it is not set, or set to a different type. // Otherwise we will merge as normal. if out.IsNil() || out.Elem().Type() != in.Elem().Type() { out.Set(reflect.New(in.Elem().Elem().Type())) // interface -> *T -> T -> new(T) } mergeAny(out.Elem(), in.Elem(), false, nil) case reflect.Map: if in.Len() == 0 { return } if out.IsNil() { out.Set(reflect.MakeMap(in.Type())) } // For maps with value types of *T or []byte we need to deep copy each value. elemKind := in.Type().Elem().Kind() for _, key := range in.MapKeys() { var val reflect.Value switch elemKind { case reflect.Ptr: val = reflect.New(in.Type().Elem().Elem()) mergeAny(val, in.MapIndex(key), false, nil) case reflect.Slice: val = in.MapIndex(key) val = reflect.ValueOf(append([]byte{}, val.Bytes()...)) default: val = in.MapIndex(key) } out.SetMapIndex(key, val) } case reflect.Ptr: if in.IsNil() { return } if out.IsNil() { out.Set(reflect.New(in.Elem().Type())) } mergeAny(out.Elem(), in.Elem(), true, nil) case reflect.Slice: if in.IsNil() { return } if in.Type().Elem().Kind() == reflect.Uint8 { // []byte is a scalar bytes field, not a repeated field. // Edge case: if this is in a proto3 message, a zero length // bytes field is considered the zero value, and should not // be merged. if prop != nil && prop.proto3 && in.Len() == 0 { return } // Make a deep copy. // Append to []byte{} instead of []byte(nil) so that we never end up // with a nil result. out.SetBytes(append([]byte{}, in.Bytes()...)) return } n := in.Len() if out.IsNil() { out.Set(reflect.MakeSlice(in.Type(), 0, n)) } switch in.Type().Elem().Kind() { case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, reflect.String, reflect.Uint32, reflect.Uint64: out.Set(reflect.AppendSlice(out, in)) default: for i := 0; i < n; i++ { x := reflect.Indirect(reflect.New(in.Type().Elem())) mergeAny(x, in.Index(i), false, nil) out.Set(reflect.Append(out, x)) } } case reflect.Struct: mergeStruct(out, in) default: // unknown type, so not a protocol buffer log.Printf("proto: don't know how to copy %v", in) } }
mergeAny performs a merge between two values of the same type. viaPtr indicates whether the values were indirected through a pointer (implying proto2). prop is set if this is a struct field (it may be nil).
mergeAny
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/clone.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/clone.go
Apache-2.0
func unmarshalMessageSet(buf []byte, exts interface{}) error { var m map[int32]Extension switch exts := exts.(type) { case *XXX_InternalExtensions: m = exts.extensionsWrite() case map[int32]Extension: m = exts default: return errors.New("proto: not an extension map") }
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.
unmarshalMessageSet
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/message_set.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/message_set.go
Apache-2.0
func (p *Properties) String() string { s := p.Wire s += "," s += strconv.Itoa(p.Tag) if p.Required { s += ",req" } if p.Optional { s += ",opt" } if p.Repeated { s += ",rep" } if p.Packed { s += ",packed" } s += ",name=" + p.OrigName if p.JSONName != p.OrigName { s += ",json=" + p.JSONName } if p.proto3 { s += ",proto3" } if p.oneof { s += ",oneof" } if len(p.Enum) > 0 { s += ",enum=" + p.Enum } if p.HasDefault { s += ",def=" + p.Default } return s }
String formats the properties in the protobuf struct field tag style.
String
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func (p *Properties) Parse(s string) { // "bytes,49,opt,name=foo,def=hello!" fields := strings.Split(s, ",") // breaks def=, but handled below. if len(fields) < 2 { log.Printf("proto: tag has too few fields: %q", s) return } p.Wire = fields[0] switch p.Wire { case "varint": p.WireType = WireVarint case "fixed32": p.WireType = WireFixed32 case "fixed64": p.WireType = WireFixed64 case "zigzag32": p.WireType = WireVarint case "zigzag64": p.WireType = WireVarint case "bytes", "group": p.WireType = WireBytes // no numeric converter for non-numeric types default: log.Printf("proto: tag has unknown wire type: %q", s) return } var err error p.Tag, err = strconv.Atoi(fields[1]) if err != nil { return } outer: for i := 2; i < len(fields); i++ { f := fields[i] switch { case f == "req": p.Required = true case f == "opt": p.Optional = true case f == "rep": p.Repeated = true case f == "packed": p.Packed = true case strings.HasPrefix(f, "name="): p.OrigName = f[5:] case strings.HasPrefix(f, "json="): p.JSONName = f[5:] case strings.HasPrefix(f, "enum="): p.Enum = f[5:] case f == "proto3": p.proto3 = true case f == "oneof": p.oneof = true case strings.HasPrefix(f, "def="): p.HasDefault = true p.Default = f[4:] // rest of string if i+1 < len(fields) { // Commas aren't escaped, and def is always last. p.Default += "," + strings.Join(fields[i+1:], ",") break outer } case strings.HasPrefix(f, "embedded="): p.OrigName = strings.Split(f, "=")[1] case strings.HasPrefix(f, "customtype="): p.CustomType = strings.Split(f, "=")[1] case strings.HasPrefix(f, "casttype="): p.CastType = strings.Split(f, "=")[1] case f == "stdtime": p.StdTime = true case f == "stdduration": p.StdDuration = true case f == "wktptr": p.WktPointer = true } } }
Parse populates p by parsing a string in the protobuf struct field tag style.
Parse
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, lockGetProp bool) { isMap := typ.Kind() == reflect.Map if len(p.CustomType) > 0 && !isMap { p.ctype = typ p.setTag(lockGetProp) return } if p.StdTime && !isMap { p.setTag(lockGetProp) return } if p.StdDuration && !isMap { p.setTag(lockGetProp) return } if p.WktPointer && !isMap { p.setTag(lockGetProp) return } switch t1 := typ; t1.Kind() { case reflect.Struct: p.stype = typ case reflect.Ptr: if t1.Elem().Kind() == reflect.Struct { p.stype = t1.Elem() } case reflect.Slice: switch t2 := t1.Elem(); t2.Kind() { case reflect.Ptr: switch t3 := t2.Elem(); t3.Kind() { case reflect.Struct: p.stype = t3 } case reflect.Struct: p.stype = t2 } case reflect.Map: p.mtype = t1 p.MapKeyProp = &Properties{} p.MapKeyProp.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp) p.MapValProp = &Properties{} vtype := p.mtype.Elem() if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice { // The value type is not a message (*T) or bytes ([]byte), // so we need encoders for the pointer to this type. vtype = reflect.PtrTo(vtype) } p.MapValProp.CustomType = p.CustomType p.MapValProp.StdDuration = p.StdDuration p.MapValProp.StdTime = p.StdTime p.MapValProp.WktPointer = p.WktPointer p.MapValProp.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp) } p.setTag(lockGetProp) }
setFieldProps initializes the field properties for submessages and maps.
setFieldProps
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) { p.init(typ, name, tag, f, true) }
Init populates the properties from a protocol buffer struct tag.
Init
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func GetProperties(t reflect.Type) *StructProperties { if t.Kind() != reflect.Struct { panic("proto: type must have kind struct") } // Most calls to GetProperties in a long-running program will be // retrieving details for types we have seen before. propertiesMu.RLock() sprop, ok := propertiesMap[t] propertiesMu.RUnlock() if ok { return sprop } propertiesMu.Lock() sprop = getPropertiesLocked(t) propertiesMu.Unlock() return sprop }
GetProperties returns the list of properties for the type represented by t. t must represent a generated struct type of a protocol message.
GetProperties
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[string]int32) { if _, ok := enumValueMaps[typeName]; ok { panic("proto: duplicate enum registered: " + typeName) } enumValueMaps[typeName] = valueMap if _, ok := enumStringMaps[typeName]; ok { panic("proto: duplicate enum registered: " + typeName) } enumStringMaps[typeName] = unusedNameMap }
RegisterEnum is called from the generated code to install the enum descriptor maps into the global table to aid parsing text format protocol buffers.
RegisterEnum
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func EnumValueMap(enumType string) map[string]int32 { return enumValueMaps[enumType] }
EnumValueMap returns the mapping from names to integers of the enum type enumType, or a nil if not found.
EnumValueMap
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func RegisterType(x Message, name string) { if _, ok := protoTypedNils[name]; ok { // TODO: Some day, make this a panic. log.Printf("proto: duplicate proto type registered: %s", name) return } t := reflect.TypeOf(x) if v := reflect.ValueOf(x); v.Kind() == reflect.Ptr && v.Pointer() == 0 { // Generated code always calls RegisterType with nil x. // This check is just for extra safety. protoTypedNils[name] = x } else { protoTypedNils[name] = reflect.Zero(t).Interface().(Message) } revProtoTypes[t] = name }
RegisterType is called from generated code and maps from the fully qualified proto name to the type (pointer to struct) of the protocol buffer.
RegisterType
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func RegisterMapType(x interface{}, name string) { if reflect.TypeOf(x).Kind() != reflect.Map { panic(fmt.Sprintf("RegisterMapType(%T, %q); want map", x, name)) } if _, ok := protoMapTypes[name]; ok { log.Printf("proto: duplicate proto type registered: %s", name) return } t := reflect.TypeOf(x) protoMapTypes[name] = t revProtoTypes[t] = name }
RegisterMapType is called from generated code and maps from the fully qualified proto name to the native map type of the proto map definition.
RegisterMapType
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func MessageName(x Message) string { type xname interface { XXX_MessageName() string } if m, ok := x.(xname); ok { return m.XXX_MessageName() } return revProtoTypes[reflect.TypeOf(x)] }
MessageName returns the fully-qualified proto name for the given message type.
MessageName
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func MessageType(name string) reflect.Type { if t, ok := protoTypedNils[name]; ok { return reflect.TypeOf(t) } return protoMapTypes[name] }
MessageType returns the message type (pointer to struct) for a named message. The type is not guaranteed to implement proto.Message if the name refers to a map entry.
MessageType
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func RegisterFile(filename string, fileDescriptor []byte) { protoFiles[filename] = fileDescriptor }
RegisterFile is called from generated code and maps from the full file name of a .proto file to its compressed FileDescriptorProto.
RegisterFile
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func FileDescriptor(filename string) []byte { return protoFiles[filename] }
FileDescriptor returns the compressed FileDescriptorProto for a .proto file.
FileDescriptor
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/properties.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/properties.go
Apache-2.0
func (a *InternalMessageInfo) Merge(dst, src Message) { mi := atomicLoadMergeInfo(&a.merge) if mi == nil { mi = getMergeInfo(reflect.TypeOf(dst).Elem()) atomicStoreMergeInfo(&a.merge, mi) } mi.merge(toPointer(&dst), toPointer(&src)) }
Merge merges the src message into dst. This assumes that dst and src of the same type and are non-nil.
Merge
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_merge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_merge.go
Apache-2.0
func (mi *mergeInfo) merge(dst, src pointer) { if dst.isNil() { panic("proto: nil destination") } if src.isNil() { return // Nothing to do. } if atomic.LoadInt32(&mi.initialized) == 0 { mi.computeMergeInfo() } for _, fi := range mi.fields { sfp := src.offset(fi.field) // As an optimization, we can avoid the merge function call cost // if we know for sure that the source will have no effect // by checking if it is the zero value. if unsafeAllowed { if fi.isPointer && sfp.getPointer().isNil() { // Could be slice or string continue } if fi.basicWidth > 0 { switch { case fi.basicWidth == 1 && !*sfp.toBool(): continue case fi.basicWidth == 4 && *sfp.toUint32() == 0: continue case fi.basicWidth == 8 && *sfp.toUint64() == 0: continue } } } dfp := dst.offset(fi.field) fi.merge(dfp, sfp) } // TODO: Make this faster? out := dst.asPointerTo(mi.typ).Elem() in := src.asPointerTo(mi.typ).Elem() if emIn, err := extendable(in.Addr().Interface()); err == nil { emOut, _ := extendable(out.Addr().Interface()) mIn, muIn := emIn.extensionsRead() if mIn != nil { mOut := emOut.extensionsWrite() muIn.Lock() mergeExtension(mOut, mIn) muIn.Unlock() } } if mi.unrecognized.IsValid() { if b := *src.offset(mi.unrecognized).toBytes(); len(b) > 0 { *dst.offset(mi.unrecognized).toBytes() = append([]byte(nil), b...) } } }
merge merges src into dst assuming they are both of type *mi.typ.
merge
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_merge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_merge.go
Apache-2.0
func EncodeVarint(x uint64) []byte { var buf [maxVarintBytes]byte var n int for n = 0; x > 127; n++ { buf[n] = 0x80 | uint8(x&0x7F) x >>= 7 } buf[n] = uint8(x) n++ return buf[0:n] }
EncodeVarint returns the varint encoding of x. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types. Not used by the package itself, but helpful to clients wishing to use the same encoding.
EncodeVarint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeVarint(x uint64) error { for x >= 1<<7 { p.buf = append(p.buf, uint8(x&0x7f|0x80)) x >>= 7 } p.buf = append(p.buf, uint8(x)) return nil }
EncodeVarint writes a varint-encoded integer to the Buffer. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types.
EncodeVarint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func SizeVarint(x uint64) int { switch { case x < 1<<7: return 1 case x < 1<<14: return 2 case x < 1<<21: return 3 case x < 1<<28: return 4 case x < 1<<35: return 5 case x < 1<<42: return 6 case x < 1<<49: return 7 case x < 1<<56: return 8 case x < 1<<63: return 9 } return 10 }
SizeVarint returns the varint encoding size of an integer.
SizeVarint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeFixed64(x uint64) error { p.buf = append(p.buf, uint8(x), uint8(x>>8), uint8(x>>16), uint8(x>>24), uint8(x>>32), uint8(x>>40), uint8(x>>48), uint8(x>>56)) return nil }
EncodeFixed64 writes a 64-bit integer to the Buffer. This is the format for the fixed64, sfixed64, and double protocol buffer types.
EncodeFixed64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeFixed32(x uint64) error { p.buf = append(p.buf, uint8(x), uint8(x>>8), uint8(x>>16), uint8(x>>24)) return nil }
EncodeFixed32 writes a 32-bit integer to the Buffer. This is the format for the fixed32, sfixed32, and float protocol buffer types.
EncodeFixed32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeZigzag64(x uint64) error { // use signed number to get arithmetic right shift. return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) }
EncodeZigzag64 writes a zigzag-encoded 64-bit integer to the Buffer. This is the format used for the sint64 protocol buffer type.
EncodeZigzag64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeZigzag32(x uint64) error { // use signed number to get arithmetic right shift. return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31)))) }
EncodeZigzag32 writes a zigzag-encoded 32-bit integer to the Buffer. This is the format used for the sint32 protocol buffer type.
EncodeZigzag32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeRawBytes(b []byte) error { p.EncodeVarint(uint64(len(b))) p.buf = append(p.buf, b...) return nil }
EncodeRawBytes writes a count-delimited byte buffer to the Buffer. This is the format used for the bytes protocol buffer type and for embedded messages.
EncodeRawBytes
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeStringBytes(s string) error { p.EncodeVarint(uint64(len(s))) p.buf = append(p.buf, s...) return nil }
EncodeStringBytes writes an encoded string to the Buffer. This is the format used for the proto2 string type.
EncodeStringBytes
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func (p *Buffer) EncodeMessage(pb Message) error { siz := Size(pb) sizVar := SizeVarint(uint64(siz)) p.grow(siz + sizVar) p.EncodeVarint(uint64(siz)) return p.Marshal(pb) }
EncodeMessage writes the protocol buffer to the Buffer, prefixed by a varint-encoded length.
EncodeMessage
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func isNil(v reflect.Value) bool { switch v.Kind() { case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: return v.IsNil() } return false }
All protocol buffer fields are nillable, but be careful.
isNil
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/encode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/encode.go
Apache-2.0
func getMarshalInfo(t reflect.Type) *marshalInfo { marshalInfoLock.Lock() u, ok := marshalInfoMap[t] if !ok { u = &marshalInfo{typ: t} marshalInfoMap[t] = u } marshalInfoLock.Unlock() return u }
getMarshalInfo returns the information to marshal a given type of message. The info it returns may not necessarily initialized. t is the type of the message (NOT the pointer to it).
getMarshalInfo
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (a *InternalMessageInfo) Size(msg Message) int { u := getMessageMarshalInfo(msg, a) ptr := toPointer(&msg) if ptr.isNil() { // We get here if msg is a typed nil ((*SomeMessage)(nil)), // so it satisfies the interface, and msg == nil wouldn't // catch it. We don't want crash in this case. return 0 } return u.size(ptr) }
Size is the entry point from generated code, and should be ONLY called by generated code. It computes the size of encoded data of msg. a is a pointer to a place to store cached marshal info.
Size
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (a *InternalMessageInfo) Marshal(b []byte, msg Message, deterministic bool) ([]byte, error) { u := getMessageMarshalInfo(msg, a) ptr := toPointer(&msg) if ptr.isNil() { // We get here if msg is a typed nil ((*SomeMessage)(nil)), // so it satisfies the interface, and msg == nil wouldn't // catch it. We don't want crash in this case. return b, ErrNil } return u.marshal(b, ptr, deterministic) }
Marshal is the entry point from generated code, and should be ONLY called by generated code. It marshals msg to the end of b. a is a pointer to a place to store cached marshal info.
Marshal
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (u *marshalInfo) size(ptr pointer) int { if atomic.LoadInt32(&u.initialized) == 0 { u.computeMarshalInfo() } // If the message can marshal itself, let it do it, for compatibility. // NOTE: This is not efficient. if u.hasmarshaler { // Uses the message's Size method if available if u.hassizer { s := ptr.asPointerTo(u.typ).Interface().(Sizer) return s.Size() } // Uses the message's ProtoSize method if available if u.hasprotosizer { s := ptr.asPointerTo(u.typ).Interface().(ProtoSizer) return s.ProtoSize() } m := ptr.asPointerTo(u.typ).Interface().(Marshaler) b, _ := m.Marshal() return len(b) } n := 0 for _, f := range u.fields { if f.isPointer && ptr.offset(f.field).getPointer().isNil() { // nil pointer always marshals to nothing continue } n += f.sizer(ptr.offset(f.field), f.tagsize) } if u.extensions.IsValid() { e := ptr.offset(u.extensions).toExtensions() if u.messageset { n += u.sizeMessageSet(e) } else { n += u.sizeExtensions(e) } } if u.v1extensions.IsValid() { m := *ptr.offset(u.v1extensions).toOldExtensions() n += u.sizeV1Extensions(m) } if u.bytesExtensions.IsValid() { s := *ptr.offset(u.bytesExtensions).toBytes() n += len(s) } if u.unrecognized.IsValid() { s := *ptr.offset(u.unrecognized).toBytes() n += len(s) } // cache the result for use in marshal if u.sizecache.IsValid() { atomic.StoreInt32(ptr.offset(u.sizecache).toInt32(), int32(n)) } return n }
size is the main function to compute the size of the encoded data of a message. ptr is the pointer to the message.
size
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (u *marshalInfo) cachedsize(ptr pointer) int { if u.sizecache.IsValid() { return int(atomic.LoadInt32(ptr.offset(u.sizecache).toInt32())) } return u.size(ptr) }
cachedsize gets the size from cache. If there is no cache (i.e. message is not generated), fall back to compute the size.
cachedsize
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (u *marshalInfo) marshal(b []byte, ptr pointer, deterministic bool) ([]byte, error) { if atomic.LoadInt32(&u.initialized) == 0 { u.computeMarshalInfo() } // If the message can marshal itself, let it do it, for compatibility. // NOTE: This is not efficient. if u.hasmarshaler { m := ptr.asPointerTo(u.typ).Interface().(Marshaler) b1, err := m.Marshal() b = append(b, b1...) return b, err } var err, errLater error // The old marshaler encodes extensions at beginning. if u.extensions.IsValid() { e := ptr.offset(u.extensions).toExtensions() if u.messageset { b, err = u.appendMessageSet(b, e, deterministic) } else { b, err = u.appendExtensions(b, e, deterministic) } if err != nil { return b, err } } if u.v1extensions.IsValid() { m := *ptr.offset(u.v1extensions).toOldExtensions() b, err = u.appendV1Extensions(b, m, deterministic) if err != nil { return b, err } } if u.bytesExtensions.IsValid() { s := *ptr.offset(u.bytesExtensions).toBytes() b = append(b, s...) } for _, f := range u.fields { if f.required { if f.isPointer && ptr.offset(f.field).getPointer().isNil() { // Required field is not set. // We record the error but keep going, to give a complete marshaling. if errLater == nil { errLater = &RequiredNotSetError{f.name} } continue } } if f.isPointer && ptr.offset(f.field).getPointer().isNil() { // nil pointer always marshals to nothing continue } b, err = f.marshaler(b, ptr.offset(f.field), f.wiretag, deterministic) if err != nil { if err1, ok := err.(*RequiredNotSetError); ok { // Required field in submessage is not set. // We record the error but keep going, to give a complete marshaling. if errLater == nil { errLater = &RequiredNotSetError{f.name + "." + err1.field} } continue } if err == errRepeatedHasNil { err = errors.New("proto: repeated field " + f.name + " has nil element") } if err == errInvalidUTF8 { if errLater == nil { fullName := revProtoTypes[reflect.PtrTo(u.typ)] + "." + f.name errLater = &invalidUTF8Error{fullName} } continue } return b, err } } if u.unrecognized.IsValid() { s := *ptr.offset(u.unrecognized).toBytes() b = append(b, s...) } return b, errLater }
marshal is the main function to marshal a message. It takes a byte slice and appends the encoded data to the end of the slice, returns the slice and error (if any). ptr is the pointer to the message. If deterministic is true, map is marshaled in deterministic order.
marshal
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func (u *marshalInfo) computeMarshalInfo() { u.Lock() defer u.Unlock() if u.initialized != 0 { // non-atomic read is ok as it is protected by the lock return } t := u.typ u.unrecognized = invalidField u.extensions = invalidField u.v1extensions = invalidField u.bytesExtensions = invalidField u.sizecache = invalidField isOneofMessage := false if reflect.PtrTo(t).Implements(sizerType) { u.hassizer = true } if reflect.PtrTo(t).Implements(protosizerType) { u.hasprotosizer = true } // If the message can marshal itself, let it do it, for compatibility. // NOTE: This is not efficient. if reflect.PtrTo(t).Implements(marshalerType) { u.hasmarshaler = true atomic.StoreInt32(&u.initialized, 1) return } n := t.NumField() // deal with XXX fields first for i := 0; i < t.NumField(); i++ { f := t.Field(i) if f.Tag.Get("protobuf_oneof") != "" { isOneofMessage = true } if !strings.HasPrefix(f.Name, "XXX_") { continue } switch f.Name { case "XXX_sizecache": u.sizecache = toField(&f) case "XXX_unrecognized": u.unrecognized = toField(&f) case "XXX_InternalExtensions": u.extensions = toField(&f) u.messageset = f.Tag.Get("protobuf_messageset") == "1" case "XXX_extensions": if f.Type.Kind() == reflect.Map { u.v1extensions = toField(&f) } else { u.bytesExtensions = toField(&f) } case "XXX_NoUnkeyedLiteral": // nothing to do default: panic("unknown XXX field: " + f.Name) } n-- } // get oneof implementers var oneofImplementers []interface{} // gogo: isOneofMessage is needed for embedded oneof messages, without a marshaler and unmarshaler if isOneofMessage { switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) { case oneofFuncsIface: _, _, _, oneofImplementers = m.XXX_OneofFuncs() case oneofWrappersIface: oneofImplementers = m.XXX_OneofWrappers() } }
computeMarshalInfo initializes the marshal info.
computeMarshalInfo
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/table_marshal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/table_marshal.go
Apache-2.0
func toField(f *reflect.StructField) field { return field(f.Offset) }
toField returns a field equivalent to the given reflect field.
toField
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (f field) IsValid() bool { return f != invalidField }
IsValid reports whether the field identifier is valid.
IsValid
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func toPointer(i *Message) pointer { // Super-tricky - read pointer out of data word of interface value. // Saves ~25ns over the equivalent: // return valToPointer(reflect.ValueOf(*i)) return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]} }
toPointer converts an interface of pointer type to a pointer that points to the same target.
toPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func toAddrPointer(i *interface{}, isptr bool) 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)} } // 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]} }
toAddrPointer converts an interface to a pointer that points to the interface data.
toAddrPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func valToPointer(v reflect.Value) pointer { return pointer{p: unsafe.Pointer(v.Pointer())} }
valToPointer converts v to a pointer. v must be of pointer type.
valToPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) offset(f field) pointer { // For safety, we should panic if !f.IsValid, however calling panic causes // this to no longer be inlineable, which is a serious performance cost. /* if !f.IsValid() { panic("invalid field") } */ return pointer{p: unsafe.Pointer(uintptr(p.p) + uintptr(f))} }
offset converts from a pointer to a structure to a pointer to one of its fields.
offset
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) getInt32Slice() []int32 { return *(*[]int32)(p.p) }
getInt32Slice loads a []int32 from p. The value returned is aliased with the original slice. This behavior differs from the implementation in pointer_reflect.go.
getInt32Slice
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) setInt32Slice(v []int32) { *(*[]int32)(p.p) = v }
setInt32Slice stores a []int32 to p. The value set is aliased with the input slice. This behavior differs from the implementation in pointer_reflect.go.
setInt32Slice
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) getPointerSlice() []pointer { // Super-tricky - p should point to a []*T where T is a // message type. We load it as []pointer. return *(*[]pointer)(p.p) }
getPointerSlice loads []*T from p as a []pointer. The value returned is aliased with the original slice. This behavior differs from the implementation in pointer_reflect.go.
getPointerSlice
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) setPointerSlice(v []pointer) { // Super-tricky - p should point to a []*T where T is a // message type. We store it as []pointer. *(*[]pointer)(p.p) = v }
setPointerSlice stores []pointer into p as a []*T. The value set is aliased with the input slice. This behavior differs from the implementation in pointer_reflect.go.
setPointerSlice
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) getPointer() pointer { return pointer{p: *(*unsafe.Pointer)(p.p)} }
getPointer loads the pointer at p and returns it.
getPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) setPointer(q pointer) { *(*unsafe.Pointer)(p.p) = q.p }
setPointer stores the pointer q at p.
setPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) appendPointer(q pointer) { s := (*[]unsafe.Pointer)(p.p) *s = append(*s, q.p) }
append q to the slice pointed to by p.
appendPointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) getInterfacePointer() pointer { // Super-tricky - read pointer out of data word of interface value. return pointer{p: (*(*[2]unsafe.Pointer)(p.p))[1]} }
getInterfacePointer returns a pointer that points to the interface data of the interface pointed by p.
getInterfacePointer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func (p pointer) asPointerTo(t reflect.Type) reflect.Value { return reflect.NewAt(t, p.p) }
asPointerTo returns a reflect.Value that is a pointer to an object of type t stored at p.
asPointerTo
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/pointer_unsafe.go
Apache-2.0
func isNonFatal(err error) bool { if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() { return true } if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() { return true } return false }
isNonFatal reports whether the error is either a RequiredNotSet error or a InvalidUTF8 error.
isNonFatal
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (nf *nonFatal) Merge(err error) (ok bool) { if err == nil { return true // not an error } if !isNonFatal(err) { return false // fatal error } if nf.E == nil { nf.E = err // store first instance of non-fatal error } return true }
Merge merges err into nf and reports whether it was successful. Otherwise it returns false for any fatal non-nil errors.
Merge
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func NewBuffer(e []byte) *Buffer { return &Buffer{buf: e} }
NewBuffer allocates a new Buffer and initializes its internal data to the contents of the argument slice.
NewBuffer
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (p *Buffer) Reset() { p.buf = p.buf[0:0] // for reading/writing p.index = 0 // for reading }
Reset resets the Buffer, ready for marshaling a new protocol buffer.
Reset
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (p *Buffer) SetBuf(s []byte) { p.buf = s p.index = 0 }
SetBuf replaces the internal buffer with the slice, ready for unmarshaling the contents of the slice.
SetBuf
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (p *Buffer) Bytes() []byte { return p.buf }
Bytes returns the contents of the Buffer.
Bytes
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (p *Buffer) SetDeterministic(deterministic bool) { p.deterministic = deterministic }
SetDeterministic sets whether to use deterministic serialization. Deterministic serialization guarantees that for a given binary, equal messages will always be serialized to the same bytes. This implies: - Repeated serialization of a message will return the same bytes. - Different processes of the same binary (which may be executing on different machines) will serialize equal messages to the same bytes. Note that the deterministic serialization is NOT canonical across languages. It is not guaranteed to remain stable over time. It is unstable across different builds with schema changes due to unknown fields. Users who need canonical serialization (e.g., persistent storage in a canonical form, fingerprinting, etc.) should define their own canonicalization specification and implement their own serializer rather than relying on this API. If deterministic serialization is requested, map entries will be sorted by keys in lexographical order. This is an implementation detail and subject to change.
SetDeterministic
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Bool(v bool) *bool { return &v }
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
Bool
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Int32(v int32) *int32 { return &v }
Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.
Int32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Int(v int) *int32 { p := new(int32) *p = int32(v) return p }
Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.
Int
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Int64(v int64) *int64 { return &v }
Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.
Int64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Float32(v float32) *float32 { return &v }
Float32 is a helper routine that allocates a new float32 value to store v and returns a pointer to it.
Float32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Float64(v float64) *float64 { return &v }
Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.
Float64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Uint32(v uint32) *uint32 { return &v }
Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.
Uint32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func Uint64(v uint64) *uint64 { return &v }
Uint64 is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.
Uint64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func String(v string) *string { return &v }
String is a helper routine that allocates a new string value to store v and returns a pointer to it.
String
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func EnumName(m map[int32]string, v int32) string { s, ok := m[v] if ok { return s } return strconv.Itoa(int(v)) }
EnumName is a helper function to simplify printing protocol buffer enums by name. Given an enum map and a value, it returns a useful string.
EnumName
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) { if data[0] == '"' { // New style: enums are strings. var repr string if err := json.Unmarshal(data, &repr); err != nil { return -1, err } val, ok := m[repr] if !ok { return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr) } return val, nil } // Old style: enums are ints. var val int32 if err := json.Unmarshal(data, &val); err != nil { return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName) } return val, nil }
UnmarshalJSONEnum is a helper function to simplify recovering enum int values from their JSON-encoded representation. Given a map from the enum's symbolic names to its int values, and a byte buffer containing the JSON-encoded value, it returns an int32 that can be cast to the enum type by the caller. The function can deal with both JSON representations, numeric and symbolic.
UnmarshalJSONEnum
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func (p *Buffer) DebugPrint(s string, b []byte) { var u uint64 obuf := p.buf sindex := p.index p.buf = b p.index = 0 depth := 0 fmt.Printf("\n--- %s ---\n", s) out: for { for i := 0; i < depth; i++ { fmt.Print(" ") } index := p.index if index == len(p.buf) { break } op, err := p.DecodeVarint() if err != nil { fmt.Printf("%3d: fetching op err %v\n", index, err) break out } tag := op >> 3 wire := op & 7 switch wire { default: fmt.Printf("%3d: t=%3d unknown wire=%d\n", index, tag, wire) break out case WireBytes: var r []byte r, err = p.DecodeRawBytes(false) if err != nil { break out } fmt.Printf("%3d: t=%3d bytes [%d]", index, tag, len(r)) if len(r) <= 6 { for i := 0; i < len(r); i++ { fmt.Printf(" %.2x", r[i]) } } else { for i := 0; i < 3; i++ { fmt.Printf(" %.2x", r[i]) } fmt.Printf(" ..") for i := len(r) - 3; i < len(r); i++ { fmt.Printf(" %.2x", r[i]) } } fmt.Printf("\n") case WireFixed32: u, err = p.DecodeFixed32() if err != nil { fmt.Printf("%3d: t=%3d fix32 err %v\n", index, tag, err) break out } fmt.Printf("%3d: t=%3d fix32 %d\n", index, tag, u) case WireFixed64: u, err = p.DecodeFixed64() if err != nil { fmt.Printf("%3d: t=%3d fix64 err %v\n", index, tag, err) break out } fmt.Printf("%3d: t=%3d fix64 %d\n", index, tag, u) case WireVarint: u, err = p.DecodeVarint() if err != nil { fmt.Printf("%3d: t=%3d varint err %v\n", index, tag, err) break out } fmt.Printf("%3d: t=%3d varint %d\n", index, tag, u) case WireStartGroup: fmt.Printf("%3d: t=%3d start\n", index, tag) depth++ case WireEndGroup: depth-- fmt.Printf("%3d: t=%3d end\n", index, tag) } } if depth != 0 { fmt.Printf("%3d: start-end not balanced %d\n", p.index, depth) } fmt.Printf("\n") p.buf = obuf p.index = sindex }
DebugPrint dumps the encoded data in b in a debugging format with a header including the string s. Used in testing but made available for general debugging.
DebugPrint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func SetDefaults(pb Message) { setDefaults(reflect.ValueOf(pb), true, false) }
SetDefaults sets unset protocol buffer fields to their default values. It only modifies fields that are both unset and have defined defaults. It recursively sets default values in any non-nil sub-messages.
SetDefaults
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMessage bool, err error) { var canHaveDefault bool switch ft.Kind() { case reflect.Struct: nestedMessage = true // non-nullable case reflect.Ptr: if ft.Elem().Kind() == reflect.Struct { nestedMessage = true } else { canHaveDefault = true // proto2 scalar field } case reflect.Slice: switch ft.Elem().Kind() { case reflect.Ptr, reflect.Struct: nestedMessage = true // repeated message case reflect.Uint8: canHaveDefault = true // bytes field } case reflect.Map: if ft.Elem().Kind() == reflect.Ptr { nestedMessage = true // map with message values } } if !canHaveDefault { if nestedMessage { return nil, true, nil } return nil, false, nil } // We now know that ft is a pointer or slice. sf = &scalarField{kind: ft.Elem().Kind()} // scalar fields without defaults if !prop.HasDefault { return sf, false, nil } // a scalar field: either *T or []byte switch ft.Elem().Kind() { case reflect.Bool: x, err := strconv.ParseBool(prop.Default) if err != nil { return nil, false, fmt.Errorf("proto: bad default bool %q: %v", prop.Default, err) } sf.value = x case reflect.Float32: x, err := strconv.ParseFloat(prop.Default, 32) if err != nil { return nil, false, fmt.Errorf("proto: bad default float32 %q: %v", prop.Default, err) } sf.value = float32(x) case reflect.Float64: x, err := strconv.ParseFloat(prop.Default, 64) if err != nil { return nil, false, fmt.Errorf("proto: bad default float64 %q: %v", prop.Default, err) } sf.value = x case reflect.Int32: x, err := strconv.ParseInt(prop.Default, 10, 32) if err != nil { return nil, false, fmt.Errorf("proto: bad default int32 %q: %v", prop.Default, err) } sf.value = int32(x) case reflect.Int64: x, err := strconv.ParseInt(prop.Default, 10, 64) if err != nil { return nil, false, fmt.Errorf("proto: bad default int64 %q: %v", prop.Default, err) } sf.value = x case reflect.String: sf.value = prop.Default case reflect.Uint8: // []byte (not *uint8) sf.value = []byte(prop.Default) case reflect.Uint32: x, err := strconv.ParseUint(prop.Default, 10, 32) if err != nil { return nil, false, fmt.Errorf("proto: bad default uint32 %q: %v", prop.Default, err) } sf.value = uint32(x) case reflect.Uint64: x, err := strconv.ParseUint(prop.Default, 10, 64) if err != nil { return nil, false, fmt.Errorf("proto: bad default uint64 %q: %v", prop.Default, err) } sf.value = x default: return nil, false, fmt.Errorf("proto: unhandled def kind %v", ft.Elem().Kind()) } return sf, false, nil }
fieldDefault returns the scalarField for field type ft. sf will be nil if the field can not have a default. nestedMessage will be true if this is a nested message. Note that sf.index is not set on return.
fieldDefault
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func mapKeys(vs []reflect.Value) sort.Interface { s := mapKeySorter{vs: vs} // Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps. if len(vs) == 0 { return s } switch vs[0].Kind() { case reflect.Int32, reflect.Int64: s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() } case reflect.Uint32, reflect.Uint64: s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() } case reflect.Bool: s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true case reflect.String: s.less = func(a, b reflect.Value) bool { return a.String() < b.String() } default: panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind())) } return s }
mapKeys returns a sort.Interface to be used for sorting the map keys. Map fields may have key types of non-float scalars, strings and enums.
mapKeys
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func isProto3Zero(v reflect.Value) bool { switch v.Kind() { case reflect.Bool: return !v.Bool() case reflect.Int32, reflect.Int64: return v.Int() == 0 case reflect.Uint32, reflect.Uint64: return v.Uint() == 0 case reflect.Float32, reflect.Float64: return v.Float() == 0 case reflect.String: return v.String() == "" } return false }
isProto3Zero reports whether v is a zero proto3 value.
isProto3Zero
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/lib.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/lib.go
Apache-2.0
func DecodeVarint(buf []byte) (x uint64, n int) { for shift := uint(0); shift < 64; shift += 7 { if n >= len(buf) { return 0, 0 } b := uint64(buf[n]) n++ x |= (b & 0x7F) << shift if (b & 0x80) == 0 { return x, n } } // The number is too large to represent in a 64-bit value. return 0, 0 }
DecodeVarint reads a varint-encoded integer from the slice. It returns the integer and the number of bytes consumed, or zero if there is not enough. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types.
DecodeVarint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeVarint() (x uint64, err error) { i := p.index buf := p.buf if i >= len(buf) { return 0, io.ErrUnexpectedEOF } else if buf[i] < 0x80 { p.index++ return uint64(buf[i]), nil } else if len(buf)-i < 10 { return p.decodeVarintSlow() } var b uint64 // we already checked the first byte x = uint64(buf[i]) - 0x80 i++ b = uint64(buf[i]) i++ x += b << 7 if b&0x80 == 0 { goto done } x -= 0x80 << 7 b = uint64(buf[i]) i++ x += b << 14 if b&0x80 == 0 { goto done } x -= 0x80 << 14 b = uint64(buf[i]) i++ x += b << 21 if b&0x80 == 0 { goto done } x -= 0x80 << 21 b = uint64(buf[i]) i++ x += b << 28 if b&0x80 == 0 { goto done } x -= 0x80 << 28 b = uint64(buf[i]) i++ x += b << 35 if b&0x80 == 0 { goto done } x -= 0x80 << 35 b = uint64(buf[i]) i++ x += b << 42 if b&0x80 == 0 { goto done } x -= 0x80 << 42 b = uint64(buf[i]) i++ x += b << 49 if b&0x80 == 0 { goto done } x -= 0x80 << 49 b = uint64(buf[i]) i++ x += b << 56 if b&0x80 == 0 { goto done } x -= 0x80 << 56 b = uint64(buf[i]) i++ x += b << 63 if b&0x80 == 0 { goto done } return 0, errOverflow done: p.index = i return x, nil }
DecodeVarint reads a varint-encoded integer from the Buffer. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types.
DecodeVarint
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeFixed64() (x uint64, err error) { // x, err already 0 i := p.index + 8 if i < 0 || i > len(p.buf) { err = io.ErrUnexpectedEOF return } p.index = i x = uint64(p.buf[i-8]) x |= uint64(p.buf[i-7]) << 8 x |= uint64(p.buf[i-6]) << 16 x |= uint64(p.buf[i-5]) << 24 x |= uint64(p.buf[i-4]) << 32 x |= uint64(p.buf[i-3]) << 40 x |= uint64(p.buf[i-2]) << 48 x |= uint64(p.buf[i-1]) << 56 return }
DecodeFixed64 reads a 64-bit integer from the Buffer. This is the format for the fixed64, sfixed64, and double protocol buffer types.
DecodeFixed64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeFixed32() (x uint64, err error) { // x, err already 0 i := p.index + 4 if i < 0 || i > len(p.buf) { err = io.ErrUnexpectedEOF return } p.index = i x = uint64(p.buf[i-4]) x |= uint64(p.buf[i-3]) << 8 x |= uint64(p.buf[i-2]) << 16 x |= uint64(p.buf[i-1]) << 24 return }
DecodeFixed32 reads a 32-bit integer from the Buffer. This is the format for the fixed32, sfixed32, and float protocol buffer types.
DecodeFixed32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeZigzag64() (x uint64, err error) { x, err = p.DecodeVarint() if err != nil { return } x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63) return }
DecodeZigzag64 reads a zigzag-encoded 64-bit integer from the Buffer. This is the format used for the sint64 protocol buffer type.
DecodeZigzag64
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeZigzag32() (x uint64, err error) { x, err = p.DecodeVarint() if err != nil { return } x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31)) return }
DecodeZigzag32 reads a zigzag-encoded 32-bit integer from the Buffer. This is the format used for the sint32 protocol buffer type.
DecodeZigzag32
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) { n, err := p.DecodeVarint() if err != nil { return nil, err } nb := int(n) if nb < 0 { return nil, fmt.Errorf("proto: bad byte length %d", nb) } end := p.index + nb if end < p.index || end > len(p.buf) { return nil, io.ErrUnexpectedEOF } if !alloc { // todo: check if can get more uses of alloc=false buf = p.buf[p.index:end] p.index += nb return } buf = make([]byte, nb) copy(buf, p.buf[p.index:]) p.index += nb return }
DecodeRawBytes reads a count-delimited byte buffer from the Buffer. This is the format used for the bytes protocol buffer type and for embedded messages.
DecodeRawBytes
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeStringBytes() (s string, err error) { buf, err := p.DecodeRawBytes(false) if err != nil { return } return string(buf), nil }
DecodeStringBytes reads an encoded string from the Buffer. This is the format used for the proto2 string type.
DecodeStringBytes
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func Unmarshal(buf []byte, pb Message) error { pb.Reset() if u, ok := pb.(newUnmarshaler); ok { return u.XXX_Unmarshal(buf) } if u, ok := pb.(Unmarshaler); ok { return u.Unmarshal(buf) } return NewBuffer(buf).Unmarshal(pb) }
Unmarshal parses the protocol buffer representation in buf and places the decoded result in pb. If the struct underlying pb does not match the data in buf, the results can be unpredictable. Unmarshal resets pb before starting to unmarshal, so any existing data in pb is always removed. Use UnmarshalMerge to preserve and append to existing data.
Unmarshal
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func UnmarshalMerge(buf []byte, pb Message) error { if u, ok := pb.(newUnmarshaler); ok { return u.XXX_Unmarshal(buf) } if u, ok := pb.(Unmarshaler); ok { // NOTE: The history of proto have unfortunately been inconsistent // whether Unmarshaler should or should not implicitly clear itself. // Some implementations do, most do not. // Thus, calling this here may or may not do what people want. // // See https://github.com/golang/protobuf/issues/424 return u.Unmarshal(buf) } return NewBuffer(buf).Unmarshal(pb) }
UnmarshalMerge parses the protocol buffer representation in buf and writes the decoded result to pb. If the struct underlying pb does not match the data in buf, the results can be unpredictable. UnmarshalMerge merges into existing data in pb. Most code should use Unmarshal instead.
UnmarshalMerge
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeMessage(pb Message) error { enc, err := p.DecodeRawBytes(false) if err != nil { return err } return NewBuffer(enc).Unmarshal(pb) }
DecodeMessage reads a count-delimited message from the Buffer.
DecodeMessage
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) DecodeGroup(pb Message) error { b := p.buf[p.index:] x, y := findEndGroup(b) if x < 0 { return io.ErrUnexpectedEOF } err := Unmarshal(b[:x], pb) p.index += y return err }
DecodeGroup reads a tag-delimited group from the Buffer. StartGroup tag is already consumed. This function consumes EndGroup tag.
DecodeGroup
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func (p *Buffer) Unmarshal(pb Message) error { // If the object can unmarshal itself, let it. if u, ok := pb.(newUnmarshaler); ok { err := u.XXX_Unmarshal(p.buf[p.index:]) p.index = len(p.buf) return err } if u, ok := pb.(Unmarshaler); ok { // NOTE: The history of proto have unfortunately been inconsistent // whether Unmarshaler should or should not implicitly clear itself. // Some implementations do, most do not. // Thus, calling this here may or may not do what people want. // // See https://github.com/golang/protobuf/issues/424 err := u.Unmarshal(p.buf[p.index:]) p.index = len(p.buf) return err } // Slow workaround for messages that aren't Unmarshalers. // This includes some hand-coded .pb.go files and // bootstrap protos. // TODO: fix all of those and then add Unmarshal to // the Message interface. Then: // The cast above and code below can be deleted. // The old unmarshaler can be deleted. // Clients can call Unmarshal directly (can already do that, actually). var info InternalMessageInfo err := info.Unmarshal(pb, p.buf[p.index:]) p.index = len(p.buf) return err }
Unmarshal parses the protocol buffer representation in the Buffer and places the decoded result in pb. If the struct underlying pb does not match the data in the buffer, the results can be unpredictable. Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
Unmarshal
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/decode.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/decode.go
Apache-2.0
func equalStruct(v1, v2 reflect.Value) bool { sprop := GetProperties(v1.Type()) for i := 0; i < v1.NumField(); i++ { f := v1.Type().Field(i) if strings.HasPrefix(f.Name, "XXX_") { continue } f1, f2 := v1.Field(i), v2.Field(i) if f.Type.Kind() == reflect.Ptr { if n1, n2 := f1.IsNil(), f2.IsNil(); n1 && n2 { // both unset continue } else if n1 != n2 { // set/unset mismatch return false } f1, f2 = f1.Elem(), f2.Elem() } if !equalAny(f1, f2, sprop.Prop[i]) { return false } } if em1 := v1.FieldByName("XXX_InternalExtensions"); em1.IsValid() { em2 := v2.FieldByName("XXX_InternalExtensions") if !equalExtensions(v1.Type(), em1.Interface().(XXX_InternalExtensions), em2.Interface().(XXX_InternalExtensions)) { return false } } if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() { em2 := v2.FieldByName("XXX_extensions") if !equalExtMap(v1.Type(), em1.Interface().(map[int32]Extension), em2.Interface().(map[int32]Extension)) { return false } } uf := v1.FieldByName("XXX_unrecognized") if !uf.IsValid() { return true } u1 := uf.Bytes() u2 := v2.FieldByName("XXX_unrecognized").Bytes() return bytes.Equal(u1, u2) }
v1 and v2 are known to have the same type.
equalStruct
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/equal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/equal.go
Apache-2.0
func equalAny(v1, v2 reflect.Value, prop *Properties) bool { if v1.Type() == protoMessageType { m1, _ := v1.Interface().(Message) m2, _ := v2.Interface().(Message) return Equal(m1, m2) } switch v1.Kind() { case reflect.Bool: return v1.Bool() == v2.Bool() case reflect.Float32, reflect.Float64: return v1.Float() == v2.Float() case reflect.Int32, reflect.Int64: return v1.Int() == v2.Int() case reflect.Interface: // Probably a oneof field; compare the inner values. n1, n2 := v1.IsNil(), v2.IsNil() if n1 || n2 { return n1 == n2 } e1, e2 := v1.Elem(), v2.Elem() if e1.Type() != e2.Type() { return false } return equalAny(e1, e2, nil) case reflect.Map: if v1.Len() != v2.Len() { return false } for _, key := range v1.MapKeys() { val2 := v2.MapIndex(key) if !val2.IsValid() { // This key was not found in the second map. return false } if !equalAny(v1.MapIndex(key), val2, nil) { return false } } return true case reflect.Ptr: // Maps may have nil values in them, so check for nil. if v1.IsNil() && v2.IsNil() { return true } if v1.IsNil() != v2.IsNil() { return false } return equalAny(v1.Elem(), v2.Elem(), prop) case reflect.Slice: if v1.Type().Elem().Kind() == reflect.Uint8 { // short circuit: []byte // Edge case: if this is in a proto3 message, a zero length // bytes field is considered the zero value. if prop != nil && prop.proto3 && v1.Len() == 0 && v2.Len() == 0 { return true } if v1.IsNil() != v2.IsNil() { return false } return bytes.Equal(v1.Interface().([]byte), v2.Interface().([]byte)) } if v1.Len() != v2.Len() { return false } for i := 0; i < v1.Len(); i++ { if !equalAny(v1.Index(i), v2.Index(i), prop) { return false } } return true case reflect.String: return v1.Interface().(string) == v2.Interface().(string) case reflect.Struct: return equalStruct(v1, v2) case reflect.Uint32, reflect.Uint64: return v1.Uint() == v2.Uint() } // unknown type, so not a protocol buffer log.Printf("proto: don't know how to compare %v", v1) return false }
v1 and v2 are known to have the same type. prop may be nil.
equalAny
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/equal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/equal.go
Apache-2.0
func equalExtensions(base reflect.Type, x1, x2 XXX_InternalExtensions) bool { em1, _ := x1.extensionsRead() em2, _ := x2.extensionsRead() return equalExtMap(base, em1, em2) }
base is the struct type that the extensions are based on. x1 and x2 are InternalExtensions.
equalExtensions
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/equal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/equal.go
Apache-2.0
func GetStats() Stats { return Stats{} }
Deprecated: do not use.
GetStats
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func MarshalMessageSet(interface{}) ([]byte, error) { return nil, errors.New("proto: not implemented") }
Deprecated: do not use.
MarshalMessageSet
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func UnmarshalMessageSet([]byte, interface{}) error { return errors.New("proto: not implemented") }
Deprecated: do not use.
UnmarshalMessageSet
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func MarshalMessageSetJSON(interface{}) ([]byte, error) { return nil, errors.New("proto: not implemented") }
Deprecated: do not use.
MarshalMessageSetJSON
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func UnmarshalMessageSetJSON([]byte, interface{}) error { return errors.New("proto: not implemented") }
Deprecated: do not use.
UnmarshalMessageSetJSON
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func RegisterMessageSetType(Message, int32, string) {}
Deprecated: do not use.
RegisterMessageSetType
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/deprecated.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/deprecated.go
Apache-2.0
func validateDuration(d *duration) error { if d == nil { return errors.New("duration: nil Duration") } if d.Seconds < minSeconds || d.Seconds > maxSeconds { return fmt.Errorf("duration: %#v: seconds out of range", d) } if d.Nanos <= -1e9 || d.Nanos >= 1e9 { return fmt.Errorf("duration: %#v: nanos out of range", d) } // Seconds and Nanos must have the same sign, unless d.Nanos is zero. if (d.Seconds < 0 && d.Nanos > 0) || (d.Seconds > 0 && d.Nanos < 0) { return fmt.Errorf("duration: %#v: seconds and nanos have different signs", d) } return nil }
validateDuration determines whether the Duration is valid according to the definition in google/protobuf/duration.proto. A valid Duration may still be too large to fit into a time.Duration (the range of Duration is about 10,000 years, and the range of time.Duration is about 290).
validateDuration
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/duration.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/duration.go
Apache-2.0
func durationFromProto(p *duration) (time.Duration, error) { if err := validateDuration(p); err != nil { return 0, err } d := time.Duration(p.Seconds) * time.Second if int64(d/time.Second) != p.Seconds { return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p) } if p.Nanos != 0 { d += time.Duration(p.Nanos) if (d < 0) != (p.Nanos < 0) { return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p) } } return d, nil }
DurationFromProto converts a Duration to a time.Duration. DurationFromProto returns an error if the Duration is invalid or is too large to be represented in a time.Duration.
durationFromProto
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/duration.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/duration.go
Apache-2.0
func durationProto(d time.Duration) *duration { nanos := d.Nanoseconds() secs := nanos / 1e9 nanos -= secs * 1e9 return &duration{ Seconds: secs, Nanos: int32(nanos), } }
DurationProto converts a time.Duration to a Duration.
durationProto
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/duration.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/duration.go
Apache-2.0
func isIdentOrNumberChar(c byte) bool { switch { case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z': return true case '0' <= c && c <= '9': return true } switch c { case '-', '+', '.', '_': return true } return false }
Numbers and identifiers are matched by [-+._A-Za-z0-9]
isIdentOrNumberChar
go
k8snetworkplumbingwg/multus-cni
vendor/github.com/gogo/protobuf/proto/text_parser.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go
Apache-2.0