Created
May 12, 2015 19:08
-
-
Save anton-povarov/6a3733d77da9ac837ba9 to your computer and use it in GitHub Desktop.
Bench code for #48 map vs bitmask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"testing" | |
"time" | |
) | |
import proto "github.com/gogo/protobuf/proto" | |
import math "math" | |
import io "io" | |
import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" | |
type NidOptNative struct { | |
Field1 float64 `protobuf:"fixed64,1,req" json:"Field1"` | |
Field2 float32 `protobuf:"fixed32,2,req" json:"Field2"` | |
Field3 int32 `protobuf:"varint,3,req" json:"Field3"` | |
Field4 int64 `protobuf:"varint,4,req" json:"Field4"` | |
Field5 uint32 `protobuf:"varint,5,req" json:"Field5"` | |
Field6 uint64 `protobuf:"varint,6,req" json:"Field6"` | |
Field7 int32 `protobuf:"zigzag32,7,req" json:"Field7"` | |
Field8 int64 `protobuf:"zigzag64,8,req" json:"Field8"` | |
Field9 uint32 `protobuf:"fixed32,9,req" json:"Field9"` | |
Field10 int32 `protobuf:"fixed32,10,req" json:"Field10"` | |
Field11 uint64 `protobuf:"fixed64,11,req" json:"Field11"` | |
Field12 int64 `protobuf:"fixed64,12,req" json:"Field12"` | |
Field13 bool `protobuf:"varint,13,req" json:"Field13"` | |
Field14 string `protobuf:"bytes,14,req" json:"Field14"` | |
Field15 []byte `protobuf:"bytes,15,req" json:"Field15"` | |
XXX_unrecognized []byte `json:"-"` | |
} | |
func (m *NidOptNative) Reset() { *m = NidOptNative{} } | |
func (m *NidOptNative) String() string { return proto.CompactTextString(m) } | |
func (*NidOptNative) ProtoMessage() {} | |
func (m *NidOptNative) UnmarshalBitmask(data []byte) error { | |
var hasFields [1]uint64 | |
l := len(data) | |
index := 0 | |
for index < l { | |
var wire uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
wire |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
fieldNum := int32(wire >> 3) | |
wireType := int(wire & 0x7) | |
switch fieldNum { | |
case 1: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field1", wireType) | |
} | |
var v uint64 | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
v = uint64(data[i-8]) | |
v |= uint64(data[i-7]) << 8 | |
v |= uint64(data[i-6]) << 16 | |
v |= uint64(data[i-5]) << 24 | |
v |= uint64(data[i-4]) << 32 | |
v |= uint64(data[i-3]) << 40 | |
v |= uint64(data[i-2]) << 48 | |
v |= uint64(data[i-1]) << 56 | |
m.Field1 = math.Float64frombits(v) | |
hasFields[0] |= uint64(0x00000001) | |
case 2: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field2", wireType) | |
} | |
var v uint32 | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
v = uint32(data[i-4]) | |
v |= uint32(data[i-3]) << 8 | |
v |= uint32(data[i-2]) << 16 | |
v |= uint32(data[i-1]) << 24 | |
m.Field2 = math.Float32frombits(v) | |
hasFields[0] |= uint64(0x00000002) | |
case 3: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field3", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field3 |= (int32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
hasFields[0] |= uint64(0x00000004) | |
case 4: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field4", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field4 |= (int64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
hasFields[0] |= uint64(0x00000008) | |
case 5: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field5", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field5 |= (uint32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
hasFields[0] |= uint64(0x00000010) | |
case 6: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field6", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field6 |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
hasFields[0] |= uint64(0x00000020) | |
case 7: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field7", wireType) | |
} | |
var v int32 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (int32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) | |
m.Field7 = v | |
hasFields[0] |= uint64(0x00000040) | |
case 8: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field8", wireType) | |
} | |
var v uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63) | |
m.Field8 = int64(v) | |
hasFields[0] |= uint64(0x00000080) | |
case 9: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field9", wireType) | |
} | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field9 = uint32(data[i-4]) | |
m.Field9 |= uint32(data[i-3]) << 8 | |
m.Field9 |= uint32(data[i-2]) << 16 | |
m.Field9 |= uint32(data[i-1]) << 24 | |
hasFields[0] |= uint64(0x00000100) | |
case 10: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field10", wireType) | |
} | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field10 = int32(data[i-4]) | |
m.Field10 |= int32(data[i-3]) << 8 | |
m.Field10 |= int32(data[i-2]) << 16 | |
m.Field10 |= int32(data[i-1]) << 24 | |
hasFields[0] |= uint64(0x00000200) | |
case 11: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field11", wireType) | |
} | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field11 = uint64(data[i-8]) | |
m.Field11 |= uint64(data[i-7]) << 8 | |
m.Field11 |= uint64(data[i-6]) << 16 | |
m.Field11 |= uint64(data[i-5]) << 24 | |
m.Field11 |= uint64(data[i-4]) << 32 | |
m.Field11 |= uint64(data[i-3]) << 40 | |
m.Field11 |= uint64(data[i-2]) << 48 | |
m.Field11 |= uint64(data[i-1]) << 56 | |
hasFields[0] |= uint64(0x00000400) | |
case 12: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field12", wireType) | |
} | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field12 = int64(data[i-8]) | |
m.Field12 |= int64(data[i-7]) << 8 | |
m.Field12 |= int64(data[i-6]) << 16 | |
m.Field12 |= int64(data[i-5]) << 24 | |
m.Field12 |= int64(data[i-4]) << 32 | |
m.Field12 |= int64(data[i-3]) << 40 | |
m.Field12 |= int64(data[i-2]) << 48 | |
m.Field12 |= int64(data[i-1]) << 56 | |
hasFields[0] |= uint64(0x00000800) | |
case 13: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field13", wireType) | |
} | |
var v int | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (int(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
m.Field13 = bool(v != 0) | |
hasFields[0] |= uint64(0x00001000) | |
case 14: | |
if wireType != 2 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field14", wireType) | |
} | |
var stringLen uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
stringLen |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
postIndex := index + int(stringLen) | |
if postIndex > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.Field14 = string(data[index:postIndex]) | |
index = postIndex | |
hasFields[0] |= uint64(0x00002000) | |
case 15: | |
if wireType != 2 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field15", wireType) | |
} | |
var byteLen int | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
byteLen |= (int(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
postIndex := index + byteLen | |
if postIndex > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.Field15 = append([]byte{}, data[index:postIndex]...) | |
index = postIndex | |
hasFields[0] |= uint64(0x00004000) | |
default: | |
var sizeOfWire int | |
for { | |
sizeOfWire++ | |
wire >>= 7 | |
if wire == 0 { | |
break | |
} | |
} | |
index -= sizeOfWire | |
skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:]) | |
if err != nil { | |
return err | |
} | |
if (index + skippy) > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...) | |
index += skippy | |
} | |
} | |
if hasFields[0]&uint64(0x00000001) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field1") | |
} | |
if hasFields[0]&uint64(0x00000002) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field2") | |
} | |
if hasFields[0]&uint64(0x00000004) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field3") | |
} | |
if hasFields[0]&uint64(0x00000008) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field4") | |
} | |
if hasFields[0]&uint64(0x00000010) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field5") | |
} | |
if hasFields[0]&uint64(0x00000020) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field6") | |
} | |
if hasFields[0]&uint64(0x00000040) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field7") | |
} | |
if hasFields[0]&uint64(0x00000080) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field8") | |
} | |
if hasFields[0]&uint64(0x00000100) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field9") | |
} | |
if hasFields[0]&uint64(0x00000200) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field10") | |
} | |
if hasFields[0]&uint64(0x00000400) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field11") | |
} | |
if hasFields[0]&uint64(0x00000800) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field12") | |
} | |
if hasFields[0]&uint64(0x00001000) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field13") | |
} | |
if hasFields[0]&uint64(0x00002000) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field14") | |
} | |
if hasFields[0]&uint64(0x00004000) == 0 { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Field15") | |
} | |
return nil | |
} | |
func (m *NidOptNative) UnmarshalMap(data []byte) error { | |
requiredFieldsPresent := map[string]bool{ | |
"Field1": false, | |
"Field2": false, | |
"Field3": false, | |
"Field4": false, | |
"Field5": false, | |
"Field6": false, | |
"Field7": false, | |
"Field8": false, | |
"Field9": false, | |
"Field10": false, | |
"Field11": false, | |
"Field12": false, | |
"Field13": false, | |
"Field14": false, | |
"Field15": false, | |
} | |
l := len(data) | |
index := 0 | |
for index < l { | |
var wire uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
wire |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
fieldNum := int32(wire >> 3) | |
wireType := int(wire & 0x7) | |
switch fieldNum { | |
case 1: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field1", wireType) | |
} | |
var v uint64 | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
v = uint64(data[i-8]) | |
v |= uint64(data[i-7]) << 8 | |
v |= uint64(data[i-6]) << 16 | |
v |= uint64(data[i-5]) << 24 | |
v |= uint64(data[i-4]) << 32 | |
v |= uint64(data[i-3]) << 40 | |
v |= uint64(data[i-2]) << 48 | |
v |= uint64(data[i-1]) << 56 | |
m.Field1 = math.Float64frombits(v) | |
requiredFieldsPresent["Field1"] = true | |
case 2: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field2", wireType) | |
} | |
var v uint32 | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
v = uint32(data[i-4]) | |
v |= uint32(data[i-3]) << 8 | |
v |= uint32(data[i-2]) << 16 | |
v |= uint32(data[i-1]) << 24 | |
m.Field2 = math.Float32frombits(v) | |
requiredFieldsPresent["Field2"] = true | |
case 3: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field3", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field3 |= (int32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
requiredFieldsPresent["Field3"] = true | |
case 4: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field4", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field4 |= (int64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
requiredFieldsPresent["Field4"] = true | |
case 5: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field5", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field5 |= (uint32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
requiredFieldsPresent["Field5"] = true | |
case 6: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field6", wireType) | |
} | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
m.Field6 |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
requiredFieldsPresent["Field6"] = true | |
case 7: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field7", wireType) | |
} | |
var v int32 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (int32(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) | |
m.Field7 = v | |
requiredFieldsPresent["Field7"] = true | |
case 8: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field8", wireType) | |
} | |
var v uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63) | |
m.Field8 = int64(v) | |
requiredFieldsPresent["Field8"] = true | |
case 9: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field9", wireType) | |
} | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field9 = uint32(data[i-4]) | |
m.Field9 |= uint32(data[i-3]) << 8 | |
m.Field9 |= uint32(data[i-2]) << 16 | |
m.Field9 |= uint32(data[i-1]) << 24 | |
requiredFieldsPresent["Field9"] = true | |
case 10: | |
if wireType != 5 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field10", wireType) | |
} | |
i := index + 4 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field10 = int32(data[i-4]) | |
m.Field10 |= int32(data[i-3]) << 8 | |
m.Field10 |= int32(data[i-2]) << 16 | |
m.Field10 |= int32(data[i-1]) << 24 | |
requiredFieldsPresent["Field10"] = true | |
case 11: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field11", wireType) | |
} | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field11 = uint64(data[i-8]) | |
m.Field11 |= uint64(data[i-7]) << 8 | |
m.Field11 |= uint64(data[i-6]) << 16 | |
m.Field11 |= uint64(data[i-5]) << 24 | |
m.Field11 |= uint64(data[i-4]) << 32 | |
m.Field11 |= uint64(data[i-3]) << 40 | |
m.Field11 |= uint64(data[i-2]) << 48 | |
m.Field11 |= uint64(data[i-1]) << 56 | |
requiredFieldsPresent["Field11"] = true | |
case 12: | |
if wireType != 1 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field12", wireType) | |
} | |
i := index + 8 | |
if i > l { | |
return io.ErrUnexpectedEOF | |
} | |
index = i | |
m.Field12 = int64(data[i-8]) | |
m.Field12 |= int64(data[i-7]) << 8 | |
m.Field12 |= int64(data[i-6]) << 16 | |
m.Field12 |= int64(data[i-5]) << 24 | |
m.Field12 |= int64(data[i-4]) << 32 | |
m.Field12 |= int64(data[i-3]) << 40 | |
m.Field12 |= int64(data[i-2]) << 48 | |
m.Field12 |= int64(data[i-1]) << 56 | |
requiredFieldsPresent["Field12"] = true | |
case 13: | |
if wireType != 0 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field13", wireType) | |
} | |
var v int | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
v |= (int(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
m.Field13 = bool(v != 0) | |
requiredFieldsPresent["Field13"] = true | |
case 14: | |
if wireType != 2 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field14", wireType) | |
} | |
var stringLen uint64 | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
stringLen |= (uint64(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
postIndex := index + int(stringLen) | |
if postIndex > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.Field14 = string(data[index:postIndex]) | |
index = postIndex | |
requiredFieldsPresent["Field14"] = true | |
case 15: | |
if wireType != 2 { | |
return fmt.Errorf("proto: wrong wireType = %d for field Field15", wireType) | |
} | |
var byteLen int | |
for shift := uint(0); ; shift += 7 { | |
if index >= l { | |
return io.ErrUnexpectedEOF | |
} | |
b := data[index] | |
index++ | |
byteLen |= (int(b) & 0x7F) << shift | |
if b < 0x80 { | |
break | |
} | |
} | |
postIndex := index + byteLen | |
if postIndex > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.Field15 = append([]byte{}, data[index:postIndex]...) | |
index = postIndex | |
requiredFieldsPresent["Field15"] = true | |
default: | |
var sizeOfWire int | |
for { | |
sizeOfWire++ | |
wire >>= 7 | |
if wire == 0 { | |
break | |
} | |
} | |
index -= sizeOfWire | |
skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:]) | |
if err != nil { | |
return err | |
} | |
if (index + skippy) > l { | |
return io.ErrUnexpectedEOF | |
} | |
m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...) | |
index += skippy | |
} | |
} | |
for fieldName, present := range requiredFieldsPresent { | |
if !present { | |
return github_com_gogo_protobuf_proto.NewRequiredNotSetError(fieldName) | |
} | |
} | |
return nil | |
} | |
func NewPopulatedNidOptNative(r randyRequiredexample, easy bool) *NidOptNative { | |
this := &NidOptNative{} | |
this.Field1 = r.Float64() | |
if r.Intn(2) == 0 { | |
this.Field1 *= -1 | |
} | |
this.Field2 = r.Float32() | |
if r.Intn(2) == 0 { | |
this.Field2 *= -1 | |
} | |
this.Field3 = r.Int31() | |
if r.Intn(2) == 0 { | |
this.Field3 *= -1 | |
} | |
this.Field4 = r.Int63() | |
if r.Intn(2) == 0 { | |
this.Field4 *= -1 | |
} | |
this.Field5 = r.Uint32() | |
this.Field6 = uint64(r.Uint32()) | |
this.Field7 = r.Int31() | |
if r.Intn(2) == 0 { | |
this.Field7 *= -1 | |
} | |
this.Field8 = r.Int63() | |
if r.Intn(2) == 0 { | |
this.Field8 *= -1 | |
} | |
this.Field9 = r.Uint32() | |
this.Field10 = r.Int31() | |
if r.Intn(2) == 0 { | |
this.Field10 *= -1 | |
} | |
this.Field11 = uint64(r.Uint32()) | |
this.Field12 = r.Int63() | |
if r.Intn(2) == 0 { | |
this.Field12 *= -1 | |
} | |
this.Field13 = bool(r.Intn(2) == 0) | |
this.Field14 = randStringRequiredexample(r) | |
v4 := r.Intn(100) | |
this.Field15 = make([]byte, v4) | |
for i := 0; i < v4; i++ { | |
this.Field15[i] = byte(r.Intn(256)) | |
} | |
if !easy && r.Intn(10) != 0 { | |
this.XXX_unrecognized = randUnrecognizedRequiredexample(r, 16) | |
} | |
return this | |
} | |
type RequiredExample struct { | |
TheRequiredString *string `protobuf:"bytes,1,req,name=theRequiredString" json:"theRequiredString,omitempty"` | |
TheOptionalString *string `protobuf:"bytes,2,opt,name=theOptionalString" json:"theOptionalString,omitempty"` | |
TheRepeatedStrings []string `protobuf:"bytes,3,rep,name=theRepeatedStrings" json:"theRepeatedStrings,omitempty"` | |
XXX_unrecognized []byte `json:"-"` | |
} | |
func (m *RequiredExample) Reset() { *m = RequiredExample{} } | |
func (m *RequiredExample) String() string { return proto.CompactTextString(m) } | |
func (*RequiredExample) ProtoMessage() {} | |
func (m *RequiredExample) Size() (n int) { | |
var l int | |
_ = l | |
if m.TheRequiredString != nil { | |
l = len(*m.TheRequiredString) | |
n += 1 + l + sovRequiredexample(uint64(l)) | |
} | |
if m.TheOptionalString != nil { | |
l = len(*m.TheOptionalString) | |
n += 1 + l + sovRequiredexample(uint64(l)) | |
} | |
if len(m.TheRepeatedStrings) > 0 { | |
for _, s := range m.TheRepeatedStrings { | |
l = len(s) | |
n += 1 + l + sovRequiredexample(uint64(l)) | |
} | |
} | |
if m.XXX_unrecognized != nil { | |
n += len(m.XXX_unrecognized) | |
} | |
return n | |
} | |
func sovRequiredexample(x uint64) (n int) { | |
for { | |
n++ | |
x >>= 7 | |
if x == 0 { | |
break | |
} | |
} | |
return n | |
} | |
func sozRequiredexample(x uint64) (n int) { | |
return sovRequiredexample(uint64((x << 1) ^ uint64((int64(x) >> 63)))) | |
} | |
func (m *RequiredExample) MarshalTo(data []byte) (n int, err error) { | |
var i int | |
_ = i | |
var l int | |
_ = l | |
if m.TheRequiredString == nil { | |
return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("theRequiredString") | |
} else { | |
data[i] = 0xa | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(len(*m.TheRequiredString))) | |
i += copy(data[i:], *m.TheRequiredString) | |
} | |
if m.TheOptionalString != nil { | |
data[i] = 0x12 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(len(*m.TheOptionalString))) | |
i += copy(data[i:], *m.TheOptionalString) | |
} | |
if len(m.TheRepeatedStrings) > 0 { | |
for _, s := range m.TheRepeatedStrings { | |
data[i] = 0x1a | |
i++ | |
l = len(s) | |
for l >= 1<<7 { | |
data[i] = uint8(uint64(l)&0x7f | 0x80) | |
l >>= 7 | |
i++ | |
} | |
data[i] = uint8(l) | |
i++ | |
i += copy(data[i:], s) | |
} | |
} | |
if m.XXX_unrecognized != nil { | |
i += copy(data[i:], m.XXX_unrecognized) | |
} | |
return i, nil | |
} | |
func (m *NidOptNative) Marshal() (data []byte, err error) { | |
size := m.Size() | |
data = make([]byte, size) | |
n, err := m.MarshalTo(data) | |
if err != nil { | |
return nil, err | |
} | |
return data[:n], nil | |
} | |
func encodeFixed64Requiredexample(data []byte, offset int, v uint64) int { | |
data[offset] = uint8(v) | |
data[offset+1] = uint8(v >> 8) | |
data[offset+2] = uint8(v >> 16) | |
data[offset+3] = uint8(v >> 24) | |
data[offset+4] = uint8(v >> 32) | |
data[offset+5] = uint8(v >> 40) | |
data[offset+6] = uint8(v >> 48) | |
data[offset+7] = uint8(v >> 56) | |
return offset + 8 | |
} | |
func encodeFixed32Requiredexample(data []byte, offset int, v uint32) int { | |
data[offset] = uint8(v) | |
data[offset+1] = uint8(v >> 8) | |
data[offset+2] = uint8(v >> 16) | |
data[offset+3] = uint8(v >> 24) | |
return offset + 4 | |
} | |
func encodeVarintRequiredexample(data []byte, offset int, v uint64) int { | |
for v >= 1<<7 { | |
data[offset] = uint8(v&0x7f | 0x80) | |
v >>= 7 | |
offset++ | |
} | |
data[offset] = uint8(v) | |
return offset + 1 | |
} | |
func (m *NidOptNative) MarshalTo(data []byte) (n int, err error) { | |
var i int | |
_ = i | |
var l int | |
_ = l | |
data[i] = 0x9 | |
i++ | |
i = encodeFixed64Requiredexample(data, i, uint64(math.Float64bits(m.Field1))) | |
data[i] = 0x15 | |
i++ | |
i = encodeFixed32Requiredexample(data, i, uint32(math.Float32bits(m.Field2))) | |
data[i] = 0x18 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(m.Field3)) | |
data[i] = 0x20 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(m.Field4)) | |
data[i] = 0x28 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(m.Field5)) | |
data[i] = 0x30 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(m.Field6)) | |
data[i] = 0x38 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64((uint32(m.Field7)<<1)^uint32((m.Field7>>31)))) | |
data[i] = 0x40 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64((uint64(m.Field8)<<1)^uint64((m.Field8>>63)))) | |
data[i] = 0x4d | |
i++ | |
i = encodeFixed32Requiredexample(data, i, uint32(m.Field9)) | |
data[i] = 0x55 | |
i++ | |
i = encodeFixed32Requiredexample(data, i, uint32(m.Field10)) | |
data[i] = 0x59 | |
i++ | |
i = encodeFixed64Requiredexample(data, i, uint64(m.Field11)) | |
data[i] = 0x61 | |
i++ | |
i = encodeFixed64Requiredexample(data, i, uint64(m.Field12)) | |
data[i] = 0x68 | |
i++ | |
if m.Field13 { | |
data[i] = 1 | |
} else { | |
data[i] = 0 | |
} | |
i++ | |
data[i] = 0x72 | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(len(m.Field14))) | |
i += copy(data[i:], m.Field14) | |
if m.Field15 != nil { | |
data[i] = 0x7a | |
i++ | |
i = encodeVarintRequiredexample(data, i, uint64(len(m.Field15))) | |
i += copy(data[i:], m.Field15) | |
} | |
if m.XXX_unrecognized != nil { | |
i += copy(data[i:], m.XXX_unrecognized) | |
} | |
return i, nil | |
} | |
func (m *NidOptNative) Size() (n int) { | |
var l int | |
_ = l | |
n += 9 | |
n += 5 | |
n += 1 + sovRequiredexample(uint64(m.Field3)) | |
n += 1 + sovRequiredexample(uint64(m.Field4)) | |
n += 1 + sovRequiredexample(uint64(m.Field5)) | |
n += 1 + sovRequiredexample(uint64(m.Field6)) | |
n += 1 + sozRequiredexample(uint64(m.Field7)) | |
n += 1 + sozRequiredexample(uint64(m.Field8)) | |
n += 5 | |
n += 5 | |
n += 9 | |
n += 9 | |
n += 2 | |
l = len(m.Field14) | |
n += 1 + l + sovRequiredexample(uint64(l)) | |
if m.Field15 != nil { | |
l = len(m.Field15) | |
n += 1 + l + sovRequiredexample(uint64(l)) | |
} | |
if m.XXX_unrecognized != nil { | |
n += len(m.XXX_unrecognized) | |
} | |
return n | |
} | |
type randyRequiredexample interface { | |
Float32() float32 | |
Float64() float64 | |
Int63() int64 | |
Int31() int32 | |
Uint32() uint32 | |
Intn(n int) int | |
} | |
func randUTF8RuneRequiredexample(r randyRequiredexample) rune { | |
return rune(r.Intn(126-43) + 43) | |
} | |
func randStringRequiredexample(r randyRequiredexample) string { | |
v20 := r.Intn(100) | |
tmps := make([]rune, v20) | |
for i := 0; i < v20; i++ { | |
tmps[i] = randUTF8RuneRequiredexample(r) | |
} | |
return string(tmps) | |
} | |
func randUnrecognizedRequiredexample(r randyRequiredexample, maxFieldNumber int) (data []byte) { | |
l := r.Intn(5) | |
for i := 0; i < l; i++ { | |
wire := r.Intn(4) | |
if wire == 3 { | |
wire = 5 | |
} | |
fieldNumber := maxFieldNumber + r.Intn(100) | |
data = randFieldRequiredexample(data, r, fieldNumber, wire) | |
} | |
return data | |
} | |
func randFieldRequiredexample(data []byte, r randyRequiredexample, fieldNumber int, wire int) []byte { | |
key := uint32(fieldNumber)<<3 | uint32(wire) | |
switch wire { | |
case 0: | |
data = encodeVarintPopulateRequiredexample(data, uint64(key)) | |
v21 := r.Int63() | |
if r.Intn(2) == 0 { | |
v21 *= -1 | |
} | |
data = encodeVarintPopulateRequiredexample(data, uint64(v21)) | |
case 1: | |
data = encodeVarintPopulateRequiredexample(data, uint64(key)) | |
data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) | |
case 2: | |
data = encodeVarintPopulateRequiredexample(data, uint64(key)) | |
ll := r.Intn(100) | |
data = encodeVarintPopulateRequiredexample(data, uint64(ll)) | |
for j := 0; j < ll; j++ { | |
data = append(data, byte(r.Intn(256))) | |
} | |
default: | |
data = encodeVarintPopulateRequiredexample(data, uint64(key)) | |
data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) | |
} | |
return data | |
} | |
func encodeVarintPopulateRequiredexample(data []byte, v uint64) []byte { | |
for v >= 1<<7 { | |
data = append(data, uint8(uint64(v)&0x7f|0x80)) | |
v >>= 7 | |
} | |
data = append(data, uint8(v)) | |
return data | |
} | |
func (m *RequiredExample) Marshal() (data []byte, err error) { | |
size := m.Size() | |
data = make([]byte, size) | |
n, err := m.MarshalTo(data) | |
if err != nil { | |
return nil, err | |
} | |
return data[:n], nil | |
} | |
// var err error | |
func BenchmarkMap(b *testing.B) { | |
r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
dataOut := NewPopulatedNidOptNative(r, true) | |
encodedMessage, _ := proto.Marshal(dataOut) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
dataIn := NidOptNative{} | |
_ = dataIn.UnmarshalMap(encodedMessage) | |
} | |
} | |
func BenchmarkBitmask(b *testing.B) { | |
r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
dataOut := NewPopulatedNidOptNative(r, true) | |
encodedMessage, _ := proto.Marshal(dataOut) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
dataIn := NidOptNative{} | |
_ = dataIn.UnmarshalBitmask(encodedMessage) | |
} | |
} | |
func main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment