本文整理汇总了C#中ProtoBuf.ProtoWriter.Ensure方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoWriter.Ensure方法的具体用法?C# ProtoWriter.Ensure怎么用?C# ProtoWriter.Ensure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoWriter
的用法示例。
在下文中一共展示了ProtoWriter.Ensure方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteString
/// <summary>
/// Writes a string to the stream; supported wire-types: String
/// </summary>
public static void WriteString(string value, ProtoWriter writer)
{
if (writer.wireType != WireType.String) throw CreateException(writer);
if (value == null) throw new ArgumentNullException("value"); // written header; now what?
int len = value.Length;
if (len == 0)
{
WriteUInt32Variant(0, writer);
writer.wireType = WireType.None;
return; // just a header
}
#if MF
byte[] bytes = encoding.GetBytes(value);
int actual = bytes.Length;
writer.WriteUInt32Variant((uint)actual);
writer.Ensure(actual);
Helpers.BlockCopy(bytes, 0, writer.ioBuffer, writer.ioIndex, actual);
#else
int predicted = encoding.GetByteCount(value);
WriteUInt32Variant((uint)predicted, writer);
DemandSpace(predicted, writer);
int actual = encoding.GetBytes(value, 0, value.Length, writer.ioBuffer, writer.ioIndex);
Helpers.DebugAssert(predicted == actual);
#endif
IncrementedAndReset(actual, writer);
}