本文整理汇总了C#中ProtoBuf.ProtoWriter.PopRecursionStack方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoWriter.PopRecursionStack方法的具体用法?C# ProtoWriter.PopRecursionStack怎么用?C# ProtoWriter.PopRecursionStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoWriter
的用法示例。
在下文中一共展示了ProtoWriter.PopRecursionStack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndSubItem
private static void EndSubItem(SubItemToken token, ProtoWriter writer, PrefixStyle style)
{
if (writer.wireType != WireType.None) { throw CreateException(writer); }
int value = token.value;
if (writer.depth <= 0) throw CreateException(writer);
if (writer.depth-- > RecursionCheckDepth)
{
writer.PopRecursionStack();
}
writer.packedFieldNumber = 0; // ending the sub-item always wipes packed encoding
if (value < 0)
{ // group - very simple append
WriteHeaderCore(-value, WireType.EndGroup, writer);
writer.wireType = WireType.None;
return;
}
// so we're backfilling the length into an existing sequence
int len;
switch(style)
{
case PrefixStyle.Fixed32:
len = (int)((writer.ioIndex - value) - 4);
ProtoWriter.WriteInt32ToBuffer(len, writer.ioBuffer, value);
break;
case PrefixStyle.Fixed32BigEndian:
len = (int)((writer.ioIndex - value) - 4);
byte[] buffer = writer.ioBuffer;
ProtoWriter.WriteInt32ToBuffer(len, buffer, value);
// and swap the byte order
byte b = buffer[value];
buffer[value] = buffer[value + 3];
buffer[value + 3] = b;
b = buffer[value + 1];
buffer[value + 1] = buffer[value + 2];
buffer[value + 2] = b;
break;
case PrefixStyle.Base128:
// string - complicated because we only reserved one byte;
// if the prefix turns out to need more than this then
// we need to shuffle the existing data
len = (int)((writer.ioIndex - value) - 1);
int offset = 0;
uint tmp = (uint)len;
while ((tmp >>= 7) != 0) offset++;
if (offset == 0)
{
writer.ioBuffer[value] = (byte)(len & 0x7F);
}
else
{
DemandSpace(offset, writer);
byte[] blob = writer.ioBuffer;
Helpers.BlockCopy(blob, value + 1, blob, value + 1 + offset, len);
tmp = (uint)len;
do
{
blob[value++] = (byte)((tmp & 0x7F) | 0x80);
} while ((tmp >>= 7) != 0);
blob[value - 1] = (byte)(blob[value - 1] & ~0x80);
writer.position += offset;
writer.ioIndex += offset;
}
break;
default:
throw new ArgumentOutOfRangeException("style");
}
// and this object is no longer a blockage
writer.flushLock--;
}
示例2: EndSubItem
private static void EndSubItem(SubItemToken token, ProtoWriter writer, PrefixStyle style)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (writer.wireType != WireType.None)
{
throw ProtoWriter.CreateException(writer);
}
int value = token.value;
if (writer.depth <= 0)
{
throw ProtoWriter.CreateException(writer);
}
if (writer.depth-- > 25)
{
writer.PopRecursionStack();
}
writer.packedFieldNumber = 0;
if (value < 0)
{
ProtoWriter.WriteHeaderCore(-value, WireType.EndGroup, writer);
writer.wireType = WireType.None;
return;
}
switch (style)
{
case PrefixStyle.Base128:
{
int num = writer.ioIndex - value - 1;
int num2 = 0;
uint num3 = (uint)num;
while ((num3 >>= 7) != 0u)
{
num2++;
}
if (num2 == 0)
{
writer.ioBuffer[value] = (byte)(num & 127);
}
else
{
ProtoWriter.DemandSpace(num2, writer);
byte[] array = writer.ioBuffer;
Helpers.BlockCopy(array, value + 1, array, value + 1 + num2, num);
num3 = (uint)num;
do
{
array[value++] = (byte)((num3 & 127u) | 128u);
}
while ((num3 >>= 7) != 0u);
array[value - 1] = (byte)((int)array[value - 1] & -129);
writer.position += num2;
writer.ioIndex += num2;
}
break;
}
case PrefixStyle.Fixed32:
{
int num = writer.ioIndex - value - 4;
ProtoWriter.WriteInt32ToBuffer(num, writer.ioBuffer, value);
break;
}
case PrefixStyle.Fixed32BigEndian:
{
int num = writer.ioIndex - value - 4;
byte[] array2 = writer.ioBuffer;
ProtoWriter.WriteInt32ToBuffer(num, array2, value);
byte b = array2[value];
array2[value] = array2[value + 3];
array2[value + 3] = b;
b = array2[value + 1];
array2[value + 1] = array2[value + 2];
array2[value + 2] = b;
break;
}
default:
throw new ArgumentOutOfRangeException("style");
}
if (--writer.flushLock == 0 && writer.ioIndex >= 1024)
{
ProtoWriter.Flush(writer);
}
}