public static string ReadString(this IReadablePacket packet) { if (!packet.HasString()) { throw new PacketException("Cannot read string."); } var data = packet.ReadByteArray(); return(data == null ? null : Encoding.UTF8.GetString(data)); }
public void Depacketize(IReadablePacket packet) { // Get actual data. var data = packet.ReadByteArray(); // Start writing from the start, overwriting everything. _stream.Position = 0; _stream.Write(data, 0, data.Length); // Reset to start for reading. _stream.Position = 0; }
public static IReadablePacket Read(this IReadablePacket packet, out byte[] data) { data = packet.ReadByteArray(); return(packet); }
public static IReadablePacket Read( this IReadablePacket packet, byte[] buffer, int offset, int count, out int length) { length = packet.ReadByteArray(buffer, offset, count); return(packet); }