Пример #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

}
Пример #2
0
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
}
Пример #3
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()

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

		nestedMsg := msg.NestedMsg.Message(i)
		printMessage(gen, nestedMsg, file)
	}

	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("}")

}