public object Unpack(Packer stream) { object res = null; var enumType = (TypeValue)stream.ReadByte(); if (enumType == TypeValue.Int32) { var ser = new Int32Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Int16) { var ser = new Int16Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Int64) { var ser = new Int64Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt16) { var ser = new UInt16Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt32) { var ser = new UInt32Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.UInt64) { var ser = new UInt64Serializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.Byte) { var ser = new ByteSerializer(); res = ser.Unpack(stream); } else if (enumType == TypeValue.SByte) { var ser = new SByteSerializer(); res = ser.Unpack(stream); } else { var ser = new StringSerializer(); var str = (string)ser.Unpack(stream); res = System.Enum.Parse(typeof(System.Enum), str); } return(res); }
public object Unpack(Packer packer) { var int32 = new Int32Serializer(); return((RPCId)(int)(int32.Unpack(packer))); }
public object Unpack(Packer packer) { var int32 = new Int32Serializer(); var length = (int)int32.Unpack(packer); var isArray = packer.ReadByte(); var typeId = (int)int32.Unpack(packer); var typeIn = packer.GetMetaType(typeId); IList arr = null; if (isArray == 2) { var rank = (int)int32.Unpack(packer); if (rank > 1) { var lengthArray = new int[rank]; for (int j = 0; j < rank; ++j) { lengthArray[j] = (int)int32.Unpack(packer); } var arrData = System.Array.CreateInstance(typeIn, lengthArray); arr = arrData; void WrapDimension(int[] ids, int currentDimension) { if (currentDimension == rank) { arrData.SetValue(packer.UnpackInternal(), ids); } else { for (int i = 0, len = arrData.GetLength(currentDimension); i < len; i++) { ids[currentDimension] = i; WrapDimension(ids, currentDimension + 1); } } } WrapDimension(new int[rank], 0); } } else if (isArray == 1) { arr = System.Array.CreateInstance(typeIn, length); for (int i = 0; i < length; ++i) { arr[i] = packer.UnpackInternal(); } } else { var type = packer.GetMetaType((int)int32.Unpack(packer)); var t = type.MakeGenericType(typeIn); arr = (IList)System.Activator.CreateInstance(t); for (int i = 0; i < length; ++i) { arr.Add(packer.UnpackInternal()); } } return(arr); }