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


Golang FileDescriptorSet.FindExtensionByFieldNumber方法代码示例

本文整理汇总了Golang中code/google/com/p/gogoprotobuf/protoc-gen-gogo/descriptor.FileDescriptorSet.FindExtensionByFieldNumber方法的典型用法代码示例。如果您正苦于以下问题:Golang FileDescriptorSet.FindExtensionByFieldNumber方法的具体用法?Golang FileDescriptorSet.FindExtensionByFieldNumber怎么用?Golang FileDescriptorSet.FindExtensionByFieldNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/gogoprotobuf/protoc-gen-gogo/descriptor.FileDescriptorSet的用法示例。


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

示例1: ToString


//.........这里部分代码省略.........
				w.String(`}` + "\n")
				break
			} else {
				w.tab()
				w.String(f.GetName() + `:`)
				var n int
				var err error
				switch f.GetType() {
				case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
					n, err = DecFloat64(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_FLOAT:
					n, err = DecFloat32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_INT64:
					n, err = DecInt64(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_UINT64:
					n, err = DecUint64(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_INT32:
					n, err = DecInt32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_FIXED64:
					n, err = DecFixed64(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_FIXED32:
					n, err = DecFixed32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_BOOL:
					n, err = DecBool(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_STRING:
					n, err = DecString(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_GROUP:
					panic("not implemented")
				case descriptor.FieldDescriptorProto_TYPE_BYTES:
					n, err = DecBytes(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_UINT32:
					n, err = DecUint32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_ENUM:
					n, err = DecInt32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
					n, err = DecSfixed32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
					n, err = DecSfixed64(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_SINT32:
					n, err = DecSint32(buf, offset, w)
				case descriptor.FieldDescriptorProto_TYPE_SINT64:
					n, err = DecSint64(buf, offset, w)
				default:
					panic("unreachable")
				}
				offset += n
				if err != nil {
					panic(err)
				}
				w.String(",\n")
				break
			}
		}
		if !found {
			for _, extRange := range msg.GetExtensionRange() {
				if extRange.GetStart() <= fieldNum && fieldNum <= extRange.GetEnd() {
					found = true
					break
				}
			}
			w.tab()
			offset -= n
			nn, err := proto.Skip(buf[offset:])
			if err != nil {
				panic(err)
			}
			if !found {
				w.String("XXX_unrecognized:")
			} else {
				w.String("XXX_extensions:")
				extPkg, ext := desc.FindExtensionByFieldNumber(messagePkg, messageName, fieldNum)
				if ext != nil && ext.IsMessage() {
					names := strings.Split(ext.GetTypeName(), ".")
					if len(names) == 3 {
						_, nnn, err := decodeVarint(buf, offset+n)
						if err != nil {
							panic(err)
						}
						w.tab()
						w.String(extPkg + "." + names[2] + `:{` + "\n")
						err = ToString(extPkg, names[2], desc, "", buf[offset+n+nnn:offset+nn], tabs+1, writer)
						if err != nil {
							return err
						}
						offset += nn
						w.tab()
						w.String(`}` + "\n")
						break
					} else {
						panic(ext.GetTypeName())
					}
				}
			}
			w.Bytes(buf[offset : offset+nn])
			w.String("\n")
			offset += nn
		}
	}
	return nil
}
开发者ID:Huangyan9188,项目名称:gogoprotobuf,代码行数:101,代码来源:string.go


注:本文中的code/google/com/p/gogoprotobuf/protoc-gen-gogo/descriptor.FileDescriptorSet.FindExtensionByFieldNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。