本文整理汇总了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);
}
}
示例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;
}
示例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
}
示例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;
}
示例5: GenerateEnums
static void GenerateEnums(ProtoMessage m, CodeWriter cw)
{
foreach (ProtoEnum me in m.Enums.Values)
{
GenerateEnum(me, cw);
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}