• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IProtoSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



IProtoSerializer类属于命名空间,在下文中一共展示了IProtoSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: FieldDecorator

 public FieldDecorator(Type forType, FieldInfo field, IProtoSerializer tail) : base(tail)
 {
     Helpers.DebugAssert(forType != null);
     Helpers.DebugAssert(field != null);
     this.forType = forType;
     this.field = field;
 }
开发者ID:Rasarack,项目名称:SteamBot,代码行数:7,代码来源:FieldDecorator.cs


示例2: MemberSpecifiedDecorator

 public MemberSpecifiedDecorator(MethodInfo getSpecified, MethodInfo setSpecified, IProtoSerializer tail)
     : base(tail)
 {
     if (getSpecified == null && setSpecified == null) throw new InvalidOperationException();
     this.getSpecified = getSpecified;
     this.setSpecified = setSpecified;
 }
开发者ID:Rasarack,项目名称:SteamBot,代码行数:7,代码来源:MemberSpecifiedDecorator.cs


示例3: 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


示例4: 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


示例5: ReflectedUriDecorator

        public ReflectedUriDecorator(Type type, ProtoBuf.Meta.TypeModel model, IProtoSerializer tail) : base(tail)
        {
            expectedType = type;

            absoluteUriProperty = expectedType.GetProperty("AbsoluteUri");
            typeConstructor = expectedType.GetConstructor(new Type[] { typeof(string) });
        }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:7,代码来源:ReflectedUriDecorator.cs


示例6: 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


示例7: 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


示例8: 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


示例9: PropertyDecorator

 public PropertyDecorator(Type forType, PropertyInfo property, IProtoSerializer tail) : base(tail)
 {
     Helpers.DebugAssert(forType != null);
     Helpers.DebugAssert(property != null);
     this.forType = forType;
     this.property = property;
     SanityCheck(property, tail, out readOptionsWriteValue, true);
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:8,代码来源:PropertyDecorator.cs


示例10: 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


示例11: PropertyDecorator

 public PropertyDecorator(TypeModel model, Type forType, PropertyInfo property, IProtoSerializer tail)
     : base(tail)
 {
     this.forType = forType;
     this.property = property;
     PropertyDecorator.SanityCheck(model, property, tail, out this.readOptionsWriteValue, true, true);
     this.shadowSetter = PropertyDecorator.GetShadowSetter(model, property);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:8,代码来源:PropertyDecorator.cs


示例12: DefaultValueDecorator

 public DefaultValueDecorator(object defaultValue, IProtoSerializer tail) : base(tail)
 {
     if (defaultValue == null) throw new ArgumentNullException("defaultValue");
     if (defaultValue.GetType() != tail.ExpectedType)
     {
         throw new ArgumentException("Default value is of incorrect type", "defaultValue");
     }
     this.defaultValue = defaultValue;
 }
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:9,代码来源:DefaultValueDecorator.cs


示例13: PrimitivesDecorator

        public PrimitivesDecorator(IProtoSerializer itemSerializer)
        {
            if (itemSerializer == null)
            {
                throw new ArgumentNullException("itemSerializer");
            }

            this.itemSerializer = itemSerializer;
        }
开发者ID:robb83,项目名称:Protocols,代码行数:9,代码来源:PrimitivesDecorator.cs


示例14: 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


示例15: BuildSerializer

 public static ProtoSerializer BuildSerializer(IProtoSerializer head)
 {
     Type type = head.ExpectedType;
     CompilerContext ctx = new CompilerContext(type, true, true);
     ctx.LoadValue(Local.InputValue);
     ctx.CastFromObject(type);
     ctx.WriteNullCheckedTail(type, head, null);
     ctx.Emit(OpCodes.Ret);
     return (ProtoSerializer)ctx.method.CreateDelegate(
         typeof(ProtoSerializer));
 }
开发者ID:KimimaroTsukimiya,项目名称:SteamBot-1,代码行数:11,代码来源:CompilerContext.cs


示例16: TypeSerializer

 public TypeSerializer(TypeModel model, Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType, MethodInfo factory)
 {
     Helpers.Sort(fieldNumbers, serializers);
     bool flag = false;
     for (int i = 1; i < fieldNumbers.Length; i++)
     {
         if (fieldNumbers[i] == fieldNumbers[i - 1])
         {
             throw new InvalidOperationException("Duplicate field-number detected; " + fieldNumbers[i].ToString() + " on: " + forType.FullName);
         }
         if (!flag && serializers[i].ExpectedType != forType)
         {
             flag = true;
         }
     }
     this.forType = forType;
     this.factory = factory;
     if (constructType == null)
     {
         constructType = forType;
     }
     else if (!forType.IsAssignableFrom(constructType))
     {
         throw new InvalidOperationException(forType.FullName + " cannot be assigned from " + constructType.FullName);
     }
     this.constructType = constructType;
     this.serializers = serializers;
     this.fieldNumbers = fieldNumbers;
     this.callbacks = callbacks;
     this.isRootType = isRootType;
     this.useConstructor = useConstructor;
     if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0)
     {
         baseCtorCallbacks = null;
     }
     this.baseCtorCallbacks = baseCtorCallbacks;
     if (Helpers.GetUnderlyingType(forType) != null)
     {
         throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
     }
     if (model.MapType(TypeSerializer.iextensible).IsAssignableFrom(forType))
     {
         if (forType.IsValueType || !isRootType || flag)
         {
             throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
         }
         this.isExtensible = true;
     }
     this.hasConstructor = (!constructType.IsAbstract && Helpers.GetConstructor(constructType, Helpers.EmptyTypes, true) != null);
     if (constructType != forType && useConstructor && !this.hasConstructor)
     {
         throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
     }
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:54,代码来源:TypeSerializer.cs


示例17: SanityCheck

 private static void SanityCheck(PropertyInfo property, IProtoSerializer tail, out bool writeValue, bool nonPublic) {
     if(property == null) throw new ArgumentNullException("property");
     
     writeValue = tail.ReturnsValue && (GetShadowSetter(property) != null || (property.CanWrite && Helpers.GetSetMethod(property, nonPublic) != null));
     if (!property.CanRead || Helpers.GetGetMethod(property, nonPublic) == null) throw new InvalidOperationException("Cannot serialize property without a get accessor");
     if (!writeValue && (!tail.RequiresOldValue || Helpers.IsValueType(tail.ExpectedType)))
     { // so we can't save the value, and the tail doesn't use it either... not helpful
         // or: can't write the value, so the struct value will be lost
         throw new InvalidOperationException("Cannot apply changes to property " + property.DeclaringType.FullName + "." + property.Name);
     }
 }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:11,代码来源:PropertyDecorator.cs


示例18: DefaultValueDecorator

        public DefaultValueDecorator(TypeModel model, object defaultValue, IProtoSerializer tail) : base(tail)
        {
            if (defaultValue == null) throw new ArgumentNullException("defaultValue");
            Type type = model.MapType(defaultValue.GetType());
            if (type != tail.ExpectedType
#if FEAT_IKVM // in IKVM, we'll have the default value as an underlying type
                && !(tail.ExpectedType.IsEnum && type == tail.ExpectedType.GetEnumUnderlyingType())
#endif
                )
            {
                throw new ArgumentException("Default value is of incorrect type", "defaultValue");
            }
            this.defaultValue = defaultValue;
        }
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:14,代码来源:DefaultValueDecorator.cs


示例19: SanityCheck

        private static void SanityCheck(PropertyInfo property, IProtoSerializer tail, out bool writeValue, bool nonPublic) {
            if(property == null) throw new ArgumentNullException("property");
            
            writeValue = tail.ReturnsValue && property.CanWrite && property.GetSetMethod(nonPublic) != null;
            if (!property.CanRead || property.GetGetMethod(nonPublic) == null) throw new InvalidOperationException("Cannot serialize property without a get accessor");
            if (!tail.RequiresOldValue && !writeValue)
            { // so we can't save the value, and the tail doesn't use it either... not helpful
                throw new InvalidOperationException("Cannot apply changes to property");
            }

            if (!writeValue && tail.ExpectedType.IsValueType)
            { // can't write the value, so the struct value will be lost
                throw new InvalidOperationException("Cannot apply changes to property");
            }
        }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:15,代码来源:PropertyDecorator.cs


示例20: NullDecorator

        public NullDecorator(IProtoSerializer tail) : base(tail)
        {
            if (!tail.ReturnsValue)
                throw new NotSupportedException("NullDecorator only supports implementations that return values");
            if(tail.ExpectedType.IsValueType)
            {
#if NO_GENERICS
                throw new NotSupportedException("NullDecorator cannot be used with a struct without generics support");
#else
                expectedType = typeof (Nullable<>).MakeGenericType(tail.ExpectedType);
#endif
            }
            else
            {
                expectedType = tail.ExpectedType;
            }

        }
开发者ID:techtronics,项目名称:mapreduce-net,代码行数:18,代码来源:NullDecorator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IProtocol类代码示例发布时间:2022-05-24
下一篇:
C# IProtectionService类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap