Decodes the provided frame data. If this method leaves data in the buffer then
this buffer should be compacted so this data is preserved, unless there is no
more data in which case this should be considered a protocol error.

@param buffer The buffer
14372
public void decode(ByteBuffer buffer, boolean moreData) throws HpackException {
        while (buffer.hasRemaining()) {
            int originalPos = buffer.position();
            byte b = buffer.get();
            if ((b & 0b10000000) != 0) {
                first = false;
                //if the first bit is set it is an indexed header field
                buffer.position(buffer.position() - 1); //unget the byte
                int index = Hpack.decodeInteger(buffer, 7); //prefix is 7
                if (index == -1) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                } else if(index == 0) {
                    throw UndertowMessages.MESSAGES.zeroNotValidHeaderTableIndex();
                }
                handleIndex(index);
            } else if ((b & 0b01000000) != 0) {
                first = false;
                //Literal Header Field with Incremental Indexing
                HttpString headerName = readHeaderName(buffer, 6);
                if (headerName == null) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                }
                String headerValue = readHpackString(buffer);
                if (headerValue == null) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                }
                headerEmitter.emitHeader(headerName, headerValue, false);
                addEntryToHeaderTable(new HeaderField(headerName, headerValue));
            } else if ((b & 0b11110000) == 0) {
                first = false;
                //Literal Header Field without Indexing
                HttpString headerName = readHeaderName(buffer, 4);
                if (headerName == null) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                }
                String headerValue = readHpackString(buffer);
                if (headerValue == null) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                }
                headerEmitter.emitHeader(headerName, headerValue, false);
            } else if ((b & 0b11110000) == 0b00010000) {
                first = false;
                //Literal Header Field never indexed
                HttpString headerName = readHeaderName(buffer, 4);
                if (headerName == null) {
                    buffer.position(originalPos);
                    return;
                }
                String headerValue = readHpackString(buffer);
                if (headerValue == null) {
                    if(!moreData) {
                        throw UndertowMessages.MESSAGES.hpackFailed();
                    }
                    buffer.position(originalPos);
                    return;
                }
                headerEmitter.emitHeader(headerName, headerValue, true);
            } else if ((b & 0b11100000) == 0b00100000) {
                if(!first) {
                    throw new HpackException();
                }
                //context update max table size change
                if (!handleMaxMemorySizeChange(buffer, originalPos)) {
                    return;
                }
            } else {
                throw UndertowMessages.MESSAGES.invalidHpackEncoding(b);
            }
        }
        if(!moreData) {
            first = true;
        }
    }
601078
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;

        this.capabilities = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;

        System.arraycopy(buffer, bufferIndex, this.serverGuid, 0, 16);
        bufferIndex += 16;

        this.securityMode = SMBUtil.readInt2(buffer, bufferIndex);
        this.dialect = SMBUtil.readInt2(buffer, bufferIndex + 2);
        bufferIndex += 4;

        return bufferIndex - start;
    }
735455
public void serializeCompact(ByteBuffer buffer) {
        byte[] chainWorkBytes = getChainWork().toByteArray();
        checkState(chainWorkBytes.length <= CHAIN_WORK_BYTES, "Ran out of space to store chain work!");
        if (chainWorkBytes.length < CHAIN_WORK_BYTES) {
            // Pad to the right size.
            buffer.put(EMPTY_BYTES, 0, CHAIN_WORK_BYTES - chainWorkBytes.length);
        }
        buffer.put(chainWorkBytes);
        buffer.putInt(getHeight());
        // Using unsafeBitcoinSerialize here can give us direct access to the same bytes we read off the wire,
        // avoiding serialization round-trips.
        byte[] bytes = getHeader().unsafeBitcoinSerialize();
        buffer.put(bytes, 0, Block.HEADER_SIZE);  // Trim the trailing 00 byte (zero transactions).
    }
148979
public static byte[] decode(String string)
    {
        if (string.length() % 5 != 0) {
            return null;
        }
        ByteBuffer buf = ByteBuffer.allocate(string.length() * 4 / 5);

        int byteNbr = 0;
        int charNbr = 0;
        int stringLen = string.length();
        long value = 0;
        while (charNbr < stringLen) {
            //  Accumulate value in base 85
            value = value * 85 + (decoder[string.charAt(charNbr++) - 32] & 0xff);
            if (charNbr % 5 == 0) {
                //  Output value in base 256
                int divisor = 256 * 256 * 256;
                while (divisor != 0) {
                    buf.put(byteNbr++, (byte) ((value / divisor) % 256));
                    divisor /= 256;
                }
                value = 0;
            }
        }
        assert (byteNbr == string.length() * 4 / 5);
        return buf.array();
    }
919631
private boolean parsePayload(ByteBuffer buffer) {
        if (payloadLength == 0) {
            return true;
        }

        if (buffer.hasRemaining()) {
            // Create a small window of the incoming buffer to work with.
            // this should only show the payload itself, and not any more
            // bytes that could belong to the start of the next frame.
            int bytesSoFar = payload == null ? 0 : payload.position();
            int bytesExpected = payloadLength - bytesSoFar;
            int bytesAvailable = buffer.remaining();
            int windowBytes = Math.min(bytesAvailable, bytesExpected);
            int limit = buffer.limit();
            buffer.limit(buffer.position() + windowBytes);
            ByteBuffer window = buffer.slice();
            buffer.limit(limit);
            buffer.position(buffer.position() + window.remaining());

            if (LOG.isDebugEnabled()) {
                LOG.debug("{} Window: {}", policy.getBehavior(), BufferUtils.toDetailString(window));
            }

            maskProcessor.process(window);

            if (window.remaining() == payloadLength) {
                // We have the whole content, no need to copy.
                frame.setPayload(window);
                return true;
            } else {
                if (payload == null) {
                    payload = BufferUtils.allocate(payloadLength);
                    BufferUtils.clearToFill(payload);
                }
                // Copy the payload.
                payload.put(window);

                if (payload.position() == payloadLength) {
                    BufferUtils.flipToFlush(payload, 0);
                    frame.setPayload(payload);
                    return true;
                }
            }
        }
        return false;
    }
895777
function decode (data, start, end, encoding) {
  if (data == null || data.length === 0) {
    return null
  }

  if (typeof start !== 'number' && encoding == null) {
    encoding = start
    start = undefined
  }

  if (typeof end !== 'number' && encoding == null) {
    encoding = end
    end = undefined
  }

  decode.position = 0
  decode.encoding = encoding || null

  decode.data = !(Buffer.isBuffer(data))
    ? Buffer.from(data)
    : data.slice(start, end)

  decode.bytes = decode.data.length

  return decode.next()
}
538026
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.numberOfLinks = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.deletePending = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        this.directory = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        return bufferIndex - start;
    }
496992
public ServiceMessage decode(ByteBuf dataBuffer, ByteBuf headersBuffer)
      throws MessageCodecException {
    ServiceMessage.Builder builder = ServiceMessage.builder();

    if (dataBuffer.isReadable()) {
      builder.data(dataBuffer);
    }
    if (headersBuffer.isReadable()) {
      try (ByteBufInputStream stream = new ByteBufInputStream(headersBuffer, true)) {
        builder.headers(headersCodec.decode(stream));
      } catch (Throwable ex) {
        ReferenceCountUtil.safestRelease(dataBuffer); // release data buf as well
        throw new MessageCodecException("Failed to decode message headers", ex);
      }
    }

    return builder.build();
  }
384745
def decode_buffer(buffer: dict) -> np.ndarray:
    
    buf = np.frombuffer(buffer['data'], dtype=buffer['dtype'])
    return buf.reshape(buffer['shape'])
231904
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        int nciphers = SMBUtil.readInt2(buffer, bufferIndex);
        bufferIndex += 2;

        this.ciphers = new int[nciphers];
        for ( int i = 0; i < nciphers; i++ ) {
            this.ciphers[ i ] = SMBUtil.readInt2(buffer, bufferIndex);
            bufferIndex += 2;
        }

        return bufferIndex - start;
    }
649748
function decode(buffer, encoding) {
		validateEncoding(encoding);
		if (encoding === null || encoding === 'buffer') return [buffer, new Buffer(0)];
		var decoder = new StringDecoder(encoding);
		var str = decoder.write(buffer);
		var leftover = decoder.charBuffer.slice(0, decoder.charReceived);
		return [str, leftover];
	}
28218
public void read(ByteBuffer buffer) {
        Persistables.persistable(streamableNoBuffers()).read(buffer);

        final int n = getNumDataBuffers();
        int lengthsPosition = buffer.position();
        buffer.position(buffer.position() + 2 * n); // skip positions
        for (int i = 0; i < n; i++) {
            final int size = buffer.getShort(lengthsPosition) & 0xFFFF; // big-endian
            lengthsPosition += 2;

            final ByteBuffer b1 = Persistables.slice(buffer, size);
            setDataBuffer(i, b1);
        }
    }
1046051
public final void decode(byte type, byte from, byte dest, DataInputStream buffer) throws IOException
    {
        this.type = type;
        clientId = from;
        clientDestId = dest;
        decode(buffer);
    }
1212915
synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) {
        long maxValue = integerValuesHistogram.getMaxValue();
        int relevantLength = integerValuesHistogram.getLengthForNumberOfBuckets(
                integerValuesHistogram.getBucketsNeededToCoverValue(maxValue));
        if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) {
            throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " +
                    getNeededByteBufferCapacity(relevantLength) + " bytes");
        }
        buffer.putInt(DHIST_encodingCookie);
        buffer.putInt(getNumberOfSignificantValueDigits());
        buffer.putLong(configuredHighestToLowestValueRatio);
        return integerValuesHistogram.encodeIntoByteBuffer(buffer) + 16;
    }
961075
@Override
	protected int decode(ByteBuffer b, char[] chars, int pos, int len, MutableBoolean interrupt, int min) {
		if (b == null) {
			// end
			if (state == 0)
				return -1;
			chars[pos] = (char)val;
			state = 0;
			return 1;
		}
		int nb = 0;
		while ((state == 7 || b.hasRemaining()) && nb < len && (nb < min || interrupt == null || !interrupt.get())) {
			int a = state == 7 ? 0 : b.get() & 0xFF;
			switch (state) {
			case 0:
				if (a < 0x80) {
					// 0aaa aaaa
					chars[pos + (nb++)] = (char)a;
				} else if ((a & 0xE0) == 0xC0) {
					// 110a aaaa 10bb bbbb
					val = (a & 0x1F) << 6;
					state = 1;
				} else if ((a & 0xF0) == 0xE0) {
					// 1110 aaaa 10bb bbbb 10cc cccc
					val = (a & 0x0F) << 12;
					state = 2;
				} else if ((a & 0xF8) == 0xF0) {
					// 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
					val = (a & 0x07) << 12;
					state = 4;
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				break;
			case 1:
				// second byte of 110a aaaa 10bb bbbb
				if ((a & 0xC0) == 0x80) {
					chars[pos + (nb++)] = (char)(val | (a & 0x3F));
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				state = 0;
				break;
			case 2:
				// second byte of 1110 aaaa 10bb bbbb 10cc cccc
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F) << 6;
					state = 3;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 3:
				// third byte of 1110 aaaa 10bb bbbb 10cc cccc
				if ((a & 0xC0) == 0x80) {
					chars[pos + (nb++)] = (char)(val | (a & 0x3F));
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				state = 0;
				break;
			case 4:
				// second byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F) << 6;
					state = 5;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 5:
				// third byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F);
					state = 6;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 6:
				// fourth byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					// UTF-8:   [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]*
					// Unicode: [1101 10ww] [wwzz zzyy] (high surrogate)
					//          [1101 11yy] [yyxx xxxx] (low surrogate)
					//          * uuuuu = wwww + 1
					int uuuuu = (val & 0x7C00) >> 10;
					// TODO if > 0x10 invalid Surrogate
					int wwww = uuuuu - 1;
					chars[pos + (nb++)] = (char)(0xD800 | (wwww << 6) | ((val & 0x3C0) >> 4) | ((val & 0x30) >> 4));
					val = (0xDC00 | ((val & 0xF) << 6) | (a & 0x3F));
					state = 7;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 7:
				chars[pos + (nb++)] = (char)val;
				state = 0;
				break;
			}
		}
		return nb;
	}
240477
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.namedPipeState = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.readDataAvailable = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.numberOfMessages = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.messageLength = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.data = new byte[len - 16];
        if ( this.data.length > 0 ) {
            System.arraycopy(buffer, bufferIndex, this.data, 0, this.data.length);
        }
        return bufferIndex - start;
    }
680997
protected Object decode(ChannelHandlerContext channelHandlerContext, Channel channel, ChannelBuffer channelBuffer) throws Exception {
        // Wait until the length prefix is available.
        if (channelBuffer.readableBytes() < 4) {
            // If null is returned, it means there is not enough data yet.
            // FrameDecoder will call again when there is a sufficient amount of data available.
            return null;
        }

        //marking the current reading position
        channelBuffer.markReaderIndex();

        //get the fragment size and wait until the entire fragment is available.
        long fragSize = channelBuffer.readUnsignedInt();
        boolean lastFragment = RecordMarkingUtil.isLastFragment(fragSize);
        fragSize = RecordMarkingUtil.maskFragmentSize(fragSize);
        if (channelBuffer.readableBytes() < fragSize) {
            channelBuffer.resetReaderIndex();
            return null;
        }

        //seek to the beginning of the next fragment
        channelBuffer.skipBytes((int) fragSize);

        _recordLength += 4 + (int) fragSize;

        //check the last fragment
        if (!lastFragment) {
            //not the last fragment, the data is put in an internally maintained cumulative buffer
            return null;
        }

        byte[] rpcResponse = new byte[_recordLength];
        channelBuffer.readerIndex(channelBuffer.readerIndex() - _recordLength);
        channelBuffer.readBytes(rpcResponse, 0, _recordLength);

        _recordLength = 0;
        return rpcResponse;
    }