本文整理汇总了C#中ProtoBuf.ProtoReader.SkipField方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader.SkipField方法的具体用法?C# ProtoReader.SkipField怎么用?C# ProtoReader.SkipField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoReader
的用法示例。
在下文中一共展示了ProtoReader.SkipField方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRandomDataWithReader
public void TestRandomDataWithReader()
{
var input = File.ReadAllBytes("protobuf-net.dll");
var stream = new MemoryStream(input);
stream.Seek(0, SeekOrigin.Begin);
Assert.Greater(3, 0); // I always double-check the param order
Assert.Greater(stream.Length, 0);
using (var reader = new ProtoReader(stream, null, null))
{
while (reader.ReadFieldHeader() > 0)
{
reader.SkipField();
}
}
}
示例2: ReadDecimal
public static decimal ReadDecimal(ProtoReader reader)
{
ulong num = 0uL;
uint num2 = 0u;
uint num3 = 0u;
SubItemToken token = ProtoReader.StartSubItem(reader);
int num4;
while ((num4 = reader.ReadFieldHeader()) > 0)
{
switch (num4)
{
case 1:
num = reader.ReadUInt64();
break;
case 2:
num2 = reader.ReadUInt32();
break;
case 3:
num3 = reader.ReadUInt32();
break;
default:
reader.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, reader);
if (num == 0uL && num2 == 0u)
{
return 0m;
}
int lo = (int)(num & 0xFFFFFFFFL);
int mid = (int)(num >> 32 & 0xFFFFFFFFL);
int hi = (int)num2;
bool isNegative = (num3 & 1u) == 1u;
byte scale = (byte)((num3 & 510u) >> 1);
return new decimal(lo, mid, hi, isNegative, scale);
}
示例3: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
#if FEAT_IKVM
throw new NotSupportedException();
#else
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
string typeName = source.ReadString();
type = source.DeserializeType(typeName);
if(type == null)
{
throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
if (type == typeof(string))
{
key = -1;
}
else
{
key = source.GetTypeKey(ref type);
if (key < 0)
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
break;
case FieldObject:
bool isString = type == typeof(string);
bool wasNull = value == null;
bool lateSet = wasNull && (isString || ((options & NetObjectOptions.LateSet) != 0));
if (newObjectKey >= 0 && !lateSet)
{
if (value == null)
{
source.TrapNextObject(newObjectKey);
}
else
{
source.NetCache.SetKeyedObject(newObjectKey, value);
}
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0)
{
if(wasNull && !lateSet)
{ // this both ensures (via exception) that it *was* set, and makes sure we don't shout
// about changed references
oldValue = source.NetCache.GetKeyedObject(newObjectKey);
}
if (lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
}
if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (newObjectKey < 0 && newTypeKey >= 0)
{ // have a new type, but not a new object
source.NetCache.SetKeyedObject(newTypeKey, type);
}
break;
default:
source.SkipField();
break;
//.........这里部分代码省略.........
示例4: ReadGuid
/// <summary>
/// Parses a Guid from a protobuf stream
/// </summary>
public static Guid ReadGuid(ProtoReader source)
{
ulong low = 0, high = 0;
int fieldNumber;
SubItemToken token = ProtoReader.StartSubItem(source);
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldGuidLow: low = source.ReadUInt64(); break;
case FieldGuidHigh: high = source.ReadUInt64(); break;
default: source.SkipField(); break;
}
}
ProtoReader.EndSubItem(token, source);
if(low == 0 && high == 0) return Guid.Empty;
uint a = (uint)(low >> 32), b = (uint)low, c = (uint)(high >> 32), d= (uint)high;
return new Guid((int)b, (short)a, (short)(a >> 16),
(byte)d, (byte)(d >> 8), (byte)(d >> 16), (byte)(d >> 24),
(byte)c, (byte)(c >> 8), (byte)(c >> 16), (byte)(c >> 24));
}
示例5: ReadDecimal
/// <summary>
/// Parses a decimal from a protobuf stream
/// </summary>
public static decimal ReadDecimal(ProtoReader reader)
{
ulong low = 0;
uint high = 0;
uint signScale = 0;
int fieldNumber;
SubItemToken token = ProtoReader.StartSubItem(reader);
while ((fieldNumber = reader.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldDecimalLow: low = reader.ReadUInt64(); break;
case FieldDecimalHigh: high = reader.ReadUInt32(); break;
case FieldDecimalSignScale: signScale = reader.ReadUInt32(); break;
default: reader.SkipField(); break;
}
}
ProtoReader.EndSubItem(token, reader);
if (low == 0 && high == 0) return decimal.Zero;
int lo = (int)(low & 0xFFFFFFFFL),
mid = (int)((low >> 32) & 0xFFFFFFFFL),
hi = (int)high;
bool isNeg = (signScale & 0x0001) == 0x0001;
byte scale = (byte)((signScale & 0x01FE) >> 1);
return new decimal(lo, mid, hi, isNeg, scale);
}
示例6: ReadTimeSpanTicks
private static long ReadTimeSpanTicks(ProtoReader source) {
switch (source.WireType)
{
case WireType.String:
case WireType.StartGroup:
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
TimeSpanScale scale = TimeSpanScale.Days;
long value = 0;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldTimeSpanScale:
scale = (TimeSpanScale)source.ReadInt32();
break;
case FieldTimeSpanValue:
source.Assert(WireType.SignedVariant);
value = source.ReadInt64();
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
switch (scale)
{
case TimeSpanScale.Days:
return value * TimeSpan.TicksPerDay;
case TimeSpanScale.Hours:
return value * TimeSpan.TicksPerHour;
case TimeSpanScale.Minutes:
return value * TimeSpan.TicksPerMinute;
case TimeSpanScale.Seconds:
return value * TimeSpan.TicksPerSecond;
case TimeSpanScale.Milliseconds:
return value * TimeSpan.TicksPerMillisecond;
case TimeSpanScale.Ticks:
return value;
case TimeSpanScale.MinMax:
switch (value)
{
case 1: return long.MaxValue;
case -1: return long.MinValue;
default: throw new ProtoException("Unknown min/max value: " + value.ToString());
}
default:
throw new ProtoException("Unknown timescale: " + scale.ToString());
}
case WireType.Fixed64:
return source.ReadInt64();
default:
throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
}
}
示例7: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
string typeName = source.ReadString();
type = source.DeserializeType(typeName);
if(type == null)
{
throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
key = source.GetTypeKey(ref type);
if(key < 0) throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
break;
case FieldObject:
bool isString = type == typeof(string);
bool lateSet = value == null && isString;
if (value == null && !lateSet)
{
try
{
value = ((options & NetObjectOptions.UseConstructor) == 0)
? BclHelpers.GetUninitializedObject(type)
: (type.IsArray || type.IsInterface ? null : Activator.CreateInstance(type, true));
} catch (Exception ex)
{
throw new ProtoException("Unable to create type " + (type == null ? "<null>" : type.FullName) + ": " + ex.Message, ex);
}
}
if (newObjectKey >= 0 && !lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0 && lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value) && type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (newObjectKey < 0 && newTypeKey >= 0)
{ // have a new type, but not a new object
source.NetCache.SetKeyedObject(newTypeKey, type);
}
break;
default:
source.SkipField();
break;
}
}
if(newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
{
throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
}
ProtoReader.EndSubItem(token, source);
return value;
}
示例8: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
type = source.DeserializeType(source.ReadString());
key = source.GetTypeKey(ref type);
break;
case FieldObject:
bool isString = type == typeof(string);
bool lateSet = value == null && isString;
if (value == null && !lateSet)
{
value = ((options & NetObjectOptions.UseConstructor) == 0) ? BclHelpers.GetUninitializedObject(type) : Activator.CreateInstance(type);
}
if (newObjectKey >= 0 && !lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0 && lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
if (!lateSet && !ReferenceEquals(oldValue, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
return value;
}
示例9: ReadGuid
public static Guid ReadGuid(ProtoReader source)
{
ulong num = 0uL;
ulong num2 = 0uL;
SubItemToken token = ProtoReader.StartSubItem(source);
int num3;
while ((num3 = source.ReadFieldHeader()) > 0)
{
int num4 = num3;
if (num4 != 1)
{
if (num4 != 2)
{
source.SkipField();
}
else
{
num2 = source.ReadUInt64();
}
}
else
{
num = source.ReadUInt64();
}
}
ProtoReader.EndSubItem(token, source);
if (num == 0uL && num2 == 0uL)
{
return Guid.Empty;
}
uint num5 = (uint)(num >> 32);
uint a = (uint)num;
uint num6 = (uint)(num2 >> 32);
uint num7 = (uint)num2;
return new Guid((int)a, (short)num5, (short)(num5 >> 16), (byte)num7, (byte)(num7 >> 8), (byte)(num7 >> 16), (byte)(num7 >> 24), (byte)num6, (byte)(num6 >> 8), (byte)(num6 >> 16), (byte)(num6 >> 24));
}
示例10: ReadTimeSpanTicks
private static long ReadTimeSpanTicks(ProtoReader source)
{
switch (source.WireType)
{
case WireType.Fixed64:
return source.ReadInt64();
case WireType.String:
case WireType.StartGroup:
{
SubItemToken token = ProtoReader.StartSubItem(source);
TimeSpanScale timeSpanScale = TimeSpanScale.Days;
long num = 0L;
int num2;
while ((num2 = source.ReadFieldHeader()) > 0)
{
int num3 = num2;
if (num3 != 1)
{
if (num3 != 2)
{
source.SkipField();
}
else
{
timeSpanScale = (TimeSpanScale)source.ReadInt32();
}
}
else
{
source.Assert(WireType.SignedVariant);
num = source.ReadInt64();
}
}
ProtoReader.EndSubItem(token, source);
TimeSpanScale timeSpanScale2 = timeSpanScale;
switch (timeSpanScale2)
{
case TimeSpanScale.Days:
return num * 864000000000L;
case TimeSpanScale.Hours:
return num * 36000000000L;
case TimeSpanScale.Minutes:
return num * 600000000L;
case TimeSpanScale.Seconds:
return num * 10000000L;
case TimeSpanScale.Milliseconds:
return num * 10000L;
case TimeSpanScale.Ticks:
return num;
default:
{
if (timeSpanScale2 != TimeSpanScale.MinMax)
{
throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
}
long num4 = num;
if (num4 >= -1L && num4 <= 1L)
{
switch ((int)(num4 - -1L))
{
case 0:
return -9223372036854775808L;
case 2:
return 9223372036854775807L;
}
}
throw new ProtoException("Unknown min/max value: " + num.ToString());
}
}
break;
}
default:
throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
}
}
示例11: ReadNetObject
//.........这里部分代码省略.........
}
case 2:
num = source.ReadInt32();
continue;
case 3:
{
int key2 = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(key2);
key = source.GetTypeKey(ref type);
continue;
}
case 4:
num2 = source.ReadInt32();
continue;
case 8:
{
string text = source.ReadString();
type = source.DeserializeType(text);
if (type == null)
{
throw new ProtoException("Unable to resolve type: " + text + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
if (type == typeof(string))
{
key = -1;
}
else
{
key = source.GetTypeKey(ref type);
if (key < 0)
{
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
}
continue;
}
case 10:
{
bool flag = type == typeof(string);
bool flag2 = value == null;
bool flag3 = flag2 && (flag || (byte)(options & BclHelpers.NetObjectOptions.LateSet) != 0);
if (num >= 0 && !flag3)
{
if (value == null)
{
source.TrapNextObject(num);
}
else
{
source.NetCache.SetKeyedObject(num, value);
}
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
object obj = value;
if (flag)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(obj, key, source, type);
}
if (num >= 0)
{
if (flag2 && !flag3)
{
obj = source.NetCache.GetKeyedObject(num);
}
if (flag3)
{
source.NetCache.SetKeyedObject(num, value);
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
}
if (num >= 0 && !flag3 && !object.ReferenceEquals(obj, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (num < 0 && num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
continue;
}
}
source.SkipField();
}
if (num >= 0 && (byte)(options & BclHelpers.NetObjectOptions.AsReference) == 0)
{
throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
}
ProtoReader.EndSubItem(token, source);
return value;
}
示例12: Read
/// <summary>
/// The read.
/// </summary>
/// <param name="platformData">
/// The platform data.
/// </param>
/// <param name="protoReader">
/// The proto reader.
/// </param>
/// <returns>
/// The <see cref="PlatformData"/>.
/// </returns>
private static PlatformData Read(PlatformData platformData, ProtoReader protoReader)
{
int num;
while ((num = protoReader.ReadFieldHeader()) > 0)
{
if (num != 1)
{
if (num != 2)
{
if (platformData == null)
{
var expr_164 = new PlatformData();
ProtoReader.NoteObject(expr_164, protoReader);
platformData = expr_164;
}
protoReader.SkipField();
}
else
{
if (platformData == null)
{
var expr_134 = new PlatformData();
ProtoReader.NoteObject(expr_134, protoReader);
platformData = expr_134;
}
byte[] array = ProtoReader.AppendBytes(platformData.Data, protoReader);
if (array != null)
{
platformData.Data = array;
}
}
}
else
{
if (platformData == null)
{
var expr_19 = new PlatformData();
ProtoReader.NoteObject(expr_19, protoReader);
platformData = expr_19;
}
int num2 = protoReader.ReadInt32();
var targetPlatform = TargetPlatform.Windows;
if (num2 != 0)
{
if (num2 != 1)
{
if (num2 != 2)
{
if (num2 != 3)
{
if (num2 != 4)
{
if (num2 != 5)
{
if (num2 != 6)
{
if (num2 != 7)
{
if (num2 != 8)
{
if (num2 != 9)
{
if (num2 != 10)
{
if (num2 != 11)
{
if (num2 != 12)
{
protoReader.ThrowEnumException(
typeof(TargetPlatform),
num2);
}
else
{
targetPlatform = TargetPlatform.RaspberryPi;
}
}
else
{
targetPlatform = TargetPlatform.WindowsPhone8;
}
}
else
{
targetPlatform = TargetPlatform.PlayStationMobile;
//.........这里部分代码省略.........
示例13: Read
/// <summary>
/// The read.
/// </summary>
/// <param name="mxPayload">
/// The mx payload.
/// </param>
/// <param name="protoReader">
/// The proto reader.
/// </param>
/// <returns>
/// The <see cref="MxPayload"/>.
/// </returns>
private static MxPayload Read(MxPayload mxPayload, ProtoReader protoReader)
{
int num;
while ((num = protoReader.ReadFieldHeader()) > 0)
{
if (num != 1)
{
if (mxPayload == null)
{
var expr_49 = new MxPayload();
ProtoReader.NoteObject(expr_49, protoReader);
mxPayload = expr_49;
}
protoReader.SkipField();
}
else
{
if (mxPayload == null)
{
var expr_19 = new MxPayload();
ProtoReader.NoteObject(expr_19, protoReader);
mxPayload = expr_19;
}
byte[] array = ProtoReader.AppendBytes(mxPayload.Data, protoReader);
if (array != null)
{
mxPayload.Data = array;
}
}
}
if (mxPayload == null)
{
var expr_71 = new MxPayload();
ProtoReader.NoteObject(expr_71, protoReader);
mxPayload = expr_71;
}
return mxPayload;
}