4 // Lluis Sanchez Gual (lluis@ideary.com)
6 // (C) 2003 Lluis Sanchez Gual
10 namespace System.Runtime.Serialization.Formatters.Binary
\r
12 internal class BinaryCommon
\r
14 // Header present in all binary serializations
\r
15 public static byte[] BinaryHeader = new Byte[] {0,1,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0};
\r
17 static Type[] _typeCodesToType;
\r
18 static byte[] _typeCodeMap;
\r
20 static BinaryCommon()
\r
22 _typeCodesToType = new Type [19];
\r
23 _typeCodesToType[(int)BinaryTypeCode.Boolean] = typeof (Boolean);
\r
24 _typeCodesToType[(int)BinaryTypeCode.Byte] = typeof (Byte);
\r
25 _typeCodesToType[(int)BinaryTypeCode.Char] = typeof (Char);
\r
26 _typeCodesToType[(int)BinaryTypeCode.TimeSpan] = typeof (TimeSpan);
\r
27 _typeCodesToType[(int)BinaryTypeCode.DateTime] = typeof (DateTime);
\r
28 _typeCodesToType[(int)BinaryTypeCode.Decimal] = typeof (Decimal);
\r
29 _typeCodesToType[(int)BinaryTypeCode.Double] = typeof (Double);
\r
30 _typeCodesToType[(int)BinaryTypeCode.Int16] = typeof (Int16);
\r
31 _typeCodesToType[(int)BinaryTypeCode.Int32] = typeof (Int32);
\r
32 _typeCodesToType[(int)BinaryTypeCode.Int64] = typeof (Int64);
\r
33 _typeCodesToType[(int)BinaryTypeCode.SByte] = typeof (SByte);
\r
34 _typeCodesToType[(int)BinaryTypeCode.Single] = typeof (Single);
\r
35 _typeCodesToType[(int)BinaryTypeCode.UInt16] = typeof (UInt16);
\r
36 _typeCodesToType[(int)BinaryTypeCode.UInt32] = typeof (UInt32);
\r
37 _typeCodesToType[(int)BinaryTypeCode.UInt64] = typeof (UInt64);
\r
38 _typeCodesToType[(int)BinaryTypeCode.Null] = null;
\r
39 _typeCodesToType[(int)BinaryTypeCode.String] = typeof (string);
\r
41 _typeCodeMap = new byte[30];
\r
42 _typeCodeMap[(int)TypeCode.Boolean] = (byte) BinaryTypeCode.Boolean;
\r
43 _typeCodeMap[(int)TypeCode.Byte] = (byte) BinaryTypeCode.Byte;
\r
44 _typeCodeMap[(int)TypeCode.Char] = (byte) BinaryTypeCode.Char;
\r
45 _typeCodeMap[(int)TypeCode.DateTime] = (byte) BinaryTypeCode.DateTime;
\r
46 _typeCodeMap[(int)TypeCode.Decimal] = (byte) BinaryTypeCode.Decimal;
\r
47 _typeCodeMap[(int)TypeCode.Double] = (byte) BinaryTypeCode.Double;
\r
48 _typeCodeMap[(int)TypeCode.Int16] = (byte) BinaryTypeCode.Int16;
\r
49 _typeCodeMap[(int)TypeCode.Int32] = (byte) BinaryTypeCode.Int32;
\r
50 _typeCodeMap[(int)TypeCode.Int64] = (byte) BinaryTypeCode.Int64;
\r
51 _typeCodeMap[(int)TypeCode.SByte] = (byte) BinaryTypeCode.SByte;
\r
52 _typeCodeMap[(int)TypeCode.Single] = (byte) BinaryTypeCode.Single;
\r
53 _typeCodeMap[(int)TypeCode.UInt16] = (byte) BinaryTypeCode.UInt16;
\r
54 _typeCodeMap[(int)TypeCode.UInt32] = (byte) BinaryTypeCode.UInt32;
\r
55 _typeCodeMap[(int)TypeCode.UInt64] = (byte) BinaryTypeCode.UInt64;
\r
56 _typeCodeMap[(int)TypeCode.String] = (byte) BinaryTypeCode.String;
\r
58 // TimeStamp does not have a TypeCode, so it is managed as a special
\r
59 // case in GetTypeCode()
\r
62 public static bool IsPrimitive (Type type)
\r
64 return type.IsPrimitive ||
\r
65 type == typeof (DateTime) ||
\r
66 type == typeof (TimeSpan) ||
\r
67 type == typeof (Decimal);
\r
70 public static byte GetTypeCode (Type type)
\r
72 if (type == typeof(TimeSpan)) return (byte) BinaryTypeCode.TimeSpan;
\r
73 else return _typeCodeMap [(int)Type.GetTypeCode(type)];
\r
76 public static Type GetTypeFromCode (int code)
\r
78 return _typeCodesToType [code];
\r
82 internal enum BinaryElement : byte
\r
92 BoxedPrimitiveTypeValue = 8,
99 ArrayOfPrimitiveType = 15,
109 internal enum TypeTag : byte
118 ArrayOfPrimitiveType = 7
121 internal enum ArrayStructure : byte
123 SingleDimensional = 0,
128 internal enum MethodFlags : byte
131 PrimitiveArguments = 2,
132 ArgumentsInSimpleArray = 4,
133 ArgumentsInMultiArray = 8,
134 ExcludeLogicalCallContext = 16,
135 IncludesLogicalCallContext = 64,
136 IncludesSignature = 128,
139 NeedsInfoArrayMask = 4 + 8 + 64 + 128
142 internal enum ReturnTypeTag : byte
\r
150 enum BinaryTypeCode : byte
\r