private static void HandleRangeUpdate(int index, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); RangePacket r = buffer.ReadRange(); buffer.Dispose(); Console.WriteLine(r); }
public void WriteSelectedRange(RangePacket input) { try { Debug.WriteLine("Writing selected range:"); BinaryFormatter bf = new BinaryFormatter(); byte[] data; using (var ms = new MemoryStream()) { bf.Serialize(ms, input); data = new byte[ms.Length]; data = ms.ToArray(); } Debug.WriteLine(data.Length); bufferList.AddRange(BitConverter.GetBytes(data.Length)); bufferList.AddRange(data); buffUpdate = true; } catch (Exception ex) { Debug.WriteLine("Writing selected range: " + ex); } }
private static void HandleSelectionUpdate(int index, byte[] data) { Console.WriteLine("Received selection update"); PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); RangePacket r = buffer.ReadSelectedRange(); if (Server) { SelectionReceived?.Invoke(new Tuple <int, byte[]>(index, data), EventArgs.Empty); } else { SelectionReceived?.Invoke(r, EventArgs.Empty); } buffer.Dispose(); Console.WriteLine(r.User.ToString() + "has updated their selection to: " + r.RangeInfo); }
public RangePacket ReadSelectedRange(bool peek = true) { int length = ReadInteger(); if (buffUpdate) { readBuffer = bufferList.ToArray(); buffUpdate = false; } BinaryFormatter b = new BinaryFormatter(); byte[] rangeBytes = new byte[length]; Array.Copy(readBuffer, readPosition, rangeBytes, 0, length); RangePacket val = (RangePacket)b.Deserialize(new MemoryStream(rangeBytes)); if (peek && bufferList.Count > readPosition) { readPosition += length; } return(val); }