Decodes common 9-byte header.

 @param buf [Buffer]
558130
def read_common_header(buf)
      frame = {}
      len_hi, len_lo, type, flags, stream = buf.slice(0, 9).unpack(HEADERPACK)

      frame[:length] = (len_hi << FRAME_LENGTH_HISHIFT) | len_lo
      frame[:type], _ = FRAME_TYPES.find { |_t, pos| type == pos }
      if frame[:type]
        frame[:flags] = FRAME_FLAGS[frame[:type]].each_with_object([]) do |(name, pos), acc|
          acc << name if (flags & (1 << pos)) > 0
        end
      end

      frame[:stream] = stream & RBIT
      frame
    end
238131
public static ChunkFetchSuccess decode(ByteBuf buf) {
    StreamChunkId streamChunkId = StreamChunkId.decode(buf);
    buf.retain();
    NettyManagedBuffer managedBuf = new NettyManagedBuffer(buf.duplicate());
    return new ChunkFetchSuccess(streamChunkId, managedBuf);
  }
21506
@Override
  public NSMessage<T> decode(final byte[] buf) {
    if (isStreamingCodec) {
      final StreamingCodec<T> streamingCodec = (StreamingCodec<T>) codec;
      try (ByteArrayInputStream bais = new ByteArrayInputStream(buf)) {
        try (DataInputStream dais = new DataInputStream(bais)) {
          final Identifier srcId = factory.getNewInstance(dais.readUTF());
          final Identifier destId = factory.getNewInstance(dais.readUTF());
          final int size = dais.readInt();
          final List<T> list = new ArrayList<>(size);
          for (int i = 0; i < size; i++) {
            list.add(streamingCodec.decodeFromStream(dais));
          }
          return new NSMessage<>(srcId, destId, list);
        }
      } catch (final IOException e) {
        throw new RuntimeException("IOException", e);
      }
    } else {
      final NSMessagePBuf pbuf;
      try {
        pbuf = NSMessagePBuf.parseFrom(buf);
      } catch (final InvalidProtocolBufferException e) {
        e.printStackTrace();
        throw new NetworkRuntimeException(e);
      }
      final List<T> list = new ArrayList<>();
      for (final NSRecordPBuf rbuf : pbuf.getMsgsList()) {
        list.add(codec.decode(rbuf.getData().toByteArray()));
      }
      return new NSMessage<>(factory.getNewInstance(pbuf.getSrcid()), factory.getNewInstance(pbuf.getDestid()), list);
    }
  }
732881
def from_buffer(self, buf):
        
        with self.lock:
            try:
                # if we're on python3, convert buf to bytes
                # otherwise this string is passed as wchar*
                # which is not what libmagic expects
                if isinstance(buf, str) and str != bytes:
                    buf = buf.encode('utf-8', errors='replace')
                return maybe_decode(magic_buffer(self.cookie, buf))
            except MagicException as e:
                return self._handle509Bug(e)
53553
public void toBytesDense(ByteBuffer buf)
  {
    buf.putInt(size);
    buf.putInt(binCount);

    buf.asFloatBuffer().put(positions);
    buf.position(buf.position() + Float.BYTES * positions.length);
    buf.asLongBuffer().put(bins);
    buf.position(buf.position() + Long.BYTES * bins.length);

    buf.putFloat(min);
    buf.putFloat(max);
  }
812937
public static int readInt(ByteBuffer buf) {
        byte len=buf.get();
        if(len == 0)
            return 0;
        return makeInt(buf, len);
    }
660308
public static DerId decode(ByteBuffer buf) {
        if (buf == null || buf.remaining() == 0) {
            throw new IllegalArgumentException("Null or empty buffer");
        }

        DerId id = new DerId();

        byte first = buf.get(); // first octet

        // Bits 8 and 7 represent the tag class
        id.tagClass = TagClass.values()[(first & 0xc0) >> 6];

        // Bit 6 represents the encoding type
        id.encodingType = EncodingType.values()[(first & 0x20) >> 5];

        // Bits 5 through 1 represent the tag number if tag number is less than 30.
        // Bits 5 through 1 are set to 1 if the tag number is greater than 30.
        int tagNum = first & 0x1f;
        if (tagNum == 0x1F) {
            // Tag number greater than 30
            if (buf.remaining() == 0) {
                throw new IllegalArgumentException("Insufficient data to decode tag number greater than 30");
            }
            tagNum = 0;
            while (buf.hasRemaining()) {
                byte octet = buf.get();
                tagNum = (tagNum << 7) + (octet & 0x7f);
                if ((octet >> 7) == 0) {
                    break;
                }
            }
        }
        id.tagNumber = tagNum;

        return id;
    }
631204
public AsciiString decode(ByteBuf buf, int length) throws Http2Exception {
        processor.reset();
        buf.forEachByte(buf.readerIndex(), length, processor);
        buf.skipBytes(length);
        return processor.end();
    }
1042396
public static long readLong(ByteBuffer buf) {
        byte len=buf.get();
        if(len == 0)
            return 0;
        return makeLong(buf, len);
    }
651593
public int read(byte []buf, int offset, int length) throws IOException
  {
    int strlen = _length;

    int start = offset;
    int end = offset + length;
    
    int index = _index;
    for (; index < strlen && offset < end; index++) {
      int ch = _string.charAt(index);

      if (ch < 0x80)
        buf[offset++] = (byte) ch;
      else if (ch < 0x800 && offset + 1 < end) {
        buf[offset++] = (byte) (0xc0 | (ch >> 6));
        buf[offset++] = (byte) (0x80 | (ch & 0x3f));
      }
      else if (ch < 0x8000 && offset + 2 < end) {
        buf[offset++] = (byte) (0xe0 | (ch >> 12));
        buf[offset++] = (byte) (0x80 | ((ch >> 6) & 0x3f));
        buf[offset++] = (byte) (0x80 | ((ch >> 6) & 0x3f));
      }
      else if (offset == start) {
        throw new IllegalStateException("buffer length is not large enough to decode UTF-8 data");
      }
      else {
        break;
      }
    }

    _index = index;

    return start < offset ? offset - start : -1;
  }
1236672
def decode_network_packet(buf):
    
    off = 0
    blen = len(buf)

    while off < blen:
        ptype, plen = header.unpack_from(buf, off)

        if plen > blen - off:
            raise ValueError("Packet longer than amount of data in buffer")

        if ptype not in _decoders:
            raise ValueError("Message type %i not recognized" % ptype)

        yield ptype, _decoders[ptype](ptype, plen, buf[off:])
        off += plen
224388
public static function decodeUnsigned(string $buf, int &$x): int
    {
        $x = 0;
        $s = 0;
        for ($i = 0; $i < strlen($buf); $i++) {
            $b = ord($buf[$i]);
            if ($b < 0x80) {
                if ($i > 9 || $i == 9 && $b > 1) {
                    // overflow
                    $x = 0;
                    return -($i + 1);
                }
                $x = $x | $b << $s;
                return $i + 1;
            }
            $x |= ($b & 0x7f) << $s;
            $s += 7;
        }
        $x = 0;
        return 0;
    }
52453
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        if ( this.largeFile ) {
            this.pid = SMBUtil.readInt2(buffer, bufferIndex);
            int boHigh = SMBUtil.readInt4(buffer, bufferIndex + 4);
            int boLow = SMBUtil.readInt4(buffer, bufferIndex + 8);

            this.byteOffset = ( boHigh << 32 ) | boLow;

            int lHigh = SMBUtil.readInt4(buffer, bufferIndex + 12);
            int lLow = SMBUtil.readInt4(buffer, bufferIndex + 16);

            this.lengthInBytes = ( lHigh << 32 ) | lLow;
            return 20;
        }
        this.pid = SMBUtil.readInt2(buffer, bufferIndex);
        this.byteOffset = SMBUtil.readInt4(buffer, bufferIndex + 2);
        this.lengthInBytes = SMBUtil.readInt4(buffer, bufferIndex + 6);
        return 10;
    }
38726
@SuppressWarnings("WeakerAccess")
    public static AVLTreeDigest fromBytes(ByteBuffer buf) {
        int encoding = buf.getInt();
        if (encoding == VERBOSE_ENCODING) {
            double min = buf.getDouble();
            double max = buf.getDouble();
            double compression = buf.getDouble();
            AVLTreeDigest r = new AVLTreeDigest(compression);
            r.setMinMax(min, max);
            int n = buf.getInt();
            double[] means = new double[n];
            for (int i = 0; i < n; i++) {
                means[i] = buf.getDouble();
            }
            for (int i = 0; i < n; i++) {
                r.add(means[i], buf.getInt());
            }
            return r;
        } else if (encoding == SMALL_ENCODING) {
            double min = buf.getDouble();
            double max = buf.getDouble();
            double compression = buf.getDouble();
            AVLTreeDigest r = new AVLTreeDigest(compression);
            r.setMinMax(min, max);
            int n = buf.getInt();
            double[] means = new double[n];
            double x = 0;
            for (int i = 0; i < n; i++) {
                double delta = buf.getFloat();
                x += delta;
                means[i] = x;
            }

            for (int i = 0; i < n; i++) {
                int z = decode(buf);
                r.add(means[i], z);
            }
            return r;
        } else {
            throw new IllegalStateException("Invalid format for serialized histogram");
        }
    }
709875
public synchronized void returnBuf(byte[] buf) {
        if (buf == null || buf.length > mSizeLimit) {
            return;
        }
        mBuffersByLastUse.add(buf);
        int pos = Collections.binarySearch(mBuffersBySize, buf, BUF_COMPARATOR);
        if (pos < 0) {
            pos = -pos - 1;
        }
        mBuffersBySize.add(pos, buf);
        mCurrentSize += buf.length;
        trim();
    }
1303209
public boolean decode(ChannelBuffer buffer, CommandOutput<K, V, ?> output) {
        int length, end;
        ByteBuffer bytes;

        if (stack.isEmpty()) {
            stack.add(new State());
        }

        loop:

        while (!stack.isEmpty()) {
            State state = stack.peek();

            if (state.type == null) {
                if (!buffer.readable()) break;
                state.type = readReplyType(buffer);
                buffer.markReaderIndex();
            }

            switch (state.type) {
                case SINGLE:
                    if ((bytes = readLine(buffer)) == null) break loop;
                    if (!QUEUED.equals(bytes)) {
                        output.set(bytes);
                    }
                    break;
                case ERROR:
                    if ((bytes = readLine(buffer)) == null) break loop;
                    output.setError(bytes);
                    break;
                case INTEGER:
                    if ((end = findLineEnd(buffer)) == -1) break loop;
                    output.set(readLong(buffer, buffer.readerIndex(), end));
                    break;
                case BULK:
                    if ((end = findLineEnd(buffer)) == -1) break loop;
                    length = (int) readLong(buffer, buffer.readerIndex(), end);
                    if (length == -1) {
                        output.set(null);
                    } else {
                        state.type = BYTES;
                        state.count = length + 2;
                        buffer.markReaderIndex();
                        continue loop;
                    }
                    break;
                case MULTI:
                    if (state.count == -1) {
                        if ((end = findLineEnd(buffer)) == -1) break loop;
                        length = (int) readLong(buffer, buffer.readerIndex(), end);
                        state.count = length;
                        buffer.markReaderIndex();
                    }

                    if (state.count <= 0) break;

                    state.count--;
                    stack.addFirst(new State());
                    continue loop;
                case BYTES:
                    if ((bytes = readBytes(buffer, state.count)) == null) break loop;
                    output.set(bytes);
            }

            buffer.markReaderIndex();
            stack.remove();
            output.complete(stack.size());
        }

        return stack.isEmpty();
    }
1109657
int decode(Buffer b) {
        int ptr = 0;
        DecodeAux t = decode_tree;
        int lok = b.look(t.tabn);

        if (lok >= 0) {
            ptr = t.tab[lok];
            b.adv(t.tabl[lok]);
            if (ptr <= 0) {
                return -ptr;
            }
        }
        do {
            switch (b.read1()) {
                case 0:
                    ptr = t.ptr0[ptr];
                    break;
                case 1:
                    ptr = t.ptr1[ptr];
                    break;
                case -1:
                default:
                    return (-1);
            }
        } while (ptr > 0);
        return (-ptr);
    }