当前位置: 首页>>代码示例>>C#>>正文


C# WireType类代码示例

本文整理汇总了C#中WireType的典型用法代码示例。如果您正苦于以下问题:C# WireType类的具体用法?C# WireType怎么用?C# WireType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WireType类属于命名空间,在下文中一共展示了WireType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的WireType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。