本文整理汇总了C#中SilentOrbit.ProtocolBuffers.ProtoMessage.MaxFieldBufferSize方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoMessage.MaxFieldBufferSize方法的具体用法?C# ProtoMessage.MaxFieldBufferSize怎么用?C# ProtoMessage.MaxFieldBufferSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SilentOrbit.ProtocolBuffers.ProtoMessage
的用法示例。
在下文中一共展示了ProtoMessage.MaxFieldBufferSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateWriter
/// <summary>
/// Generates code for writing a class/message
/// </summary>
static void GenerateWriter(ProtoMessage m, CodeWriter cw)
{
cw.Summary("Serialize the instance into the stream");
cw.Bracket(m.OptionAccess + " static void Serialize(Stream stream, " + m.CsType + " instance)");
if (m.OptionTriggers)
{
cw.WriteLine("instance.BeforeSerialize();");
cw.WriteLine();
}
if (m.IsUsingBinaryWriter)
cw.WriteLine("BinaryWriter bw = new BinaryWriter(stream);");
//Shared memorystream for all fields
cw.Using("var msField = new MemoryStream(" + m.MaxFieldBufferSize() + ")");
foreach (Field f in m.Fields.Values)
FieldSerializer.FieldWriter(m, f, cw);
cw.EndBracket();
if (m.OptionPreserveUnknown)
{
cw.IfBracket("instance.PreservedFields != null");
cw.ForeachBracket("var kv in instance.PreservedFields");
cw.WriteLine("global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteKey(stream, kv.Key);");
cw.WriteLine("stream.Write(kv.Value, 0, kv.Value.Length);");
cw.EndBracket();
cw.EndBracket();
}
cw.EndBracket();
cw.WriteLine();
cw.Summary("Helper: Serialize into a MemoryStream and return its byte array");
cw.Bracket(m.OptionAccess + " static byte[] SerializeToBytes(" + m.CsType + " instance)");
cw.Using("var ms = new MemoryStream()");
cw.WriteLine("Serialize(ms, instance);");
cw.WriteLine("return ms.ToArray();");
cw.EndBracket();
cw.EndBracket();
cw.Summary("Helper: Serialize with a varint length prefix");
cw.Bracket(m.OptionAccess + " static void SerializeLengthDelimited(Stream stream, " + m.CsType + " instance)");
cw.WriteLine("var data = SerializeToBytes(instance);");
cw.WriteLine("global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, (uint)data.Length);");
cw.WriteLine("stream.Write(data, 0, data.Length);");
cw.EndBracket();
}