public void Pack(Packer stream, object obj) { var e = obj as System.Enum; var type = e.GetType().GetEnumUnderlyingType(); if (type == typeof(int)) { stream.WriteByte((byte)TypeValue.Int32); var ser = new Int32Serializer(); ser.Pack(stream, obj); } else if (type == typeof(short)) { stream.WriteByte((byte)TypeValue.Int16); var ser = new Int16Serializer(); ser.Pack(stream, obj); } else if (type == typeof(long)) { stream.WriteByte((byte)TypeValue.Int64); var ser = new Int64Serializer(); ser.Pack(stream, obj); } else if (type == typeof(uint)) { stream.WriteByte((byte)TypeValue.UInt32); var ser = new UInt32Serializer(); ser.Pack(stream, obj); } else if (type == typeof(ushort)) { stream.WriteByte((byte)TypeValue.UInt16); var ser = new UInt16Serializer(); ser.Pack(stream, obj); } else if (type == typeof(ulong)) { stream.WriteByte((byte)TypeValue.UInt64); var ser = new UInt64Serializer(); ser.Pack(stream, obj); } else if (type == typeof(byte)) { stream.WriteByte((byte)TypeValue.Byte); var ser = new ByteSerializer(); ser.Pack(stream, obj); } else if (type == typeof(sbyte)) { stream.WriteByte((byte)TypeValue.SByte); var ser = new SByteSerializer(); ser.Pack(stream, obj); } else { stream.WriteByte((byte)TypeValue.String); var ser = new StringSerializer(); ser.Pack(stream, obj); } }
public void Pack(Packer packer, object obj) { var int32 = new Int32Serializer(); int32.Pack(packer, (int)(RPCId)obj); }
public void Pack(Packer packer, object obj) { var arr = (IList)obj; var type = arr.GetType(); var int32 = new Int32Serializer(); int32.Pack(packer, arr.Count); if (type.IsArray == true) { var rank = type.GetArrayRank(); if (rank > 1) { packer.WriteByte(2); } else { packer.WriteByte(1); } int32.Pack(packer, packer.GetMetaTypeId(type.GetElementType())); if (rank > 1) { int32.Pack(packer, rank); var arrData = (System.Array)arr; for (int j = 0; j < rank; ++j) { int32.Pack(packer, arrData.GetLength(j)); } void WrapDimension(int[] ids, int currentDimension) { if (currentDimension == rank) { packer.PackInternal(arrData.GetValue(ids)); } else { for (int i = 0, length = arrData.GetLength(currentDimension); i < length; i++) { ids[currentDimension] = i; WrapDimension(ids, currentDimension + 1); } } } WrapDimension(new int[rank], 0); } else { for (int i = 0; i < arr.Count; ++i) { packer.PackInternal(arr[i]); } } } else { packer.WriteByte(0); int32.Pack(packer, packer.GetMetaTypeId(arr.GetType().GenericTypeArguments[0])); int32.Pack(packer, packer.GetMetaTypeId(arr.GetType().GetGenericTypeDefinition())); for (int i = 0; i < arr.Count; ++i) { packer.PackInternal(arr[i]); } } }