public static ushort UnpackDirect(Packer packer) { var res = new Int16Bytes() { b1 = packer.ReadByte(), b2 = packer.ReadByte() }; return(res.value); }
public static short UnpackDirect(Packer packer) { var size = packer.ReadByte(); var res = new Int16Bytes() { b1 = (size >= 1 ? packer.ReadByte() : byte.MinValue), b2 = (size >= 2 ? packer.ReadByte() : byte.MinValue) }; return(res.value); }
public static float UnpackDirect(Packer packer) { var size = packer.ReadByte(); var res = new FloatBytes() { b1 = (size >= 1 ? packer.ReadByte() : byte.MinValue), b2 = (size >= 2 ? packer.ReadByte() : byte.MinValue), b3 = (size >= 3 ? packer.ReadByte() : byte.MinValue), b4 = (size >= 4 ? packer.ReadByte() : byte.MinValue) }; return(res.value); }
public object Unpack(Packer packer, System.Type rootType) { var instance = System.Activator.CreateInstance(rootType); var fields = rootType.GetCachedFields(); for (int i = 0; i < fields.Length; ++i) { var type = packer.ReadByte(); if (type == (byte)TypeValue.Null) { fields[i].SetValue(instance, null); continue; } if (packer.serializers.TryGetValue(type, out var ser) == true) { fields[i].SetValue(instance, ser.unpack.Invoke(packer)); } else { packer.UnpackInternal(); } } return(instance); }
public static sbyte UnpackDirect(Packer packer) { var @sbyte = new SByte() { b1 = packer.ReadByte() }; return(@sbyte.value); }
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 static double UnpackDirect(Packer packer) { var size = packer.ReadByte(); var res = new Float64Bytes() { b1 = (size >= 1 ? packer.ReadByte() : byte.MinValue), b2 = (size >= 2 ? packer.ReadByte() : byte.MinValue), b3 = (size >= 3 ? packer.ReadByte() : byte.MinValue), b4 = (size >= 4 ? packer.ReadByte() : byte.MinValue), b5 = (size >= 5 ? packer.ReadByte() : byte.MinValue), b6 = (size >= 6 ? packer.ReadByte() : byte.MinValue), b7 = (size >= 7 ? packer.ReadByte() : byte.MinValue), b8 = (size >= 8 ? packer.ReadByte() : byte.MinValue) }; return(res.value); }
public object Unpack(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var arr = new byte[length]; for (int i = 0; i < length; ++i) { arr[i] = packer.ReadByte(); } return(arr); }
public object Unpack(Packer packer) { var pack = new ME.ECS.StatesHistory.HistoryEvent(); pack.tick = Int64Serializer.UnpackDirect(packer); pack.order = Int32Serializer.UnpackDirect(packer); pack.rpcId = Int32Serializer.UnpackDirect(packer); pack.localOrder = Int32Serializer.UnpackDirect(packer); pack.objId = Int32Serializer.UnpackDirect(packer); pack.groupId = Int32Serializer.UnpackDirect(packer); pack.storeInHistory = BooleanSerializer.UnpackDirect(packer); var hasParams = packer.ReadByte(); if (hasParams == 1) { var serializer = new ObjectArraySerializer(); pack.parameters = (object[])serializer.Unpack(packer); } return(pack); }
public void Unpack <T>(Packer packer, T objectToOverwrite) where T : class { var fields = typeof(T).GetCachedFields(); for (int i = 0; i < fields.Length; ++i) { var type = packer.ReadByte(); if (type == (byte)TypeValue.Null) { fields[i].SetValue(objectToOverwrite, null); continue; } if (packer.serializers.TryGetValue(type, out var ser) == true) { fields[i].SetValue(objectToOverwrite, ser.unpack.Invoke(packer)); } else { packer.UnpackInternal(); } } }
public object Unpack(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var isArray = packer.ReadByte(); var typeId = Int32Serializer.UnpackDirect(packer); var typeIn = packer.GetMetaType(typeId); IList arr = null; if (isArray == 2) { var rank = Int32Serializer.UnpackDirect(packer); if (rank > 1) { var lengthArray = new int[rank]; for (int j = 0; j < rank; ++j) { lengthArray[j] = Int32Serializer.UnpackDirect(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(Int32Serializer.UnpackDirect(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); }
public static byte UnpackDirect(Packer packer) { return(packer.ReadByte()); }
public static bool UnpackDirect(Packer packer) { var b = packer.ReadByte(); return(b == 1 ? true : false); }