// 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; }
/// <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; }
/// <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); }
public PacketElementTypeException(PacketElementType expected, PacketElementType actual) : base(string.Format("Expected {0}, got {1}.", expected, actual)) { }
/// <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); }
/// <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); }
/// <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); }