public void Pack(Packer packer, object obj) { var meta = (Packer.MetaType)obj; Int32Serializer.PackDirect(packer, meta.id); StringSerializer.PackDirect(packer, meta.type); }
public void Pack(Packer stream, object obj) { var v = (Vector2Int)obj; Int32Serializer.PackDirect(stream, v.x); Int32Serializer.PackDirect(stream, v.y); }
public object Unpack(Packer packer) { var typeId = Int32Serializer.UnpackDirect(packer); var rootType = packer.GetMetaType(typeId); return(this.Unpack(packer, rootType)); }
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 static void PackDirect(Packer packer, Packer.MetaType[] meta) { Int32Serializer.PackDirect(packer, meta.Length); for (int i = 0; i < meta.Length; ++i) { MetaTypeSerializer.PackDirect(packer, meta[i]); } }
public static Packer.MetaType UnpackDirect(Packer packer) { var meta = new Packer.MetaType(); meta.id = Int32Serializer.UnpackDirect(packer); meta.type = StringSerializer.UnpackDirect(packer); return(meta); }
public static byte[] UnpackDirect(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var arr = new byte[length]; packer.ReadBytes(arr); return(arr); }
public object Unpack(Packer stream) { var v = new Vector2Int(); v.x = Int32Serializer.UnpackDirect(stream); v.y = Int32Serializer.UnpackDirect(stream); return(v); }
public void Pack(Packer packer, object obj) { var rootType = obj.GetType(); var typeId = packer.GetMetaTypeId(rootType); Int32Serializer.PackDirect(packer, typeId); this.Pack(packer, obj, rootType); }
public static void PackDirect(Packer packer, string obj) { var length = obj.Length; Int32Serializer.PackDirect(packer, length); for (int i = 0; i < obj.Length; ++i) { CharSerializer.PackDirect(packer, obj[i]); } }
public void Pack(Packer packer, object obj) { var meta = (Packer.MetaType[])obj; Int32Serializer.PackDirect(packer, meta.Length); for (int i = 0; i < meta.Length; ++i) { packer.PackInternal(meta[i]); } }
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 void Pack(Packer packer, object obj) { var arr = (System.Array)obj; Int32Serializer.PackDirect(packer, arr.Length); for (int i = 0; i < arr.Length; ++i) { packer.PackInternal(arr.GetValue(i)); } }
public static Packer.MetaType[] UnpackDirect(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var meta = new Packer.MetaType[length]; for (int i = 0; i < length; ++i) { meta[i] = MetaTypeSerializer.UnpackDirect(packer); } return(meta); }
public void Pack(Packer packer, object obj) { var sentinel = (IDisposeSentinel)obj; var type = sentinel.GetType(); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetGenericTypeDefinition())); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[0])); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[1])); packer.PackInternal(sentinel.GetData()); Int64Serializer.PackDirect(packer, sentinel.GetTick()); }
public object Unpack(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var meta = new Packer.MetaType[length]; for (int i = 0; i < length; ++i) { meta[i] = packer.UnpackInternal <Packer.MetaType>(); } return(meta); }
public object Unpack(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var arr = new object[length]; for (int i = 0; i < length; ++i) { arr[i] = packer.UnpackInternal(); } return(arr); }
public static string UnpackDirect(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var sb = new System.Text.StringBuilder(length); sb.Clear(); sb.Capacity = length; for (int i = 0; i < length; ++i) { sb.Append(CharSerializer.UnpackDirect(packer)); } var res = sb.ToString(); return(res); }
public void Pack(Packer packer, object obj) { var dict = (ME.ECS.Collections.IDictionaryInt)obj; var type = dict.GetType(); Int32Serializer.PackDirect(packer, dict.Count); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[0])); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetGenericTypeDefinition())); foreach (DictionaryEntry entry in dict) { packer.PackInternal(entry.Key); packer.PackInternal(entry.Value); } }
public object Unpack(Packer packer) { var type = packer.GetMetaType(Int32Serializer.UnpackDirect(packer)); var typeValue = packer.GetMetaType(Int32Serializer.UnpackDirect(packer)); var typeProvider = packer.GetMetaType(Int32Serializer.UnpackDirect(packer)); var sentinelType = type.MakeGenericType(typeValue, typeProvider); var poolClassType = typeof(PoolClass <>).MakeGenericType(sentinelType); var spawnMethod = poolClassType.GetMethod("Spawn", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); var sentinel = (IDisposeSentinel)spawnMethod.Invoke(null, null); sentinel.SetData(packer.UnpackInternal()); sentinel.SetTick(Int64Serializer.UnpackDirect(packer)); return(sentinel); }
public static string UnpackDirect(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var sb = PoolClass <System.Text.StringBuilder> .Spawn(); sb.Clear(); sb.Capacity = length; for (int i = 0; i < length; ++i) { sb.Append(CharSerializer.UnpackDirect(packer)); } var res = sb.ToString(); PoolClass <System.Text.StringBuilder> .Recycle(ref sb); return(res); }
public object Unpack(Packer packer) { var length = Int32Serializer.UnpackDirect(packer); var typeIdValue = Int32Serializer.UnpackDirect(packer); var typeValue = packer.GetMetaType(typeIdValue); var type = packer.GetMetaType(Int32Serializer.UnpackDirect(packer)); var t = type.MakeGenericType(typeValue); var dict = (ME.ECS.Collections.IDictionaryInt)System.Activator.CreateInstance(t); for (int i = 0; i < length; ++i) { dict.Add(packer.UnpackInternal(), packer.UnpackInternal()); } return(dict); }
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 Pack(Packer packer, object obj) { var pack = (ME.ECS.StatesHistory.HistoryEvent)obj; Int64Serializer.PackDirect(packer, pack.tick); Int32Serializer.PackDirect(packer, pack.order); Int32Serializer.PackDirect(packer, pack.rpcId); Int32Serializer.PackDirect(packer, pack.localOrder); Int32Serializer.PackDirect(packer, pack.objId); Int32Serializer.PackDirect(packer, pack.groupId); BooleanSerializer.PackDirect(packer, pack.storeInHistory); if (pack.parameters != null) { packer.WriteByte(1); var serializer = new ObjectArraySerializer(); serializer.Pack(packer, pack.parameters); } else { packer.WriteByte(0); } }
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 void PackDirect(Packer packer, byte[] arr) { Int32Serializer.PackDirect(packer, arr.Length); packer.WriteBytes(arr); }
public void Pack(Packer packer, object obj) { var arr = (IList)obj; var type = arr.GetType(); Int32Serializer.PackDirect(packer, arr.Count); if (type.IsArray == true) { var rank = type.GetArrayRank(); if (rank > 1) { packer.WriteByte(2); } else { packer.WriteByte(1); } Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetElementType())); if (rank > 1) { Int32Serializer.PackDirect(packer, rank); var arrData = (System.Array)arr; for (int j = 0; j < rank; ++j) { Int32Serializer.PackDirect(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); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(arr.GetType().GenericTypeArguments[0])); Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(arr.GetType().GetGenericTypeDefinition())); for (int i = 0; i < arr.Count; ++i) { packer.PackInternal(arr[i]); } } }
public object Unpack(Packer packer) { return((RPCId)Int32Serializer.UnpackDirect(packer)); }
public void Pack(Packer packer, object obj) { Int32Serializer.PackDirect(packer, (RPCId)obj); }
public object Unpack(Packer packer) { var int32 = new Int32Serializer(); return((RPCId)(int)(int32.Unpack(packer))); }