Example #1
0
        public static Datagram ReadFrom(ArraySegment <byte> buffer, ArrayPool <byte> bufferPool)
        {
            if (buffer.Array == null)
            {
                throw new ArgumentNullException(nameof(buffer.Array));
            }
            if (bufferPool == null)
            {
                throw new ArgumentNullException(nameof(bufferPool));
            }

            var header       = DatagramHeader.ReadFrom(buffer, bufferPool);
            var headerLength = header.ByteCount;
            var payload      = new ArraySegment <byte>(
                buffer.Array,
                buffer.Offset + headerLength,
                buffer.Count - headerLength);

            return(new Datagram(header, payload));
        }
Example #2
0
 public Datagram(DatagramHeader header, ArraySegment <byte> payload)
 {
     this.Header  = header;
     this.Payload = payload;
 }