예제 #1
0
        public override bool Read(DeserializationContext context, out Object outVal)
        {
            uint id    = context.Reader.ReadUInt32();
            uint count = context.Reader.ReadUInt32();

            BinaryPrimitiveTypeCode typeCode = (BinaryPrimitiveTypeCode)context.Reader.ReadByte();

            return(Read(context, id, count, typeCode, out outVal));
        }
예제 #2
0
        public static Type GetPrimitiveType(BinaryPrimitiveTypeCode typeCode)
        {
            switch (typeCode)
            {
            case BinaryPrimitiveTypeCode.Boolean:
                return(typeof(bool));

            case BinaryPrimitiveTypeCode.Byte:
                return(typeof(byte));

            case BinaryPrimitiveTypeCode.Char:
                return(typeof(char));

            case BinaryPrimitiveTypeCode.Decimal:
                return(typeof(decimal));

            case BinaryPrimitiveTypeCode.Double:
                return(typeof(double));

            case BinaryPrimitiveTypeCode.Int16:
                return(typeof(Int16));

            case BinaryPrimitiveTypeCode.Int32:
                return(typeof(Int32));

            case BinaryPrimitiveTypeCode.Int64:
                return(typeof(Int64));

            case BinaryPrimitiveTypeCode.SByte:
                return(typeof(sbyte));

            case BinaryPrimitiveTypeCode.Single:
                return(typeof(Single));

            case BinaryPrimitiveTypeCode.TimeSpan:
                return(typeof(TimeSpan));

            case BinaryPrimitiveTypeCode.DateTime:
                return(typeof(DateTime));

            case BinaryPrimitiveTypeCode.UInt16:
                return(typeof(UInt16));

            case BinaryPrimitiveTypeCode.UInt32:
                return(typeof(UInt32));

            case BinaryPrimitiveTypeCode.UInt64:
                return(typeof(UInt64));

            case BinaryPrimitiveTypeCode.String:
                return(typeof(String));

            default:
                throw new SerializationException("unknown primitive type code:" + typeCode);
            }
        }
예제 #3
0
        public static Object ReadPrimitiveType(DeserializationContext context, BinaryPrimitiveTypeCode typeCode)
        {
            switch (typeCode)
            {
            case BinaryPrimitiveTypeCode.Boolean:
                return(context.Reader.ReadBoolean());

            case BinaryPrimitiveTypeCode.Byte:
                return(context.Reader.ReadByte());

            case BinaryPrimitiveTypeCode.Char:
                return(context.Reader.ReadChar());

            case BinaryPrimitiveTypeCode.Decimal:
                return(Decimal.Parse(context.Reader.ReadString()));

            case BinaryPrimitiveTypeCode.Double:
                return(context.Reader.ReadDouble());

            case BinaryPrimitiveTypeCode.Int16:
                return(context.Reader.ReadInt16());

            case BinaryPrimitiveTypeCode.Int32:
                return(context.Reader.ReadInt32());

            case BinaryPrimitiveTypeCode.Int64:
                return(context.Reader.ReadInt64());

            case BinaryPrimitiveTypeCode.SByte:
                return(context.Reader.ReadSByte());

            case BinaryPrimitiveTypeCode.Single:
                return(context.Reader.ReadSingle());

            case BinaryPrimitiveTypeCode.TimeSpan:
                return(new TimeSpan(context.Reader.ReadInt64()));

            case BinaryPrimitiveTypeCode.DateTime:
                return(new DateTime(context.Reader.ReadInt64()));

            case BinaryPrimitiveTypeCode.UInt16:
                return(context.Reader.ReadUInt16());

            case BinaryPrimitiveTypeCode.UInt32:
                return(context.Reader.ReadUInt32());

            case BinaryPrimitiveTypeCode.UInt64:
                return(context.Reader.ReadUInt64());

            case BinaryPrimitiveTypeCode.String:
                return(context.Reader.ReadString());

            default:
                throw new SerializationException("unknown primitive type code:" + typeCode);
            }
        }
	public static Type GetPrimitiveType(BinaryPrimitiveTypeCode typeCode)
	{
		switch(typeCode) 
		{
			case BinaryPrimitiveTypeCode.Boolean:
				return typeof(bool);
			case BinaryPrimitiveTypeCode.Byte:
				return typeof(byte);
			case BinaryPrimitiveTypeCode.Char:
				return typeof(char);
			case BinaryPrimitiveTypeCode.Decimal:
				return typeof(decimal);
			case BinaryPrimitiveTypeCode.Double:
				return typeof(double);
			case BinaryPrimitiveTypeCode.Int16:
				return typeof(Int16);
			case BinaryPrimitiveTypeCode.Int32:
				return typeof(Int32);
			case BinaryPrimitiveTypeCode.Int64:
				return typeof(Int64);
			case BinaryPrimitiveTypeCode.SByte:
				return typeof(sbyte);
			case BinaryPrimitiveTypeCode.Single:
				return typeof(Single);
			case BinaryPrimitiveTypeCode.TimeSpan:
				return typeof(TimeSpan);
			case BinaryPrimitiveTypeCode.DateTime:
				return typeof(DateTime);
			case BinaryPrimitiveTypeCode.UInt16:
				return typeof(UInt16);
			case BinaryPrimitiveTypeCode.UInt32:
				return typeof(UInt32);
			case BinaryPrimitiveTypeCode.UInt64:
				return typeof(UInt64);
			case BinaryPrimitiveTypeCode.String:
				return typeof(String);

			default:
				throw new SerializationException("unknown primitive type code:"+typeCode);
		}
	}
	public static void ReadPrimitiveTypeArray(DeserializationContext context, BinaryPrimitiveTypeCode typeCode, Array array) 
	{
		int count = array.GetLength(0);
		switch(typeCode) 
		{
			case BinaryPrimitiveTypeCode.Boolean:
				bool[] boolArray = (bool[]) array;
				for(int i = 0; i < count; i++) {
					boolArray[i] = context.Reader.ReadBoolean();
				}
				break;

			case BinaryPrimitiveTypeCode.Byte:
				byte[] byteArray = (byte[]) array;
				for(int i = 0; i < count; i++) {
					byteArray[i] = context.Reader.ReadByte();
				}
				break;

			case BinaryPrimitiveTypeCode.Char:
				char[] charArray = (char[]) array;
				for(int i = 0; i < count; i++) {
					charArray[i] = context.Reader.ReadChar();
				}
				break;

			case BinaryPrimitiveTypeCode.Decimal:
				decimal[] decimalArray = (decimal[]) array;
				for(int i = 0; i < count; i++) {
					decimalArray[i] = Decimal.Parse(context.Reader.ReadString());
				}
				break;

			case BinaryPrimitiveTypeCode.Double:
				double[] doubleArray = (double[]) array;
				for(int i = 0; i < count; i++) {
					doubleArray[i] = context.Reader.ReadDouble();
				}
				break;

			case BinaryPrimitiveTypeCode.Int16:
				short[] shortArray = (short[]) array;
				for(int i = 0; i < count; i++) {
					shortArray[i] = context.Reader.ReadInt16();
				}
				break;

			case BinaryPrimitiveTypeCode.Int32:
				int[] intArray = (int[]) array;
				for(int i = 0; i < count; i++) {
					intArray[i] = context.Reader.ReadInt32();
				}
				break;

			case BinaryPrimitiveTypeCode.Int64:
				long[] longArray = (long[]) array;
				for(int i = 0; i < count; i++) {
					longArray[i] = context.Reader.ReadInt64();
				}
				break;

			case BinaryPrimitiveTypeCode.SByte:
				sbyte[] sbyteArray = (sbyte[]) array;
				for(int i = 0; i < count; i++) {
					sbyteArray[i] = context.Reader.ReadSByte();
				}
				break;

			case BinaryPrimitiveTypeCode.Single:
				float[] singleArray = (float[]) array;
				for(int i = 0; i < count; i++) {
					singleArray[i] = context.Reader.ReadChar();
				}
				break;

			case BinaryPrimitiveTypeCode.TimeSpan:
				TimeSpan[] tsArray = (TimeSpan[]) array;
				for(int i = 0; i < count; i++) {
					tsArray[i] = new TimeSpan(context.Reader.ReadInt64());
				}
				break;

			case BinaryPrimitiveTypeCode.DateTime:
				DateTime[] dtArray = (DateTime[]) array;
				for(int i = 0; i < count; i++) {
					dtArray[i] = new DateTime(context.Reader.ReadInt64());
				}
				break;

			case BinaryPrimitiveTypeCode.UInt16:
				ushort[] ushortArray = (ushort[]) array;
				for(int i = 0; i < count; i++) {
					ushortArray[i] = context.Reader.ReadUInt16();

				}
				break;

			case BinaryPrimitiveTypeCode.UInt32:
				uint[] uintArray = (uint[]) array;
				for(int i = 0; i < count; i++) {
					uintArray[i] = context.Reader.ReadUInt32();
				}
				break;

			case BinaryPrimitiveTypeCode.UInt64:
				ulong[] ulongArray = (ulong[]) array;
				for(int i = 0; i < count; i++) {
					ulongArray[i] = context.Reader.ReadUInt64();
				}
				break;

			case BinaryPrimitiveTypeCode.String:
				string[] stringArray = (string[]) array;
				for(int i = 0; i < count; i++) {
					stringArray[i] = context.Reader.ReadString();
				}
				break;

			default:
				throw new SerializationException("unknown primitive type code:"+typeCode);
		}
	}
	public static Object ReadPrimitiveType(DeserializationContext context, BinaryPrimitiveTypeCode typeCode) 
	{
		switch(typeCode) 
		{
			case BinaryPrimitiveTypeCode.Boolean:
				return context.Reader.ReadBoolean();
			case BinaryPrimitiveTypeCode.Byte:
				return context.Reader.ReadByte();
			case BinaryPrimitiveTypeCode.Char:
				return context.Reader.ReadChar();
			case BinaryPrimitiveTypeCode.Decimal:
				return Decimal.Parse(context.Reader.ReadString());
			case BinaryPrimitiveTypeCode.Double:
				return context.Reader.ReadDouble();
			case BinaryPrimitiveTypeCode.Int16:
				return context.Reader.ReadInt16();
			case BinaryPrimitiveTypeCode.Int32:
				return context.Reader.ReadInt32();
			case BinaryPrimitiveTypeCode.Int64:
				return context.Reader.ReadInt64();
			case BinaryPrimitiveTypeCode.SByte:
				return context.Reader.ReadSByte();
			case BinaryPrimitiveTypeCode.Single:
				return context.Reader.ReadSingle();
			case BinaryPrimitiveTypeCode.TimeSpan:
				return new TimeSpan(context.Reader.ReadInt64());
			case BinaryPrimitiveTypeCode.DateTime:
				return new DateTime(context.Reader.ReadInt64());
			case BinaryPrimitiveTypeCode.UInt16:
				return context.Reader.ReadUInt16();
			case BinaryPrimitiveTypeCode.UInt32:
				return context.Reader.ReadUInt32();
			case BinaryPrimitiveTypeCode.UInt64:
				return context.Reader.ReadUInt64();
			case BinaryPrimitiveTypeCode.String:
				return context.Reader.ReadString();

			default:
				throw new SerializationException("unknown primitive type code:"+typeCode);
		}
	}
	public TypeSpecification(BinaryPrimitiveTypeCode primitive) 
	{
		mPrimitiveType = primitive;
		mTag = BinaryTypeTag.PrimitiveType;
	}
		public PrimitiveWriter(BinaryPrimitiveTypeCode code, String fieldName)
				{
					this.code = code;
					this.fieldName = fieldName;
				}
		// Constructor.
		public PrimitiveWriter(BinaryPrimitiveTypeCode code)
				{
					this.code = code;
					this.fieldName = "m_value";
				}
예제 #10
0
        public static TypeSpecification ReadTypeSpec(DeserializationContext context, BinaryTypeTag typeTag)
        {
            switch (typeTag)
            {
            case BinaryTypeTag.PrimitiveType:
            case BinaryTypeTag.ArrayOfPrimitiveType:
                BinaryPrimitiveTypeCode typeCode = (BinaryPrimitiveTypeCode)context.Reader.ReadByte();
                switch (typeCode)
                {
                case BinaryPrimitiveTypeCode.Boolean:
                    return(sBooleanSpec);

                case BinaryPrimitiveTypeCode.Byte:
                    return(sByteSpec);

                case BinaryPrimitiveTypeCode.Char:
                    return(sCharSpec);

                case BinaryPrimitiveTypeCode.Decimal:
                    return(sDecimalSpec);

                case BinaryPrimitiveTypeCode.Double:
                    return(sDoubleSpec);

                case BinaryPrimitiveTypeCode.Int16:
                    return(sInt16Spec);

                case BinaryPrimitiveTypeCode.Int32:
                    return(sInt32Spec);

                case BinaryPrimitiveTypeCode.Int64:
                    return(sInt64Spec);

                case BinaryPrimitiveTypeCode.SByte:
                    return(sSByteSpec);

                case BinaryPrimitiveTypeCode.Single:
                    return(sSingleSpec);

                case BinaryPrimitiveTypeCode.TimeSpan:
                    return(sTimeSpanSpec);

                case BinaryPrimitiveTypeCode.DateTime:
                    return(sDateTimeSpec);

                case BinaryPrimitiveTypeCode.UInt16:
                    return(sUInt16Spec);

                case BinaryPrimitiveTypeCode.UInt32:
                    return(sUInt32Spec);

                case BinaryPrimitiveTypeCode.UInt64:
                    return(sUInt64Spec);

                case BinaryPrimitiveTypeCode.String:
                    return(sStringArraySpec);

                default:
                    throw new SerializationException("unknown primitive type code:" + typeCode);
                }
                throw new SerializationException("unknown primitive type code:" + typeCode);

            case BinaryTypeTag.RuntimeType:
                return(new TypeSpecification(context.Reader.ReadString()));

            case BinaryTypeTag.GenericType:
                String typeName = context.Reader.ReadString();
                uint   assId    = context.Reader.ReadUInt32();
                return(new TypeSpecification(typeName, assId));

            case BinaryTypeTag.String:
                return(sStringSpecObject);

            case BinaryTypeTag.ObjectType:
                return(sObjectSpec);

            case BinaryTypeTag.ArrayOfString:
                return(sStringArraySpec);

            case BinaryTypeTag.ArrayOfObject:
                return(sObjectArraySpec);

            default:
                return(null);
            }
        }
예제 #11
0
        internal static Array ReadPrimitiveTypeArray(DeserializationContext context, BinaryPrimitiveTypeCode typeCode, int count)
        {
            switch (typeCode)
            {
            case BinaryPrimitiveTypeCode.Boolean:
                bool[] boolArray = new bool[count];
                for (int i = 0; i < count; i++)
                {
                    boolArray[i] = context.Reader.ReadBoolean();
                }
                return(boolArray);

            case BinaryPrimitiveTypeCode.Byte:
                byte[] byteArray = context.Reader.ReadBytes(count);
                return(byteArray);

            case BinaryPrimitiveTypeCode.Char:
                char[] charArray = context.Reader.ReadChars(count);
                return(charArray);

            case BinaryPrimitiveTypeCode.Decimal:
                decimal[] decimalArray = new decimal[count];
                for (int i = 0; i < count; i++)
                {
                    decimalArray[i] = Decimal.Parse(context.Reader.ReadString());
                }
                return(decimalArray);

            case BinaryPrimitiveTypeCode.Double:
                double[] doubleArray = new double[count];
                for (int i = 0; i < count; i++)
                {
                    doubleArray[i] = context.Reader.ReadDouble();
                }
                return(doubleArray);

            case BinaryPrimitiveTypeCode.Int16:
                short[] shortArray = new short[count];
                for (int i = 0; i < count; i++)
                {
                    shortArray[i] = context.Reader.ReadInt16();
                }
                return(shortArray);

            case BinaryPrimitiveTypeCode.Int32:
                int[] intArray = new int[count];
                for (int i = 0; i < count; i++)
                {
                    intArray[i] = context.Reader.ReadInt32();
                }
                return(intArray);

            case BinaryPrimitiveTypeCode.Int64:
                long[] longArray = new long[count];
                for (int i = 0; i < count; i++)
                {
                    longArray[i] = context.Reader.ReadInt64();
                }
                return(longArray);

            case BinaryPrimitiveTypeCode.SByte:
                sbyte[] sbyteArray = new sbyte[count];
                for (int i = 0; i < count; i++)
                {
                    sbyteArray[i] = context.Reader.ReadSByte();
                }
                return(sbyteArray);

            case BinaryPrimitiveTypeCode.Single:
                float[] singleArray = new float[count];
                for (int i = 0; i < count; i++)
                {
                    singleArray[i] = context.Reader.ReadChar();
                }
                return(singleArray);

            case BinaryPrimitiveTypeCode.TimeSpan:
                TimeSpan[] tsArray = new TimeSpan[count];
                for (int i = 0; i < count; i++)
                {
                    tsArray[i] = new TimeSpan(context.Reader.ReadInt64());
                }
                return(tsArray);

            case BinaryPrimitiveTypeCode.DateTime:
                DateTime[] dtArray = new DateTime[count];
                for (int i = 0; i < count; i++)
                {
                    dtArray[i] = new DateTime(context.Reader.ReadInt64());
                }
                return(dtArray);

            case BinaryPrimitiveTypeCode.UInt16:
                ushort[] ushortArray = new ushort[count];
                for (int i = 0; i < count; i++)
                {
                    ushortArray[i] = context.Reader.ReadUInt16();
                }
                return(ushortArray);

            case BinaryPrimitiveTypeCode.UInt32:
                uint[] uintArray = new uint[count];
                for (int i = 0; i < count; i++)
                {
                    uintArray[i] = context.Reader.ReadUInt32();
                }
                return(uintArray);

            case BinaryPrimitiveTypeCode.UInt64:
                ulong[] ulongArray = new ulong[count];
                for (int i = 0; i < count; i++)
                {
                    ulongArray[i] = context.Reader.ReadUInt64();
                }
                return(ulongArray);

            case BinaryPrimitiveTypeCode.String:
                string[] stringArray = new string[count];
                for (int i = 0; i < count; i++)
                {
                    stringArray[i] = context.Reader.ReadString();
                }
                return(stringArray);

            default:
                throw new SerializationException("unknown primitive type code:" + typeCode);
            }
        }
예제 #12
0
 public TypeSpecification(BinaryPrimitiveTypeCode primitive)
 {
     mPrimitiveType = primitive;
     mTag           = BinaryTypeTag.PrimitiveType;
 }