當前位置: 首頁>>代碼示例>>C#>>正文


C# ProtocolBuffers.ProtoMessage類代碼示例

本文整理匯總了C#中SilentOrbit.ProtocolBuffers.ProtoMessage的典型用法代碼示例。如果您正苦於以下問題:C# ProtoMessage類的具體用法?C# ProtoMessage怎麽用?C# ProtoMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProtoMessage類屬於SilentOrbit.ProtocolBuffers命名空間,在下文中一共展示了ProtoMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ParseEnum

        static void ParseEnum(TokenReader tr, ProtoMessage parent, string package)
        {
            ProtoEnum me = new ProtoEnum(parent, package);

            LocalParser.ParseComments(me, lastComment, tr);
            me.ProtoName = tr.ReadNext();

            parent.Enums.Add(me.ProtoName, me); //must be after .ProtoName is read

            if (tr.ReadNext() != "{")
                throw new ProtoFormatException("Expected: {", tr);

            while (true)
            {
                string name = tr.ReadNext();

                if (ParseComment(name))
                    continue;

                if (name == "}")
                    return;

                //Ignore options
                if (name == "option")
                {
                    ParseOption(tr, null);
                    lastComment.Clear();
                    continue;
                }

                ParseEnumValue(tr, me, name);
            }
        }
開發者ID:huodianyan,項目名稱:ProtoBuf,代碼行數:33,代碼來源:ProtoParser.cs

示例2: GenerateClassSerializer

        public void GenerateClassSerializer(ProtoMessage m)
        {
            if (options.NoGenerateImported && m.IsImported)
            {
                Console.Error.WriteLine("Skipping imported " + m.FullProtoName);   
                return;
            }

            if (m.OptionExternal || m.OptionType == "interface")
            {
                //Don't make partial class of external classes or interfaces
                //Make separate static class for them
                cw.Bracket(m.OptionAccess + " static class " + m.SerializerType);
            }
            else
            {
                if (options.SerializableAttributes)
                    cw.Attribute("System.Serializable");
                cw.Bracket(m.OptionAccess + " partial " + m.OptionType + " " + m.SerializerType);
            }

            GenerateReader(m);

            GenerateWriter(m);
            foreach (ProtoMessage sub in m.Messages.Values)
            {
                cw.WriteLine();
                GenerateClassSerializer(sub);
            }
            cw.EndBracket();
            cw.WriteLine();
            return;
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:33,代碼來源:MessageSerializer.cs

示例3: GenerateProperties

        /// <summary>
        /// Generates the properties.
        /// </summary>
        /// <param name='template'>
        /// if true it will generate only properties that are not included by default, because of the [generate=false] option.
        /// </param>
        static void GenerateProperties(ProtoMessage m, CodeWriter cw)
        {
            foreach (Field f in m.Fields.Values)
            {
                if (f.OptionExternal)
                    cw.WriteLine("//" + GenerateProperty(f) + " // Implemented by user elsewhere");
                else
                {
                    if (f.Comments != null)
                        cw.Summary(f.Comments);
                    cw.WriteLine(GenerateProperty(f));
                    cw.WriteLine();
                }

            }

            //Wire format field ID
            #if DEBUG
            cw.Comment("ProtocolBuffers wire field id");
            foreach (Field f in m.Fields.Values)
            {
                cw.WriteLine("public const int " + f.CsName + "FieldID = " + f.ID + ";");
            }
            #endif
        }
開發者ID:4eJI0Be4ur,項目名稱:ProtoBuf,代碼行數:31,代碼來源:MessageCode.cs

示例4: GenerateClassSerializer

        public static void GenerateClassSerializer(ProtoMessage m, CodeWriter cw)
        {
            if (m.OptionExternal || m.OptionType == "interface")
            {
                //Don't make partial class of external classes or interfaces
                //Make separate static class for them
                cw.Bracket(m.OptionAccess + " static class " + m.SerializerType);
            }
            else
            {
                cw.Attribute("System.Serializable()");
                cw.Bracket(m.OptionAccess + " partial " + m.OptionType + " " + m.SerializerType);
            }

            GenerateReader(m, cw);

            GenerateWriter(m, cw);
            foreach (ProtoMessage sub in m.Messages.Values)
            {
                cw.WriteLine();
                GenerateClassSerializer(sub, cw);
            }
            cw.EndBracket();
            cw.WriteLine();
            return;
        }
開發者ID:huodianyan,項目名稱:ProtoBuf,代碼行數:26,代碼來源:MessageSerializer.cs

示例5: GenerateEnums

 static void GenerateEnums(ProtoMessage m, CodeWriter cw)
 {
     foreach (ProtoEnum me in m.Enums.Values)
     {
         GenerateEnum(me, cw);
     }
 }
開發者ID:4eJI0Be4ur,項目名稱:ProtoBuf,代碼行數:7,代碼來源:MessageCode.cs

示例6: PrepareMessage

        void PrepareMessage(ProtoMessage m)
        {
            //Name of message and enums
            m.CsType = GetCamelCase(m.ProtoName);
            foreach (ProtoEnum e in m.Enums.Values)
            {
                e.CsType = GetCamelCase(e.ProtoName);
            }

            foreach (ProtoMessage sub in m.Messages.Values)
                PrepareMessage(sub);

            //Prepare fields
            foreach (Field f in m.Fields.Values)
            {
                PrepareProtoType(m, f);

                DetectNameClash(m, f);

                if (f.OptionDefault != null)
                {
                    if (f.ProtoType is ProtoBuiltin && ((ProtoBuiltin)f.ProtoType).ProtoName == "bytes")
                        throw new NotImplementedException();
                    if (f.ProtoType is ProtoMessage)
                        throw new ProtoFormatException("Message can't have a default", f.Source);
                }
            }

        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:29,代碼來源:ProtoPrepare.cs

示例7: GenerateClass

        public void GenerateClass(ProtoMessage m)
        {
            if (options.NoGenerateImported && m.IsImported)
            {
                Console.Error.WriteLine("Skipping imported " + m.FullProtoName);   
                return;
            }

            //Do not generate class code for external classes
            if (m.OptionExternal)
            {
                cw.Comment("Written elsewhere");
                cw.Comment(m.OptionAccess + " " + m.OptionType + " " + m.CsType + " {}");
                return;
            }

            //Default class
            cw.Summary(m.Comments);
            cw.Bracket(m.OptionAccess + " partial " + m.OptionType + " " + m.CsType);

            if (options.GenerateDefaultConstructors)
                GenerateCtorForDefaults(m);

            GenerateEnums(m);

            GenerateProperties(m);

            //if(options.GenerateToString...
            // ...

            if (m.OptionPreserveUnknown)
            {
                cw.Summary("Values for unknown fields.");
                cw.WriteLine("public List<global::SilentOrbit.ProtocolBuffers.KeyValue> PreservedFields;");
                cw.WriteLine();
            }

            if (m.OptionTriggers)
            {
                cw.Comment("protected virtual void BeforeSerialize() {}");
                cw.Comment("protected virtual void AfterDeserialize() {}");
                cw.WriteLine();
            }

            foreach (ProtoMessage sub in m.Messages.Values)
            {
                GenerateClass(sub);
                cw.WriteLine();
            }
            cw.EndBracket();
            return;
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:52,代碼來源:MessageCode.cs

示例8: ProtoType

 /// <summary>
 /// Used by types within a namespace
 /// </summary>
 public ProtoType(ProtoMessage parent, string package)
     : this()
 {
     if (this is ProtoCollection == false)
     {
         if (parent == null)
             throw new ArgumentNullException("parent");
         if (package == null)
             throw new ArgumentNullException("package");
     }
     this.Parent = parent;
     this.Package = package;
 }
開發者ID:4eJI0Be4ur,項目名稱:ProtoBuf,代碼行數:16,代碼來源:ProtoType.cs

示例9: ParseMessageFlags

 static void ParseMessageFlags(ProtoMessage message, string flag)
 {
     switch (flag)
     {
         case "triggers":
             message.OptionTriggers = true;
             break;
         case "preserveunknown":
             message.OptionPreserveUnknown = true;
             break;
         case "external":
             message.OptionExternal = true;
             break;
         default:
             throw new NotImplementedException("Unknown option: " + flag);
     }
 }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:17,代碼來源:LocalParser.cs

示例10: GenerateClass

        public static void GenerateClass(ProtoMessage m, CodeWriter cw, Options options)
        {
            //Do not generate class code for external classes
            if (m.OptionExternal)
            {
                cw.Comment("Written elsewhere");
                cw.Comment(m.OptionAccess + " " + m.OptionType + " " + m.CsType + " {}");
                return;
            }

            //Default class
            cw.Summary(m.Comments);
            cw.Bracket(m.OptionAccess + " partial " + m.OptionType + " " + m.CsType);

            GenerateEnums(m, cw);

            GenerateProperties(m, cw);

            //if(options.GenerateToString...
            // ...

            if (m.OptionPreserveUnknown)
            {
                cw.Summary("Values for unknown fields.");
                cw.WriteLine("public List<global::SilentOrbit.ProtocolBuffers.KeyValue> PreservedFields;");
                cw.WriteLine();
            }

            if (m.OptionTriggers)
            {
                cw.Comment("protected virtual void BeforeSerialize() {}");
                cw.Comment("protected virtual void AfterDeserialize() {}");
                cw.WriteLine();
            }

            foreach (ProtoMessage sub in m.Messages.Values)
            {
                GenerateClass(sub, cw, options);
                cw.WriteLine();
            }
            cw.EndBracket();
            return;
        }
開發者ID:4eJI0Be4ur,項目名稱:ProtoBuf,代碼行數:43,代碼來源:MessageCode.cs

示例11: ParseMessageOption

 static void ParseMessageOption(ProtoMessage message, string key, string value)
 {
     //Parse value
     switch (key)
     {
         case "namespace":
             message.OptionNamespace = value;
             break;
         case "access":
             message.OptionAccess = value;
             break;
         case "type":
             message.OptionType = value;
             break;
         case "buffer":
             message.BufferSize = int.Parse(value);
             break;
         default:
             throw new NotImplementedException("Unknown option: " + key);
     }
 }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:21,代碼來源:LocalParser.cs

示例12: DetectNameClash

        /// <summary>
        /// Detect field which have the same name as a submessage in the same message.
        /// </summary>
        /// <param name="m">Parent message</param>
        /// <param name="f">Field to check</param>
        void DetectNameClash(ProtoMessage m, Field f)
        {
            bool nameclash = false;
            if (m.CsType == f.CsName)
                nameclash = true;
            foreach (var tm in m.Messages.Values)
                if (tm.CsType == f.CsName)
                    nameclash = true;
            foreach (var te in m.Enums.Values)
                if (te.CsType == f.CsName)
                    nameclash = true;
            foreach (var tf in m.Fields.Values)
            {
                if (tf == f)
                    continue;
                if (tf.CsName == f.CsName)
                    nameclash = true;
            }
            if (nameclash == false)
                return;

            //Name clash
            if (options.FixNameclash)
            {
                if (ConvertToCamelCase)
                    f.CsName += "Field";
                else
                    f.CsName += "_field";


                Console.Error.WriteLine("Warning: renamed field: " + m.FullCsType + "." + f.CsName);

                //Make sure our change did not result in another name collission
                DetectNameClash(m, f);
            }
            else
                throw new ProtoFormatException("The field: " + m.FullCsType + "." + f.CsName +
                    " has the same name as a sibling class/enum type which is not allowed in C#. " +
                    "Use --fix-nameclash to automatically rename the field.", f.Source);
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:45,代碼來源:ProtoPrepare.cs

示例13: GenerateClass

        public static void GenerateClass(ProtoMessage m, CodeWriter cw)
        {
            //Do not generate class code for external classes
            /*if (m.OptionExternal)
            {
                cw.Comment("Written elsewhere");
                cw.Comment(m.OptionAccess + " " + m.OptionType + " " + m.CsNamespace + "_" + m.CsType + " {}");
                return;
            }*/

            //Default class
            cw.Summary(m.Comments);
            cw.Bracket(m.OptionAccess + " " + m.OptionType + " " + m.CsNamespace + "_" + m.CsType);

            GenerateEnums(m, cw);

            GenerateProperties(m, cw);

            if (m.OptionPreserveUnknown)
            {
                cw.Summary("Values for unknown fields.");
                cw.WriteLine("public List<KeyValue> PreservedFields;");
                cw.WriteLine();
            }

            if (m.OptionTriggers)
            {
                cw.Comment("protected virtual void BeforeSerialize() {}");
                cw.Comment("protected virtual void AfterDeserialize() {}");
                cw.WriteLine();
            }

            foreach (ProtoMessage sub in m.Messages.Values)
            {
                GenerateClass(sub, cw);
                cw.WriteLine();
            }
            cw.EndBracket();
            return;
        }
開發者ID:huodianyan,項目名稱:CitoProtobuf,代碼行數:40,代碼來源:MessageCode.cs

示例14: SearchSubMessages

        static ProtoType SearchSubMessages(ProtoMessage msg, string fullPath)
        {
            foreach (ProtoMessage sub in msg.Messages.Values)
            {
                if (fullPath == sub.FullProtoName)
                    return sub;

                if (fullPath.StartsWith(sub.FullProtoName + "."))
                {
                    ProtoType pt = SearchSubMessages(sub, fullPath);
                    if (pt != null)
                        return pt;
                }
            }

            foreach (ProtoEnum subEnum in msg.Enums.Values)
            {
                if (fullPath == subEnum.FullProtoName)
                    return subEnum;
            }

            return null;
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:23,代碼來源:Search.cs

示例15: GetProtoType

        /// <summary>
        /// Search for message in hierarchy
        /// </summary>
        public static ProtoType GetProtoType(ProtoMessage msg, string path)
        {
            //Search for message or enum
            ProtoType pt;

            //Search from one level up until a match is found
            while (msg is ProtoCollection == false)
            {
                //Search sub messages
                pt = SearchSubMessages(msg, msg.Package + "." + msg.ProtoName + "." + path);
                if (pt != null)
                    return pt;

                //Search siblings
                pt = SearchSubMessages(msg.Parent, msg.Package + "." + path);
                if (pt != null)
                    return pt;

                msg = msg.Parent;
            }

            //Finally search for global namespace
            return SearchSubMessages(msg, path);
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:27,代碼來源:Search.cs


注:本文中的SilentOrbit.ProtocolBuffers.ProtoMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。