本文整理匯總了Golang中github.com/gogo/protobuf/proto.Size函數的典型用法代碼示例。如果您正苦於以下問題:Golang Size函數的具體用法?Golang Size怎麽用?Golang Size使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Size函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: _Value_OneofSizer
func _Value_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Value)
// kind
switch x := m.Kind.(type) {
case *Value_NullValue:
n += proto.SizeVarint(1<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.NullValue))
case *Value_NumberValue:
n += proto.SizeVarint(2<<3 | proto.WireFixed64)
n += 8
case *Value_StringValue:
n += proto.SizeVarint(3<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.StringValue)))
n += len(x.StringValue)
case *Value_BoolValue:
n += proto.SizeVarint(4<<3 | proto.WireVarint)
n += 1
case *Value_StructValue:
s := proto.Size(x.StructValue)
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Value_ListValue:
s := proto.Size(x.ListValue)
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例2: _Mutation_OneofSizer
func _Mutation_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Mutation)
// operation
switch x := m.Operation.(type) {
case *Mutation_Insert:
s := proto.Size(x.Insert)
n += proto.SizeVarint(4<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Mutation_Update:
s := proto.Size(x.Update)
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Mutation_Upsert:
s := proto.Size(x.Upsert)
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Mutation_Delete:
s := proto.Size(x.Delete)
n += proto.SizeVarint(7<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例3: _Distribution_BucketOptions_OneofSizer
func _Distribution_BucketOptions_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Distribution_BucketOptions)
// options
switch x := m.Options.(type) {
case *Distribution_BucketOptions_LinearBuckets:
s := proto.Size(x.LinearBuckets)
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Distribution_BucketOptions_ExponentialBuckets:
s := proto.Size(x.ExponentialBuckets)
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Distribution_BucketOptions_ExplicitBuckets:
s := proto.Size(x.ExplicitBuckets)
n += proto.SizeVarint(3<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例4: _Value_OneofSizer
func _Value_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Value)
// value_type
switch x := m.ValueType.(type) {
case *Value_NullValue:
n += proto.SizeVarint(11<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.NullValue))
case *Value_BooleanValue:
n += proto.SizeVarint(1<<3 | proto.WireVarint)
n += 1
case *Value_IntegerValue:
n += proto.SizeVarint(2<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.IntegerValue))
case *Value_DoubleValue:
n += proto.SizeVarint(3<<3 | proto.WireFixed64)
n += 8
case *Value_TimestampValue:
s := proto.Size(x.TimestampValue)
n += proto.SizeVarint(10<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Value_KeyValue:
s := proto.Size(x.KeyValue)
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Value_StringValue:
n += proto.SizeVarint(17<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.StringValue)))
n += len(x.StringValue)
case *Value_BlobValue:
n += proto.SizeVarint(18<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.BlobValue)))
n += len(x.BlobValue)
case *Value_GeoPointValue:
s := proto.Size(x.GeoPointValue)
n += proto.SizeVarint(8<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Value_EntityValue:
s := proto.Size(x.EntityValue)
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Value_ArrayValue:
s := proto.Size(x.ArrayValue)
n += proto.SizeVarint(9<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例5: _HttpRule_OneofSizer
func _HttpRule_OneofSizer(msg proto.Message) (n int) {
m := msg.(*HttpRule)
// pattern
switch x := m.Pattern.(type) {
case *HttpRule_Get:
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Get)))
n += len(x.Get)
case *HttpRule_Put:
n += proto.SizeVarint(3<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Put)))
n += len(x.Put)
case *HttpRule_Post:
n += proto.SizeVarint(4<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Post)))
n += len(x.Post)
case *HttpRule_Delete:
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Delete)))
n += len(x.Delete)
case *HttpRule_Patch:
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Patch)))
n += len(x.Patch)
case *HttpRule_Custom:
s := proto.Size(x.Custom)
n += proto.SizeVarint(8<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例6: _RowValue_OneofSizer
func _RowValue_OneofSizer(msg proto.Message) (n int) {
m := msg.(*RowValue)
// value
switch x := m.Value.(type) {
case *RowValue_Str:
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Str)))
n += len(x.Str)
case *RowValue_Int:
n += proto.SizeVarint(2<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.Int))
case *RowValue_Real:
n += proto.SizeVarint(3<<3 | proto.WireFixed32)
n += 4
case *RowValue_Date:
n += proto.SizeVarint(4<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.Date))
case *RowValue_DateOfTime:
n += proto.SizeVarint(5<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.DateOfTime))
case *RowValue_TimeOfDay:
s := proto.Size(x.TimeOfDay)
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例7: testSize
func testSize(m interface {
proto.Message
Size() int
}, desc string, expected int) ([]byte, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
protoSize := proto.Size(m)
mSize := m.Size()
lenData := len(data)
if protoSize != mSize || protoSize != lenData || mSize != lenData {
return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData)
}
if got := protoSize; got != expected {
return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected)
}
if got := mSize; got != expected {
return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected)
}
if got := lenData; got != expected {
return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected)
}
return data, nil
}
示例8: _Communique_OneofSizer
func _Communique_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Communique)
// union
switch x := m.Union.(type) {
case *Communique_Number:
n += proto.SizeVarint(5<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.Number))
case *Communique_Name:
n += proto.SizeVarint(6<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Name)))
n += len(x.Name)
case *Communique_Data:
n += proto.SizeVarint(7<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Data)))
n += len(x.Data)
case *Communique_TempC:
n += proto.SizeVarint(8<<3 | proto.WireFixed64)
n += 8
case *Communique_Height:
n += proto.SizeVarint(9<<3 | proto.WireFixed32)
n += 4
case *Communique_Today:
n += proto.SizeVarint(10<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.Today))
case *Communique_Maybe:
n += proto.SizeVarint(11<<3 | proto.WireVarint)
n += 1
case *Communique_Delta_:
n += proto.SizeVarint(12<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64((uint32(x.Delta) << 1) ^ uint32((int32(x.Delta) >> 31))))
case *Communique_Msg:
s := proto.Size(x.Msg)
n += proto.SizeVarint(13<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Communique_Somegroup:
n += proto.SizeVarint(14<<3 | proto.WireStartGroup)
n += proto.Size(x.Somegroup)
n += proto.SizeVarint(14<<3 | proto.WireEndGroup)
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例9: _RunQueryRequest_OneofSizer
func _RunQueryRequest_OneofSizer(msg proto.Message) (n int) {
m := msg.(*RunQueryRequest)
// query_type
switch x := m.QueryType.(type) {
case *RunQueryRequest_Query:
s := proto.Size(x.Query)
n += proto.SizeVarint(3<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *RunQueryRequest_GqlQuery:
s := proto.Size(x.GqlQuery)
n += proto.SizeVarint(7<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例10: TestRatchetState_SavedKeys_MessageKeySize
func TestRatchetState_SavedKeys_MessageKeySize(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedRatchetState_SavedKeys_MessageKey(popr, true)
size2 := github_com_gogo_protobuf_proto.Size(p)
data, err := github_com_gogo_protobuf_proto.Marshal(p)
if err != nil {
panic(err)
}
size := p.Size()
if len(data) != size {
t.Fatalf("size %v != marshalled size %v", size, len(data))
}
if size2 != size {
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
}
size3 := github_com_gogo_protobuf_proto.Size(p)
if size3 != size {
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
}
}
示例11: _Filter_OneofSizer
func _Filter_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Filter)
// filter_type
switch x := m.FilterType.(type) {
case *Filter_CompositeFilter:
s := proto.Size(x.CompositeFilter)
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Filter_PropertyFilter:
s := proto.Size(x.PropertyFilter)
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
示例12: TestClientToServer_DeliverEnvelopeSize
func TestClientToServer_DeliverEnvelopeSize(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedClientToServer_DeliverEnvelope(popr, true)
size2 := github_com_gogo_protobuf_proto.Size(p)
data, err := github_com_gogo_protobuf_proto.Marshal(p)
if err != nil {
panic(err)
}
size := p.Size()
if len(data) != size {
t.Fatalf("size %v != marshalled size %v", size, len(data))
}
if size2 != size {
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
}
size3 := github_com_gogo_protobuf_proto.Size(p)
if size3 != size {
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
}
}
示例13: TestFloatingPointSize
func TestFloatingPointSize(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedFloatingPoint(popr, true)
size2 := github_com_gogo_protobuf_proto.Size(p)
data, err := github_com_gogo_protobuf_proto.Marshal(p)
if err != nil {
panic(err)
}
size := p.Size()
if len(data) != size {
t.Errorf("size %v != marshalled size %v", size, len(data))
}
if size2 != size {
t.Errorf("size %v != before marshal proto.Size %v", size, size2)
}
size3 := github_com_gogo_protobuf_proto.Size(p)
if size3 != size {
t.Errorf("size %v != after marshal proto.Size %v", size, size3)
}
}
示例14: TestOperation_ExpungeSize
func TestOperation_ExpungeSize(t *testing18.T) {
popr := math_rand18.New(math_rand18.NewSource(time18.Now().UnixNano()))
p := NewPopulatedOperation_Expunge(popr, true)
size2 := github_com_gogo_protobuf_proto10.Size(p)
data, err := github_com_gogo_protobuf_proto10.Marshal(p)
if err != nil {
panic(err)
}
size := p.Size()
if len(data) != size {
t.Fatalf("size %v != marshalled size %v", size, len(data))
}
if size2 != size {
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
}
size3 := github_com_gogo_protobuf_proto10.Size(p)
if size3 != size {
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
}
}
示例15: _Operation_OneofSizer
func _Operation_OneofSizer(msg proto.Message) (n int) {
m := msg.(*Operation)
// result
switch x := m.Result.(type) {
case *Operation_Error:
s := proto.Size(x.Error)
n += proto.SizeVarint(4<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Operation_Response:
s := proto.Size(x.Response)
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}