Esempio n. 1
0
        // Write
        // ------------------------------------------------------------------
        /// <summary>
        /// Adds one byte for type and the bytes in val to buffer.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        protected Packet PutSimple(PacketElementType type, params byte[] val)
        {
            this.EnsureEditable();

            var len = 1 + val.Length;
            this.EnsureSize(len);

            _buffer[_ptr++] = (byte)type;
            Buffer.BlockCopy(val, 0, _buffer, _ptr, val.Length);
            _ptr += val.Length;

            _elements++;
            _bodyLen += len;

            return this;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds one byte for type, 2 bytes for the length of the val bytes,
        /// and the vals itself to buffer.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        protected Packet PutWithLength(PacketElementType type, byte[] val)
        {
            this.EnsureEditable();

            var len = 1 + sizeof(short) + val.Length;
            this.EnsureSize(len);

            _buffer[_ptr++] = (byte)type;
            Buffer.BlockCopy(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)val.Length)), 0, _buffer, _ptr, sizeof(short));
            _ptr += 2;
            Buffer.BlockCopy(val, 0, _buffer, _ptr, val.Length);
            _ptr += val.Length;

            _elements++;
            _bodyLen += len;

            return this;
        }
Esempio n. 3
0
 /// <summary>
 /// Returns true if the next element to be read is of type.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public bool NextIs(PacketElementType type)
 {
     return (this.Peek() == type);
 }
Esempio n. 4
0
 public PacketElementTypeException(PacketElementType expected, PacketElementType actual)
     : base(string.Format("Expected {0}, got {1}.", expected, actual))
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Returns true if the next element to be read is of type.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public bool NextIs(PacketElementType type)
 {
     return(this.Peek() == type);
 }
Esempio n. 6
0
 /// <summary>
 /// Returns true if type is a valid value of the enum and not None.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 private bool IsValidType(PacketElementType type)
 {
     return(type >= PacketElementType.Byte && type <= PacketElementType.Bin);
 }
Esempio n. 7
0
 /// <summary>
 /// Returns true if type is a valid value of the enum and not None.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 private bool IsValidType(PacketElementType type)
 {
     return (type >= PacketElementType.Byte && type <= PacketElementType.Bin);
 }