docs: public static long fromByteBuffer(ByteBuffer buf) {
        if (buf.remaining() < 1) {
           // XXX make all callers check for -1
           return -1;
        }
        long first = 0x00000000000000FFL & ((long) buf.get());
        long value;
        if (first < 253) {
           // Regard this byte as a 8 bit value.
           value = 0x00000000000000FFL & ((long) first);
        } else if (first == 253) {
           // Regard the following two bytes as a 16 bit value
           if (buf.remaining() < 2) {
              return -1;
           }
           buf.order(ByteOrder.LITTLE_ENDIAN);
           value = 0x0000000000FFFFL & ((long) buf.getShort());
        } else if (first == 254) {
           // Regard the following four bytes as a 32 bit value
           if (buf.remaining() < 4) {
              return -1;
           }
           buf.order(ByteOrder.LITTLE_ENDIAN);
           value = 0x00000000FFFFFFFF & ((long) buf.getInt());
        } else {
           // Regard the following four bytes as a 64 bit value
           if (buf.remaining() < 8) {
              return -1;
           }
           buf.order(ByteOrder.LITTLE_ENDIAN);
           value = buf.getLong();
        }
        return value;
     }