예제 #1
0
        public static ISerializableWispObject GetSerializableWispObject(byte[] data, Pointer p)
        {
            uint type = GetUInt(data, p);
            ISerializableWispObject c = Factory.Instance.CreateObject(type) as ISerializableWispObject;

            c.Deserialize(data, p);
            return(c);
        }
예제 #2
0
        protected virtual ArraySegment <byte> SerializeWispObject(ISerializableWispObject value)
        {
            byte[] buff = new byte[512];
            buff[0] = 255;
            buff[1] = 128;
            buff[2] = 255;

            Pointer p = new Pointer();

            p.Position = 3;
            BitPacker.AddSerializableWispObject(ref buff, p, value);
            return(new ArraySegment <byte>(buff, 0, p.Position));
        }
예제 #3
0
        protected virtual ArraySegment <byte> SerializeObject(object value)
        {
            ISerializableWispObject w = value as ISerializableWispObject;

            if (w != null)
            {
                return(SerializeWispObject(w));
            }

            using (var ms = new MemoryStream())
            {
                new BinaryFormatter().Serialize(ms, value);
                return(new ArraySegment <byte>(ms.GetBuffer(), 0, (int)ms.Length));
            }
        }
예제 #4
0
        protected virtual object DeserializeObject(ArraySegment <byte> value)
        {
            try
            {
                ISerializableWispObject w = null;
                if (value.Count >= 3 && value.Array[value.Offset] == 255 && value.Array[value.Offset + 1] == 128 && value.Array[value.Offset + 2] == 255) // check for wisp hint
                {
                    w = DeserializeWispObject(value);
                    if (w == null)
                    {
                        throw new ArgumentException();
                    }
                    return(w);
                }
            }
            catch
            {
            }

            using (var ms = new MemoryStream(value.Array, value.Offset, value.Count))
            {
                return(new BinaryFormatter().Deserialize(ms));
            }
        }
예제 #5
0
        public static void AddSerializableWispObject(ref byte[] data, Pointer curPointer, ISerializableWispObject c)
        {
            uint type = c.TypeHash;

            AddUInt(ref data, curPointer, type);
            c.Serialize(ref data, curPointer);
        }
예제 #6
0
        protected virtual ArraySegment<byte> SerializeWispObject(ISerializableWispObject value)
        {
            byte[] buff = new byte[512];
            buff[0] = 255;
            buff[1] = 128;
            buff[2] = 255;

            Pointer p = new Pointer();
            p.Position = 3;
            BitPacker.AddSerializableWispObject(ref buff, p, value);
            return new ArraySegment<byte>(buff, 0, p.Position);
        }
예제 #7
0
파일: BitPacker.cs 프로젝트: kamilion/WISP
 public static void AddSerializableWispObject(ref byte[] data, Pointer curPointer, ISerializableWispObject c)
 {
     uint type = c.TypeHash;
     AddUInt(ref data, curPointer, type);
     c.Serialize(ref data, curPointer);
 }