protected internal override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output) { var bytes = input.BytesBefore((byte)'\n'); IByteBuffer msg = input.ReadBytes(bytes); output.Add(msg); input.SkipBytes(1); }
public static int BytesBefore(this IByteBuffer buf, byte value) { if (buf is IByteBuffer2 buffer2) { return(buffer2.BytesBefore(value)); } return(buf.BytesBefore(buf.ReaderIndex, buf.ReadableBytes, value)); }
public static int BytesBefore(this IByteBuffer buf, int length, byte value) { if (buf is IByteBuffer2 buffer2) { return(buffer2.BytesBefore(length, value)); } if ((uint)length > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException(); } return(buf.BytesBefore(buf.ReaderIndex, length, value)); }
/** * Reads a variable-length NUL-terminated string as defined input SOCKS4. */ private static string ReadString(string fieldName, IByteBuffer input) { var length = input.BytesBefore(MaxFieldLength + 1, 0); if (length < 0) { throw new DecoderException("field '" + fieldName + "' longer than " + MaxFieldLength + " chars"); } var value = input.ReadSlice(length).ToString(Encoding.ASCII); input.SkipBytes(1); // Skip the NUL. return(value); }