protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output) { input.NotNull(nameof(input)); output.NotNull(nameof(output)); if (input.ReadableBytes < 5) { return; } input.MarkReaderIndex(); int magicNumber = input.ReadByte(); if (magicNumber != 'F') { input.ResetReaderIndex(); throw new Exception("Invalid magic number: " + magicNumber); } int dataLength = input.ReadInt(); if (input.ReadableBytes < dataLength) { input.ResetReaderIndex(); return; } var decoded = new byte[dataLength]; input.ReadBytes(decoded); output.Add(new BigInteger(decoded)); }