Example #1
0
        public static Packet GetPacketFromBuffer(this BitBuffer buffer, PacketFlags flags = PacketFlags.None)
        {
            var data = ByteArrayPool.GetByteArray(buffer.Length + 4);

            buffer.ToArray(data);
            Packet packet = default(Packet);

            packet.Create(data, flags);
            ByteArrayPool.ReturnByteArray(data);
            return(packet);
        }
Example #2
0
        public static BitBuffer GetBufferFromPacket(this Packet packet, BitBuffer buffer = null)
        {
            var data = ByteArrayPool.GetByteArray(packet.Length + 4);

            packet.CopyTo(data);

            if (buffer == null)
            {
                buffer = new BitBuffer(128);
            }
            else
            {
                buffer.Clear();
            }

            buffer.FromArray(data, packet.Length);
            ByteArrayPool.ReturnByteArray(data);

            return(buffer);
        }