当前位置: 首页>>代码示例>>Golang>>正文


Golang proto.GetExtension函数代码示例

本文整理汇总了Golang中limbo/services/protobuf/proto.GetExtension函数的典型用法代码示例。如果您正苦于以下问题:Golang GetExtension函数的具体用法?Golang GetExtension怎么用?Golang GetExtension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetExtension函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestGetExtensionStability

//See another version of this test in proto/extensions_test.go
func TestGetExtensionStability(t *testing.T) {
	check := func(m *NoExtensionsMap) bool {
		ext1, err := proto.GetExtension(m, E_FieldB1)
		if err != nil {
			t.Fatalf("GetExtension() failed: %s", err)
		}
		ext2, err := proto.GetExtension(m, E_FieldB1)
		if err != nil {
			t.Fatalf("GetExtension() failed: %s", err)
		}
		return ext1.(*NinOptNative).Equal(ext2)
	}
	msg := &NoExtensionsMap{Field1: proto.Int64(2)}
	ext0 := &NinOptNative{Field1: proto.Float64(1)}
	if err := proto.SetExtension(msg, E_FieldB1, ext0); err != nil {
		t.Fatalf("Could not set ext1: %s", ext0)
	}
	if !check(msg) {
		t.Errorf("GetExtension() not stable before marshaling")
	}
	bb, err := proto.Marshal(msg)
	if err != nil {
		t.Fatalf("Marshal() failed: %s", err)
	}
	msg1 := &NoExtensionsMap{}
	err = proto.Unmarshal(bb, msg1)
	if err != nil {
		t.Fatalf("Unmarshal() failed: %s", err)
	}
	if !check(msg1) {
		t.Errorf("GetExtension() not stable after unmarshaling")
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:34,代码来源:extension_test.go

示例2: TestGetExtensionStability

func TestGetExtensionStability(t *testing.T) {
	check := func(m *pb.MyMessage) bool {
		ext1, err := proto.GetExtension(m, pb.E_Ext_More)
		if err != nil {
			t.Fatalf("GetExtension() failed: %s", err)
		}
		ext2, err := proto.GetExtension(m, pb.E_Ext_More)
		if err != nil {
			t.Fatalf("GetExtension() failed: %s", err)
		}
		return ext1 == ext2
	}
	msg := &pb.MyMessage{Count: proto.Int32(4)}
	ext0 := &pb.Ext{}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext0); err != nil {
		t.Fatalf("Could not set ext1: %s", ext0)
	}
	if !check(msg) {
		t.Errorf("GetExtension() not stable before marshaling")
	}
	bb, err := proto.Marshal(msg)
	if err != nil {
		t.Fatalf("Marshal() failed: %s", err)
	}
	msg1 := &pb.MyMessage{}
	err = proto.Unmarshal(bb, msg1)
	if err != nil {
		t.Fatalf("Unmarshal() failed: %s", err)
	}
	if !check(msg1) {
		t.Errorf("GetExtension() not stable after unmarshaling")
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:33,代码来源:extensions_test.go

示例3: check

func check(t *testing.T, m extendable, fieldA float64, ext *proto.ExtensionDesc) {
	if !proto.HasExtension(m, ext) {
		t.Fatalf("expected extension to be set")
	}
	fieldA2Interface, err := proto.GetExtension(m, ext)
	if err != nil {
		panic(err)
	}
	fieldA2 := fieldA2Interface.(*float64)
	if fieldA != *fieldA2 {
		t.Fatalf("Expected %f got %f", fieldA, *fieldA2)
	}
	fieldA3Interface, err := proto.GetUnsafeExtension(m, ext.Field)
	if err != nil {
		panic(err)
	}
	fieldA3 := fieldA3Interface.(*float64)
	if fieldA != *fieldA3 {
		t.Fatalf("Expected %f got %f", fieldA, *fieldA3)
	}
	proto.ClearExtension(m, ext)
	if proto.HasExtension(m, ext) {
		t.Fatalf("expected extension to be cleared")
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:25,代码来源:extension_test.go

示例4: GetEnumValueCustomName

func GetEnumValueCustomName(field *google_protobuf.EnumValueDescriptorProto) string {
	if field.Options != nil {
		v, err := proto.GetExtension(field.Options, E_EnumvalueCustomname)
		if err == nil && v.(*string) != nil {
			return *(v.(*string))
		}
	}
	return ""
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:9,代码来源:helper.go

示例5: GetMoreTags

func GetMoreTags(field *google_protobuf.FieldDescriptorProto) *string {
	if field.Options != nil {
		v, err := proto.GetExtension(field.Options, E_Moretags)
		if err == nil && v.(*string) != nil {
			return (v.(*string))
		}
	}
	return nil
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:9,代码来源:helper.go

示例6: GetCastType

func GetCastType(field *google_protobuf.FieldDescriptorProto) string {
	if field.Options != nil {
		v, err := proto.GetExtension(field.Options, E_Casttype)
		if err == nil && v.(*string) != nil {
			return *(v.(*string))
		}
	}
	return ""
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:9,代码来源:helper.go

示例7: GetModel

func GetModel(msg *generator.Descriptor) *ModelDescriptor {
	if msg.Options != nil {
		v, _ := proto.GetExtension(msg.Options, E_Model)
		if v != nil {
			return v.(*ModelDescriptor)
		}
	}

	return nil
}
开发者ID:limbo-services,项目名称:core,代码行数:10,代码来源:sql_helpers.go

示例8: GetJoin

func GetJoin(field *pb.FieldDescriptorProto) *JoinDescriptor {
	if field.Options != nil {
		v, _ := proto.GetExtension(field.Options, E_Join)
		if v != nil {
			return v.(*JoinDescriptor)
		}
	}

	return nil
}
开发者ID:limbo-services,项目名称:core,代码行数:10,代码来源:sql_helpers.go

示例9: GetHTTPRule

func GetHTTPRule(method *pb.MethodDescriptorProto) *HttpRule {
	if method.Options == nil {
		return nil
	}
	v, _ := proto.GetExtension(method.Options, E_Http)
	if v == nil {
		return nil
	}
	return v.(*HttpRule)
}
开发者ID:limbo-services,项目名称:core,代码行数:10,代码来源:http_helpers.go

示例10: TestExtensionsRoundTrip

func TestExtensionsRoundTrip(t *testing.T) {
	msg := &pb.MyMessage{}
	ext1 := &pb.Ext{
		Data: proto.String("hi"),
	}
	ext2 := &pb.Ext{
		Data: proto.String("there"),
	}
	exists := proto.HasExtension(msg, pb.E_Ext_More)
	if exists {
		t.Error("Extension More present unexpectedly")
	}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext1); err != nil {
		t.Error(err)
	}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext2); err != nil {
		t.Error(err)
	}
	e, err := proto.GetExtension(msg, pb.E_Ext_More)
	if err != nil {
		t.Error(err)
	}
	x, ok := e.(*pb.Ext)
	if !ok {
		t.Errorf("e has type %T, expected testdata.Ext", e)
	} else if *x.Data != "there" {
		t.Errorf("SetExtension failed to overwrite, got %+v, not 'there'", x)
	}
	proto.ClearExtension(msg, pb.E_Ext_More)
	if _, err = proto.GetExtension(msg, pb.E_Ext_More); err != proto.ErrMissingExtension {
		t.Errorf("got %v, expected ErrMissingExtension", e)
	}
	if _, err := proto.GetExtension(msg, pb.E_X215); err == nil {
		t.Error("expected bad extension error, got nil")
	}
	if err := proto.SetExtension(msg, pb.E_X215, 12); err == nil {
		t.Error("expected extension err")
	}
	if err := proto.SetExtension(msg, pb.E_Ext_More, 12); err == nil {
		t.Error("expected some sort of type mismatch error, got nil")
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:42,代码来源:extensions_test.go

示例11: GetMinLength

func GetMinLength(field *pb.FieldDescriptorProto) (uint32, bool) {
	if field == nil || field.Options == nil {
		return 0, false
	}
	v, _ := proto.GetExtension(field.Options, E_MinLength)
	s, _ := v.(*uint32)
	if s == nil {
		return 0, false
	}
	return *s, true
}
开发者ID:limbo-services,项目名称:core,代码行数:11,代码来源:jsonschema_helpers.go

示例12: GetPattern

func GetPattern(field *pb.FieldDescriptorProto) (string, bool) {
	if field == nil || field.Options == nil {
		return "", false
	}
	v, _ := proto.GetExtension(field.Options, E_Pattern)
	s, _ := v.(*string)
	if s == nil {
		return "", false
	}
	return *s, true
}
开发者ID:limbo-services,项目名称:core,代码行数:11,代码来源:jsonschema_helpers.go

示例13: getCastValue

func getCastValue(field *descriptor.FieldDescriptorProto) (packageName string, typ string, err error) {
	if field.Options != nil {
		var v interface{}
		v, err = proto.GetExtension(field.Options, gogoproto.E_Castvalue)
		if err == nil && v.(*string) != nil {
			ctype := *(v.(*string))
			packageName, typ = splitCPackageType(ctype)
			return packageName, typ, nil
		}
	}
	return "", "", err
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:12,代码来源:helper.go

示例14: GetColumn

func GetColumn(field *pb.FieldDescriptorProto) *ColumnDescriptor {
	if field.Options == nil {
		field.Options = &pb.FieldOptions{}
	}

	v, _ := proto.GetExtension(field.Options, E_Column)
	if v == nil {
		if j, _ := proto.GetExtension(field.Options, E_Join); j != nil {
			return nil
		}

		v = &ColumnDescriptor{}
		proto.SetExtension(field.Options, E_Column, v)
	}

	c := v.(*ColumnDescriptor)
	if c.Ignore {
		return nil
	}

	return c
}
开发者ID:limbo-services,项目名称:core,代码行数:22,代码来源:sql_helpers.go

示例15: GetScope

func GetScope(method *descriptor.MethodDescriptorProto) (string, bool) {
	if method.Options != nil {
		v, _ := proto.GetExtension(method.Options, E_Authz)
		if v != nil {
			scope := v.(*AuthzRule).Scope
			if scope != "" {
				return scope, true
			}
		}
	}

	return "", false
}
开发者ID:limbo-services,项目名称:core,代码行数:13,代码来源:auth_helpers.go


注:本文中的limbo/services/protobuf/proto.GetExtension函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。