本文整理汇总了C#中ProtoBuf.ProtoReader.ReadUInt32Variant方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader.ReadUInt32Variant方法的具体用法?C# ProtoReader.ReadUInt32Variant怎么用?C# ProtoReader.ReadUInt32Variant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoReader
的用法示例。
在下文中一共展示了ProtoReader.ReadUInt32Variant方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendBytes
/// <summary>
/// Reads a byte-sequence from the stream, appending them to an existing byte-sequence (which can be null); supported wire-types: String
/// </summary>
public static byte[] AppendBytes(byte[] value, ProtoReader reader)
{
switch (reader.wireType)
{
case WireType.String:
int len = (int)reader.ReadUInt32Variant(false);
reader.wireType = WireType.None;
if (len == 0) return value;
int offset;
if(value == null || value.Length == 0) {
offset = 0;
value = new byte[len];
} else {
offset = value.Length;
byte[] tmp = new byte[value.Length + len];
Helpers.BlockCopy(value, 0, tmp, 0, value.Length);
value = tmp;
}
// value is now sized with the final length, and (if necessary)
// contains the old data up to "offset"
reader.position += len; // assume success
while (len > reader.available)
{
if (reader.available > 0)
{
// copy what we *do* have
Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, reader.available);
len -= reader.available;
offset += reader.available;
reader.ioIndex = reader.available = 0; // we've drained the buffer
}
// now refill the buffer (without overflowing it)
int count = len > reader.ioBuffer.Length ? reader.ioBuffer.Length : len;
if (count > 0) reader.Ensure(count, true);
}
// at this point, we know that len <= available
if (len > 0)
{ // still need data, but we have enough buffered
Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, len);
reader.ioIndex += len;
reader.available -= len;
}
return value;
default:
throw reader.CreateException();
}
}
示例2: StartSubItem
public static SubItemToken StartSubItem(ProtoReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
WireType wireType = reader.wireType;
if (wireType != WireType.String)
{
if (wireType != WireType.StartGroup)
{
throw reader.CreateWireTypeException();
}
reader.wireType = WireType.None;
reader.depth++;
return new SubItemToken(-reader.fieldNumber);
}
else
{
int num = (int)reader.ReadUInt32Variant(false);
if (num < 0)
{
throw ProtoReader.AddErrorData(new InvalidOperationException(), reader);
}
int value = reader.blockEnd;
reader.blockEnd = reader.position + num;
reader.depth++;
return new SubItemToken(value);
}
}
示例3: StartSubItem
/// <summary>
/// Begins consuming a nested message in the stream; supported wire-types: StartGroup, String
/// </summary>
/// <remarks>The token returned must be help and used when callining EndSubItem</remarks>
public static SubItemToken StartSubItem(ProtoReader reader)
{
switch (reader.wireType)
{
case WireType.StartGroup:
reader.wireType = WireType.None; // to prevent glitches from double-calling
reader.depth++;
return new SubItemToken(-reader.fieldNumber);
case WireType.String:
int len = (int)reader.ReadUInt32Variant(false);
if (len < 0) throw AddErrorData(new InvalidOperationException(), reader);
int lastEnd = reader.blockEnd;
reader.blockEnd = reader.position + len;
reader.depth++;
return new SubItemToken(lastEnd);
default:
throw reader.CreateException(); // throws
}
}
示例4: AppendBytes
public static byte[] AppendBytes(byte[] value, ProtoReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
WireType wireType = reader.wireType;
if (wireType != WireType.String)
{
throw reader.CreateWireTypeException();
}
int i = (int)reader.ReadUInt32Variant(false);
reader.wireType = WireType.None;
if (i == 0)
{
return (value != null) ? value : ProtoReader.EmptyBlob;
}
int num;
if (value == null || value.Length == 0)
{
num = 0;
value = new byte[i];
}
else
{
num = value.Length;
byte[] array = new byte[value.Length + i];
Helpers.BlockCopy(value, 0, array, 0, value.Length);
value = array;
}
reader.position += i;
while (i > reader.available)
{
if (reader.available > 0)
{
Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, num, reader.available);
i -= reader.available;
num += reader.available;
reader.ioIndex = (reader.available = 0);
}
int num2 = (i <= reader.ioBuffer.Length) ? i : reader.ioBuffer.Length;
if (num2 > 0)
{
reader.Ensure(num2, true);
}
}
if (i > 0)
{
Helpers.BlockCopy(reader.ioBuffer, reader.ioIndex, value, num, i);
reader.ioIndex += i;
reader.available -= i;
}
return value;
}