Example #1
0
        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));
        }
Example #2
0
        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;
        }
Example #3
0
 public static IReadablePacket Read(this IReadablePacket packet, out byte[] data)
 {
     data = packet.ReadByteArray();
     return(packet);
 }
Example #4
0
 public static IReadablePacket Read(
     this IReadablePacket packet, byte[] buffer, int offset, int count, out int length)
 {
     length = packet.ReadByteArray(buffer, offset, count);
     return(packet);
 }