Exemple #1
0
 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);
 }
Exemple #2
0
        public override UnityEngine.Vector2 Deserialize(BitStream stream)
        {
            var x = BinaryReader.ReadSingle(stream);
            var y = BinaryReader.ReadSingle(stream);

            return(new UnityEngine.Vector2(x, y));
        }
Exemple #3
0
 public override BitStream Serialize(BitStream stream, T value)
 {
     if (SerializerList != null)
     {
         return(SerializerList(stream, value));
     }
     return(stream);
 }
Exemple #4
0
 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);
 }
Exemple #5
0
        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));
        }
Exemple #6
0
        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;
            }
        }
Exemple #7
0
 public override BitStream Serialize(BitStream stream, ulong value)
 {
     BinaryWriter.Write(stream, value);
     return(stream);
 }
Exemple #8
0
 public override decimal Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadDecimal(stream));
 }
Exemple #9
0
 public override BitStream Serialize(BitStream stream, byte value)
 {
     BinaryWriter.Write(stream, (uint)value);
     return(stream);
 }
Exemple #10
0
 public static T ReadT <T>(BitStream stream)
 {
     return(default(T));
 }
Exemple #11
0
 public override double Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadDouble(stream));
 }
Exemple #12
0
 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 }));
 }
Exemple #13
0
        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);
        }
Exemple #14
0
 public static ushort ReadUInt16(BitStream stream)
 {
     return((ushort)(stream.Bytes[stream.Offset++] | stream.Bytes[stream.Offset++] << 8));
 }
Exemple #15
0
 public static byte ReadByte(BitStream stream)
 {
     return(stream.Bytes[stream.Offset++]);
 }
Exemple #16
0
 public override bool Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadBoolean(stream));
 }
Exemple #17
0
 public static unsafe int ReadInt32(BitStream stream)
 {
     return((int)ReadUInt32(stream));
 }
Exemple #18
0
 public override string Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadString(stream));
 }
Exemple #19
0
 public override ushort Deserialize(BitStream stream)
 {
     return((ushort)BinaryReader.ReadUInt32(stream));
 }
Exemple #20
0
 public override int Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadInt32(stream));
 }
Exemple #21
0
 public override ulong Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadUInt64(stream));
 }
Exemple #22
0
 public static char ReadChar(BitStream stream)
 {
     return((char)stream.Bytes[stream.Offset++]);
 }
Exemple #23
0
 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 });
 }
Exemple #24
0
 public override sbyte Deserialize(BitStream stream)
 {
     return((sbyte)BinaryReader.ReadUInt32(stream));
 }
Exemple #25
0
 public static sbyte ReadSByte(BitStream stream)
 {
     return((sbyte)stream.Bytes[stream.Offset++]);
 }
Exemple #26
0
 public override float Deserialize(BitStream stream)
 {
     return(BinaryReader.ReadSingle(stream));
 }
Exemple #27
0
 public static bool ReadBoolean(BitStream stream)
 {
     return(stream.Bytes[stream.Offset++] != 0);
 }
Exemple #28
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);
        }