Inheritance: global::ProtoBuf.IExtensible
コード例 #1
0
ファイル: ProtoParseGen.cs プロジェクト: wujiangu/wanshiwu0.1
    static EnumDescriptorProto FindEnum(string name, google.protobuf.DescriptorProto message)
    {
        foreach (var cuEnum in message.enum_type)
        {
            if (string.Equals(cuEnum.name, name))
            {
                return(cuEnum);
            }
        }

        foreach (var proto in currentSet.file)
        {
            foreach (var cuEnum in proto.enum_type)
            {
                if (string.Equals(cuEnum.name, name))
                {
                    return(cuEnum);
                }
            }

            foreach (var current in proto.message_type)
            {
                foreach (var cuEnum in current.enum_type)
                {
                    if (string.Equals(cuEnum.name, name))
                    {
                        return(cuEnum);
                    }
                }
            }
        }

        throw new ProtoGenException("Enum " + name + " Can not Find!! PleaseCheck!");
        return(null);
    }
コード例 #2
0
    static int get_Define(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Descriptor obj = (Descriptor)o;
            google.protobuf.DescriptorProto ret = obj.Define;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Define on a nil value" : e.Message));
        }
    }
コード例 #3
0
ファイル: ImageFile.cs プロジェクト: wheybags/steamirc
        private void DumpDescriptor(DescriptorProto proto, FileDescriptorProto set, StringBuilder sb, int level)
        {
            PushDescriptorName(proto);

            string levelspace = new String('\t', level);

            sb.AppendLine(levelspace + "message " + proto.name + " {");

            foreach (var option in DumpOptions(proto.options))
            {
                sb.AppendLine(levelspace + "\toption " + option.Key + " = " + option.Value + ";");
            }

            foreach (DescriptorProto field in proto.nested_type)
            {
                DumpDescriptor(field, set, sb, level + 1);
            }

            DumpExtensionDescriptor(proto.extension, sb, levelspace + '\t');

            foreach (EnumDescriptorProto field in proto.enum_type)
            {
                DumpEnumDescriptor(field, sb, level + 1);
            }

            foreach (FieldDescriptorProto field in proto.field)
            {
                var enumLookup = new List<EnumDescriptorProto>();

                enumLookup.AddRange( set.enum_type ); // add global enums
                enumLookup.AddRange( proto.enum_type ); // add this message's nested enums

                sb.AppendLine(levelspace + "\t" + BuildDescriptorDeclaration(field));
            }

            if (proto.extension_range.Count > 0)
                sb.AppendLine();

            foreach (DescriptorProto.ExtensionRange range in proto.extension_range)
            {
                string max = Convert.ToString( range.end );

                // http://code.google.com/apis/protocolbuffers/docs/proto.html#extensions
                // If your numbering convention might involve extensions having very large numbers as tags, you can specify
                // that your extension range goes up to the maximum possible field number using the max keyword:
                // max is 2^29 - 1, or 536,870,911. 
                if ( range.end >= 536870911 )
                {
                    max = "max";
                }

                sb.AppendLine(levelspace + "\textensions " + range.start + " to " + max + ";");
            }

            sb.AppendLine(levelspace + "}");
            sb.AppendLine();

            PopDescriptorName();
        }
コード例 #4
0
ファイル: ImageFile.cs プロジェクト: wheybags/steamirc
 private void PushDescriptorName(DescriptorProto proto)
 {
     messageNameStack.Push(proto.name);
 }
コード例 #5
0
ファイル: ProtoParseGen.cs プロジェクト: wujiangu/wanshiwu0.1
    static void GenMessageParse(google.protobuf.DescriptorProto message)
    {
        ms_builder.Length = 0;
        StringBuilder builder = ms_builder;

        builder.Append(
            @"
    public void Parse(ProtoBuf.ProtoReader source){
        int fieldNumber = 0;
        while ((fieldNumber = source.ReadFieldHeader()) > 0)
        {
            switch (fieldNumber)
            {
                default:
                    source.SkipField();
                    break;
            
    ");
        foreach (var field in message.field)
        {
            /*builder.AppendFormat(
             *  @"
             *          case {0}:",field.number);
             */
            builder.AppendFormat(@"
            case {0}:   //{1} {2} {3} {4} {5}
                ", field.number, field.name, field.label, field.type, field.type_name, GetDataFromat(field.type));
            if (field.label == google.protobuf.FieldDescriptorProto.Label.LABEL_REPEATED)
            {
                /*if (field.type == google.protobuf.FieldDescriptorProto.Type.TYPE_STRING)
                 * {
                 *  builder.AppendFormat(@"
                 *  SubItemToken {0}token = ProtoReader.StartSubItem(source);
                 *  while (ProtoReader.HasSubValue(WireType.String, source))
                 *  {{
                 *      {0}.Add({1});
                 *  }}
                 *  ProtoReader.EndSubItem({0}token, source);
                 *  break;
                 *  ",field.name,
                 *  GetFieldParseByType(field.type, field.type_name));
                 * }
                 * else */
                {
                    if (field.type == google.protobuf.FieldDescriptorProto.Type.TYPE_MESSAGE)
                    {
                        builder.AppendFormat(
                            @"    int {1}field = source.FieldNumber;
                    do
                    {{
                        {0} {1}temp = new {0}();
                        ProtoBuf.SubItemToken {1}token = ProtoBuf.ProtoReader.StartSubItem(source); 
                        {1}temp.Parse(source);
                        ProtoBuf.ProtoReader.EndSubItem({1}token, source);
                        {1}.Add({1}temp);
                    }} while (source.TryReadFieldHeader({1}field));
                    break;
                    ", field.type_name.Substring(1), field.name);
                    }
                    else
                    {
                        string temp       = GetFieldParseByType(field.type, field.type_name);
                        var    wiretype   = TryGetWireType(field.type);
                        bool   bNeedsHint = NeedsHint(wiretype);
                        if (bNeedsHint)
                        {
                            builder.AppendFormat(
                                @"    int {0}field = source.FieldNumber;
                    do{{
                        source.Hint(ProtoBuf.WireType.{2}); 
                        {0}.Add({1});
                    }} while(source.TryReadFieldHeader({0}field));
                    break;
                    ", field.name,
                                temp, wiretype);
                        }
                        else
                        {
                            builder.AppendFormat(
                                @"    int {0}field = source.FieldNumber;
                    do{{
                        {0}.Add({1});
                    }} while(source.TryReadFieldHeader({0}field));
                    break;
                    ", field.name, temp);
                        }
                    }
                }
            }
            else
            {
                if (field.type == google.protobuf.FieldDescriptorProto.Type.TYPE_MESSAGE)
                {
                    builder.AppendFormat(@"    {0} = new {1}();", field.name, field.type_name.Substring(1));
                    builder.AppendFormat(@"
                    ProtoBuf.SubItemToken {0}token = ProtoBuf.ProtoReader.StartSubItem(source); 
                    {0}.Parse(source);
                    ProtoBuf.ProtoReader.EndSubItem({0}token, source);
                    break;
                    ", field.name);
                }
                else
                {
                    var  wiretype   = TryGetWireType(field.type);
                    bool bNeedsHint = NeedsHint(wiretype);
                    if (bNeedsHint)
                    {
                        builder.AppendFormat(
                            @"    source.Hint(ProtoBuf.WireType.{2}); 
                    {0} = {1};
                    break;
                    ", field.name,
                            GetFieldParseByType(field.type, field.type_name), wiretype);
                    }
                    else
                    {
                        builder.AppendFormat(
                            @"    {0} = {1};
                    break;
                    ", field.name,
                            GetFieldParseByType(field.type, field.type_name));
                    }
                }
            }
        }

        builder.Append(@"
            }
        }
    }");
        message.ParseCode = builder.ToString();
        foreach (var nestMsg in message.nested_type)
        {
            GenMessageParse(nestMsg);
        }
    }