public override BitStream Serialize(BitStream stream, UnityEngine.Vector3 value) { BinaryWriter.Write(stream, value.x); BinaryWriter.Write(stream, value.y); BinaryWriter.Write(stream, value.z); return(stream); }
public override UnityEngine.Vector2 Deserialize(BitStream stream) { var x = BinaryReader.ReadSingle(stream); var y = BinaryReader.ReadSingle(stream); return(new UnityEngine.Vector2(x, y)); }
public override BitStream Serialize(BitStream stream, T value) { if (SerializerList != null) { return(SerializerList(stream, value)); } return(stream); }
public override BitStream Serialize(BitStream stream, UnityEngine.Rect value) { BinaryWriter.Write(stream, value.x); BinaryWriter.Write(stream, value.y); BinaryWriter.Write(stream, value.width); BinaryWriter.Write(stream, value.height); return(stream); }
public override UnityEngine.Rect Deserialize(BitStream stream) { var x = BinaryReader.ReadSingle(stream); var y = BinaryReader.ReadSingle(stream); var width = BinaryReader.ReadSingle(stream); var height = BinaryReader.ReadSingle(stream); return(new UnityEngine.Rect(x, y, width, height)); }
private static void ReadTag(BitStream stream, int tag) { var type = (IType)(tag & TagTypeMask); switch (type) { case IType.Variable32: BinaryReader.ReadUInt32(stream); break; case IType.Variable64: BinaryReader.ReadUInt64(stream); break; case IType.Fixed32: stream.Offset += 4; break; case IType.Fixed64: stream.Offset += 8; break; case IType.Dynamic: int length = BinaryReader.ReadInt32(stream); stream.Offset += length; break; case IType.EndGroup: while (true) { int loopTag = BinaryReader.ReadInt32(stream); if (loopTag == 0) { break; } ReadTag(stream, loopTag); } break; } }
public override BitStream Serialize(BitStream stream, ulong value) { BinaryWriter.Write(stream, value); return(stream); }
public override decimal Deserialize(BitStream stream) { return(BinaryReader.ReadDecimal(stream)); }
public override BitStream Serialize(BitStream stream, byte value) { BinaryWriter.Write(stream, (uint)value); return(stream); }
public static T ReadT <T>(BitStream stream) { return(default(T)); }
public override double Deserialize(BitStream stream) { return(BinaryReader.ReadDouble(stream)); }
public static object Read(BitStream stream, Type t) { return(typeof(DynamicWriter <>).MakeGenericType(t) .InvokeMember("Read", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public, null, null, new object[] { stream })); }
public override T Deserialize(BitStream stream) { if (DeserializeArray == null) { return(default(T)); } if (stream.Bytes.Length == 0) { return(default(T)); } var obj = Instance(); int index = 0; int compressTag; while (true) { compressTag = BinaryReader.ReadInt32(stream); if (compressTag == 0) { //stream.Offset++; return(obj); } if (DeserializeArray.Length == index) { ReadTag(stream, compressTag); continue; } var deserialize = DeserializeArray[index]; #if Unity && DEBUG Debug.Log("读取Tag(压缩):" + compressTag + ",读取Tag(解压):" + (compressTag >> 3) + "当前占用字节:" + stream.Offset); #endif if (stream.Offset == 334) { Debug.Log("ddasdsadsa"); } else if (compressTag == -1) { index++; continue; } if (deserialize.Data.Index == compressTag >> 3) { try { deserialize.Action(stream, obj); index++; } catch (Exception e) { throw new Exception("Index:" + deserialize.Data.Index + ",Name:" + deserialize.Data.Name + ",Type:" + deserialize.Data.Type + ",CurType:" + obj.GetType() + "\n" + e); } } else { ReadTag(stream, compressTag); } } //End Group stream.Offset++; return(obj); }
public static ushort ReadUInt16(BitStream stream) { return((ushort)(stream.Bytes[stream.Offset++] | stream.Bytes[stream.Offset++] << 8)); }
public static byte ReadByte(BitStream stream) { return(stream.Bytes[stream.Offset++]); }
public override bool Deserialize(BitStream stream) { return(BinaryReader.ReadBoolean(stream)); }
public static unsafe int ReadInt32(BitStream stream) { return((int)ReadUInt32(stream)); }
public override string Deserialize(BitStream stream) { return(BinaryReader.ReadString(stream)); }
public override ushort Deserialize(BitStream stream) { return((ushort)BinaryReader.ReadUInt32(stream)); }
public override int Deserialize(BitStream stream) { return(BinaryReader.ReadInt32(stream)); }
public override ulong Deserialize(BitStream stream) { return(BinaryReader.ReadUInt64(stream)); }
public static char ReadChar(BitStream stream) { return((char)stream.Bytes[stream.Offset++]); }
public static void Write(BitStream stream, object value, Type t) { typeof(DynamicWriter <>).MakeGenericType(t) .InvokeMember("Write", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public, null, null, new[] { stream, value }); }
public override sbyte Deserialize(BitStream stream) { return((sbyte)BinaryReader.ReadUInt32(stream)); }
public static sbyte ReadSByte(BitStream stream) { return((sbyte)stream.Bytes[stream.Offset++]); }
public override float Deserialize(BitStream stream) { return(BinaryReader.ReadSingle(stream)); }
public static bool ReadBoolean(BitStream stream) { return(stream.Bytes[stream.Offset++] != 0); }
public static unsafe float ReadSingle(BitStream stream) { uint tmpBuffer = (uint)(stream.Bytes[stream.Offset++] | stream.Bytes[stream.Offset++] << 8 | stream.Bytes[stream.Offset++] << 16 | stream.Bytes[stream.Offset++] << 24); return(*(float *)&tmpBuffer); }