本文整理汇总了C#中WireType类的典型用法代码示例。如果您正苦于以下问题:C# WireType类的具体用法?C# WireType怎么用?C# WireType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WireType类属于命名空间,在下文中一共展示了WireType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ArrayDecorator
public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
: base(tail)
{
Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
this.itemType = arrayType.GetElementType();
#if NO_GENERICS
Type underlyingItemType = itemType;
#else
Type underlyingItemType = supportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType);
#endif
Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType, "invalid tail");
Helpers.DebugAssert(Tail.ExpectedType != model.MapType(typeof(byte)), "Should have used BlobSerializer");
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked) options |= OPTIONS_WritePacked;
if (overwriteList) options |= OPTIONS_OverwriteList;
if (supportNull) options |= OPTIONS_SupportNull;
this.arrayType = arrayType;
}
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:27,代码来源:ArrayDecorator.cs
示例2: ReadKey
/// <summary>
/// Reads and decodes a key from the Protobuf stream.
/// </summary>
/// <param name="stream">The input stream.</param>
/// <param name="fieldNumber">Decoded field number.</param>
/// <param name="wireType">Decoded wire type.</param>
public static void ReadKey(Stream stream, out uint fieldNumber,
out WireType wireType)
{
ulong value = ReadUnsignedVarint(stream);
wireType = (WireType)(value & 0x7ul);
fieldNumber = (uint)(value >> 3);
}
开发者ID:eigenein,项目名称:cloudy,代码行数:13,代码来源:ProtobufReader.cs
示例3: ArrayDecorator
public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
: base(tail)
{
this.itemType = arrayType.GetElementType();
Type arg_3E_0 = (!supportNull) ? (Helpers.GetUnderlyingType(this.itemType) ?? this.itemType) : this.itemType;
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0)
{
throw new ArgumentOutOfRangeException("fieldNumber");
}
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked)
{
throw new InvalidOperationException("Only simple data-types can use packed encoding");
}
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked)
{
this.options |= 1;
}
if (overwriteList)
{
this.options |= 2;
}
if (supportNull)
{
this.options |= 4;
}
this.arrayType = arrayType;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:33,代码来源:ArrayDecorator.cs
示例4: ListDecorator
public ListDecorator(Type declaredType, Type concreteType, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, bool returnList, bool overwriteList) : base(tail)
{
if (returnList) options |= OPTIONS_ReturnList;
if (overwriteList) options |= OPTIONS_OverwriteList;
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
if (writePacked) options |= OPTIONS_WritePacked;
this.packedWireType = packedWireType;
if (declaredType == null) throw new ArgumentNullException("declaredType");
if (declaredType.IsArray) throw new ArgumentException("Cannot treat arrays as lists", "declaredType");
this.declaredType = declaredType;
this.concreteType = concreteType;
// look for a public list.Add(typedObject) method
bool isList;
add = TypeModel.ResolveListAdd(declaredType, tail.ExpectedType, out isList);
if (isList)
{
options |= OPTIONS_IsList;
if (declaredType.FullName.StartsWith("System.Data.Linq.EntitySet`1[["))
{ // see http://stackoverflow.com/questions/6194639/entityset-is-there-a-sane-reason-that-ilist-add-doesnt-set-assigned
options |= OPTIONS_SuppressIList;
}
}
if (add == null) throw new InvalidOperationException();
}
开发者ID:KimimaroTsukimiya,项目名称:SteamBot-1,代码行数:32,代码来源:ListDecorator.cs
示例5: ListDecorator
public ListDecorator(Type declaredType, Type concreteType, IProtoSerializer tail, int packedFieldNumber, WireType packedWireType) : base(tail)
{
this.packedWireType = WireType.None;
if (packedFieldNumber != 0)
{
if (packedFieldNumber < 0) throw new ArgumentOutOfRangeException("packedFieldNumber");
switch(packedWireType)
{
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
case WireType.Variant:
break;
default:
throw new InvalidOperationException("Only simple data-types can use packed encoding");
}
this.packedFieldNumber = packedFieldNumber;
this.packedWireType = packedWireType;
}
if (declaredType == null) throw new ArgumentNullException("declaredType");
if (declaredType.IsArray) throw new ArgumentException("Cannot treat arrays as lists", "declaredType");
this.declaredType = declaredType;
this.concreteType = concreteType;
// look for a public list.Add(typedObject) method
add = TypeModel.ResolveListAdd(declaredType, tail.ExpectedType, out isList);
if (add == null) throw new InvalidOperationException();
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:28,代码来源:ListDecorator.cs
示例6: TagDecorator
public TagDecorator(int fieldNumber, WireType wireType, bool strict, IProtoSerializer tail)
: base(tail)
{
this.fieldNumber = fieldNumber;
this.wireType = wireType;
this.strict = strict;
}
开发者ID:tsuixl,项目名称:Frame,代码行数:7,代码来源:TagDecorator.cs
示例7: ImmutableCollectionDecorator
internal ImmutableCollectionDecorator(TypeModel model, Type declaredType, Type concreteType, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, bool returnList, bool overwriteList, bool supportNull, MethodInfo builderFactory, MethodInfo add, MethodInfo addRange, MethodInfo finish)
: base(model, declaredType, concreteType, tail, fieldNumber, writePacked, packedWireType, returnList, overwriteList, supportNull)
{
this.builderFactory = builderFactory;
this.add = add;
this.addRange = addRange;
this.finish = finish;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:8,代码来源:ImmutableCollectionDecorator.cs
示例8: EmitReadList
internal static void EmitReadList(ProtoBuf.Compiler.CompilerContext ctx, Compiler.Local list, IProtoSerializer tail, MethodInfo add, WireType packedWireType)
{
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, typeof(int)))
{
Compiler.CodeLabel readPacked = packedWireType == WireType.None ? new Compiler.CodeLabel() : ctx.DefineLabel();
if (packedWireType != WireType.None)
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("WireType"));
ctx.LoadValue((int)WireType.String);
ctx.BranchIfEqual(readPacked, false);
}
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("FieldNumber"));
ctx.StoreValue(fieldNumber);
Compiler.CodeLabel @continue = ctx.DefineLabel();
ctx.MarkLabel(@continue);
EmitReadAndAddItem(ctx, list, tail, add);
ctx.LoadReaderWriter();
ctx.LoadValue(fieldNumber);
ctx.EmitCall(typeof(ProtoReader).GetMethod("TryReadFieldHeader"));
ctx.BranchIfTrue(@continue, false);
if (packedWireType != WireType.None)
{
Compiler.CodeLabel allDone = ctx.DefineLabel();
ctx.Branch(allDone, false);
ctx.MarkLabel(readPacked);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("StartSubItem"));
Compiler.CodeLabel testForData = ctx.DefineLabel(), noMoreData = ctx.DefineLabel();
ctx.MarkLabel(testForData);
ctx.LoadValue((int)packedWireType);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("HasSubValue"));
ctx.BranchIfFalse(noMoreData, false);
EmitReadAndAddItem(ctx, list, tail, add);
ctx.Branch(testForData, false);
ctx.MarkLabel(noMoreData);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("EndSubItem"));
ctx.MarkLabel(allDone);
}
}
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:55,代码来源:ListDecorator.cs
示例9: Skip
/// <summary>
/// Skips the field with the specified wire type.
/// </summary>
public static void Skip(Stream stream, WireType wireType)
{
Action<Stream> skipAction;
if (!Cache.TryGetValue(wireType, out skipAction))
{
throw new KeyNotFoundException(String.Format(
"The wire type could not be skipped, because there is no appropriate method: {0}",
wireType));
}
skipAction(stream);
}
开发者ID:eigenein,项目名称:cloudy,代码行数:14,代码来源:UnknownFieldSkipHelper.cs
示例10: CanPack
internal static bool CanPack(WireType wireType)
{
switch (wireType)
{
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
case WireType.Variant:
return true;
default:
return false;
}
}
开发者ID:KimimaroTsukimiya,项目名称:SteamBot-1,代码行数:13,代码来源:ListDecorator.cs
示例11: ProtoWriter
/// <summary>
/// Creates a new writer against a stream
/// </summary>
/// <param name="dest">The destination stream</param>
/// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to serialize sub-objects</param>
/// <param name="context">Additional context about this serialization operation</param>
public ProtoWriter(Stream dest, TypeModel model, SerializationContext context)
{
if (dest == null) throw new ArgumentNullException("dest");
if (!dest.CanWrite) throw new ArgumentException("Cannot write to stream", "dest");
//if (model == null) throw new ArgumentNullException("model");
this.dest = dest;
this.ioBuffer = BufferPool.GetBuffer();
this.model = model;
this.wireType = WireType.None;
if (context == null) { context = SerializationContext.Default; }
else { context.Freeze(); }
this.context = context;
}
开发者ID:helios57,项目名称:anrl,代码行数:19,代码来源:ProtoWriter.cs
示例12: WriteFieldHeader
/// <summary>
/// Writes a field-header, indicating the format of the next data we plan to write.
/// </summary>
public static void WriteFieldHeader(int fieldNumber, WireType wireType, ProtoWriter writer) {
if (writer.wireType != WireType.None) throw new InvalidOperationException("Cannot write a " + wireType
+ " header until the " + writer.wireType + " data has been written");
if(fieldNumber < 0) throw new ArgumentOutOfRangeException("fieldNumber");
#if DEBUG
switch (wireType)
{ // validate requested header-type
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.String:
case WireType.StartGroup:
case WireType.SignedVariant:
case WireType.Variant:
break; // fine
case WireType.None:
case WireType.EndGroup:
default:
throw new ArgumentException("Invalid wire-type: " + wireType, "wireType");
}
#endif
if (writer.packedFieldNumber == 0) {
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
WriteHeaderCore(fieldNumber, wireType, writer);
}
else if (writer.packedFieldNumber == fieldNumber)
{ // we'll set things up, but note we *don't* actually write the header here
switch (wireType)
{
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.Variant:
case WireType.SignedVariant:
break; // fine
default:
throw new InvalidOperationException("Wire-type cannot be encoded as packed: " + wireType);
}
writer.fieldNumber = fieldNumber;
writer.wireType = wireType;
}
else
{
throw new InvalidOperationException("Field mismatch during packed encoding; expected " + writer.packedFieldNumber + " but received " + fieldNumber);
}
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:48,代码来源:ProtoWriter.cs
示例13: ArrayDecorator
public ArrayDecorator(IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList)
: base(tail)
{
Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array");
Helpers.DebugAssert(arrayType.GetElementType() == Tail.ExpectedType, "invalid tail");
Helpers.DebugAssert(Tail.ExpectedType != typeof(byte), "Should have used BlobSerializer");
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked) options |= OPTIONS_WritePacked;
if (overwriteList) options |= OPTIONS_OverwriteList;
this.arrayType = arrayType;
this.itemType = Tail.ExpectedType;
}
开发者ID:helios57,项目名称:anrl,代码行数:20,代码来源:ArrayDecorator.cs
示例14: ArrayDecorator
public ArrayDecorator(IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType,
Type arrayType, bool overwriteList, bool supportNull, bool asReference, bool nested)
: base(tail)
{
Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
//Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
if (!arrayType.IsArray /*|| arrayType.GetArrayRank() != 1*/)
{
throw new Exception("Temporary exception");
}
this.itemType = arrayType.GetElementType();
#if NO_GENERICS
Type underlyingItemType = itemType;
#else
Type underlyingItemType = supportNull ? itemType : (Nullable.GetUnderlyingType(itemType) ?? itemType);
#endif
Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType || (underlyingItemType.IsInterface && Tail.ExpectedType == typeof(object)), "invalid tail");
Helpers.DebugAssert(Tail.ExpectedType != typeof(byte), "Should have used BlobSerializer");
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked) options |= OPTIONS_WritePacked;
if (overwriteList) options |= OPTIONS_OverwriteList;
if (supportNull) options |= OPTIONS_SupportNull;
if (asReference) options |= OPTIONS_AsReference;
if (asReference && writePacked) throw new InvalidOperationException("Cannot be packed and AsReference (not supported yet)");
if (asReference && overwriteList) throw new InvalidOperationException("Cannot be overwriteList and AsReference (not supported yet)");
this.arrayType = arrayType;
this.nested = nested;
}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:39,代码来源:ArrayDecorator.cs
示例15: ArrayDecorator
public ArrayDecorator(IProtoSerializer tail, int packedFieldNumber, WireType packedWireType)
: base(tail)
{
Helpers.DebugAssert(Tail.ExpectedType != typeof(byte), "Should have used BlobSerializer");
this.packedWireType = WireType.None;
if (packedFieldNumber != 0)
{
if (packedFieldNumber < 0) throw new ArgumentOutOfRangeException("packedFieldNumber");
switch (packedWireType)
{
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
case WireType.Variant:
break;
default:
throw new ArgumentException("Packed buffers are not supported for wire-type: " + packedWireType, "packedFieldNumber");
}
this.packedFieldNumber = packedFieldNumber;
this.packedWireType = packedWireType;
}
this.itemType = Tail.ExpectedType;
this.arrayType = Helpers.MakeArrayType(itemType);
}
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:24,代码来源:ArrayDecorator.cs
示例16: GetNestedSerializer
private IProtoSerializer GetNestedSerializer(BasicList nestedHierarchy, out WireType wireType)
{
IProtoSerializer ser = null;
int listCount = nestedHierarchy.Count;
wireType = WireType.None;
bool hasAutoDynamicHandling = HasAutoDynamicHandling(nestedHierarchy);
for (int i = listCount - 1; i >= 0; i--)
{
NestedItem item = (NestedItem)nestedHierarchy[i];
if (item.ItemType == null)
{
bool isDynamic = dynamicType;
bool requiresDynamic = item.Type.IsInterface || item.Type == typeof (object);
if (!isDynamic && autoDynamicType && requiresDynamic)
{
isDynamic = true;
}
else if (hasAutoDynamicHandling && requiresDynamic)
{
// for now just set isDynamic to true
isDynamic = true;
}
ser = TryGetCoreSerializer(model, dataFormat, item.Type, out wireType, asReference, /*dynamicType*/isDynamic, OverwriteList, false, SupportNull);
if (ser == null) throw new InvalidOperationException("No serializer defined for type: " + item.Type.FullName);
if (listCount == 1)
{
ser = new TagDecorator(fieldNumber, wireType, IsStrict, ser);
}
}
else
{
if (SupportNull)
{
if (IsPacked)
{
throw new NotSupportedException("Packed encodings cannot support null values");
}
ser = new TagDecorator(NullDecorator.Tag, wireType, IsStrict, ser);
ser = new NullDecorator(ser);
ser = new TagDecorator(fieldNumber, WireType.StartGroup, false, ser);
}
else
{
ser = new TagDecorator(fieldNumber, wireType, IsStrict, ser);
}
bool nested = listCount > 2 && i >= 1;
if (item.Type.IsArray)
{
ser = new ArrayDecorator(ser, fieldNumber, IsPacked, wireType, item.Type, OverwriteList, SupportNull, AsReference, nested);
}
else
{
ser = new ListDecorator(item.Type, item.DefaultType, ser, fieldNumber, IsPacked, wireType,
member == null || PropertyDecorator.CanWrite(member), OverwriteList,
SupportNull, AsReference, nested, isValueMemberForCollectionBasedTypes);
}
}
}
return ser;
}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:68,代码来源:ValueMember.cs
示例17: MakeTag
/// <summary>
/// Makes a tag value given a field number and wire type.
/// </summary>
public static uint MakeTag(int fieldNumber, WireType wireType)
{
return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
}
开发者ID:2php,项目名称:protobuf,代码行数:7,代码来源:WireFormat.cs
示例18: TryReadFieldHeader
/// <summary>
/// Looks ahead to see whether the next field in the stream is what we expect
/// (typically; what we've just finished reading - for example ot read successive list items)
/// </summary>
public bool TryReadFieldHeader(int field)
{
// check for virtual end of stream
if (blockEnd <= position || wireType == WireType.EndGroup) { return false; }
uint tag;
int read = TryReadUInt32VariantWithoutMoving(false, out tag);
WireType tmpWireType; // need to catch this to exclude (early) any "end group" tokens
if (read > 0 && ((int)tag >> 3) == field
&& (tmpWireType = (WireType)(tag & 7)) != WireType.EndGroup)
{
wireType = tmpWireType;
fieldNumber = field;
position += read;
ioIndex += read;
available -= read;
return true;
}
return false;
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:23,代码来源:ProtoReader.cs
示例19: Stream
private void Stream(ArrayList data, WireType wireType)
{
data.Add(new Snoop.Data.ClassSeparator(typeof(WireType)));
data.Add(new Snoop.Data.Object("Actual value", wireType.Conduit));
data.Add(new Snoop.Data.Object("Is in use", wireType.Insulation));
data.Add(new Snoop.Data.Bool("Is in use", wireType.IsInUse));
data.Add(new Snoop.Data.Object("Max size", wireType.MaxSize));
data.Add(new Snoop.Data.Double("Neutral multiplier", wireType.NeutralMultiplier));
data.Add(new Snoop.Data.Bool("Neutral required", wireType.NeutralRequired));
data.Add(new Snoop.Data.String("Neutral size", wireType.NeutralSize.ToString()));
data.Add(new Snoop.Data.Object("Temperature rating", wireType.TemperatureRating));
data.Add(new Snoop.Data.Object("Wire material", wireType.WireMaterial));
}
开发者ID:halad,项目名称:RevitLookup,代码行数:14,代码来源:CollectorExtSymbol.cs
示例20: WriteKey
/// <summary>
/// Encodes and writes the key.
/// </summary>
public static void WriteKey(Stream stream, uint fieldNumber, WireType wireType)
{
WriteUnsignedVarint(stream, ((fieldNumber) << 3) | (uint)wireType);
}
开发者ID:eigenein,项目名称:cloudy,代码行数:7,代码来源:ProtobufWriter.cs
注:本文中的WireType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论