本文整理匯總了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();
}