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); }
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)); }
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)); } }
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)); } }
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); }
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); }