Exemplo n.º 1
0
func FieldByNameWithMeta(msgD *pbmeta.Descriptor, name string) *pbmeta.FieldDescriptor {

	for i := 0; i < msgD.FieldCount(); i++ {
		fd := msgD.Field(i)

		if fd.Name() == name {
			return fd
		}

		meta, ok := data.GetFieldMeta(fd)

		if !ok {
			return nil
		}

		if meta != nil && meta.Alias == name {

			return fd
		}

	}

	return nil

}
Exemplo n.º 2
0
func printMessage(gen *Generator, msg *pbmeta.Descriptor, file *pbmeta.FileDescriptor) {
	gen.Println("[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@\"", msg.Name(), "\")]")
	gen.Println("public partial class ", msg.Name(), " : global::ProtoBuf.IExtensible")
	gen.Println("{")
	gen.In()

	gen.Println("public ", msg.Name(), "() {}")
	gen.Println()

	for i := 0; i < msg.FieldCount(); i++ {

		fd := msg.Field(i)
		printField(gen, fd, msg, file)
		gen.Println()
	}

	for i := 0; i < msg.EnumCount(); i++ {

		enum := msg.Enum(i)
		printEnum(gen, enum)
	}

	gen.Println("private global::ProtoBuf.IExtension extensionObject;")
	gen.Println("global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)")
	gen.Println("{ return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }")

	gen.Out()
	gen.Println("}")

}
Exemplo n.º 3
0
Arquivo: lua.go Projeto: davyxu/tabtoy
func findMapperField(msg *data.DynamicMessage) (fdset []*pbmeta.FieldDescriptor, lineFieldName string) {

	var lineMsgDesc *pbmeta.Descriptor
	// 找到行描述符
	for i := 0; i < msg.Desc.FieldCount(); i++ {
		fd := msg.Desc.Field(i)

		if fd.IsRepeated() {
			lineMsgDesc = fd.MessageDesc()
			lineFieldName = fd.Name()
			break
		}
	}

	// 在结构中寻找需要导出的lua字段
	for i := 0; i < lineMsgDesc.FieldCount(); i++ {
		fd := lineMsgDesc.Field(i)

		meta, ok := data.GetFieldMeta(fd)

		if !ok {
			return nil, ""
		}

		if meta == nil {
			continue
		}

		if !meta.LuaMapper {
			continue
		}

		fdset = append(fdset, fd)
	}

	return
}