<fim-prefix>dI64() throws TException {
    return zigzagToLong(readVarint64());
  }

  /** No magic here - just read a double off the wire. */
  public double readDouble() throws TException {
    trans_.readAll(buffer, 0, 8);
    long value;
    if (version_ >= VERSION_DOUBLE_BE) {
      value = bytesToLong(buffer);
    } else {
      value = bytesToLongLE(buffer);
    }
    return Double.longBitsToDouble(value);
  }

  /** No magic here - just read a float off the wire. */
  public float readFloat() throws TException {
    trans_.readAll(buffer, 0, 4);
    int value = bytesToInt(buffer);
    return Float.intBitsToFloat(value);
  }

  /** Reads a byte[] (via readBinary), and then UTF-8 decodes it. */
  public String readString() throws TException {
    int length = readVarint32();
    checkReadLength(length);

    if (length == 0) {
      return "";
    }

    if (trans_.getBytesRemainingInBuffer() >= length) {
      String str =
          new String(
              trans_.getBuffer(), trans_.getBufferPosition(), length, StandardCharsets.UTF_8);
      trans_.consumeBuffer(length);
      return str;
    } else {
      return new String(readBinary(length), StandardCharsets.UTF_8);
    }
  }

  /** Read a byte[] from the wire. */
  public byte[] readBinary() throws TException {
    int length = readVarint32();
    checkReadLength(length);
    return readBinary(length);
  }

  private byte[] readBinary(int length) throws TException {
    if (length == 0) {
      return new byte[0];
    }
    // BUG: CWE-770 Allocation of Resources Without Limits or Throttling
    // 
    // FIXED: 
<fim-middle>    ensureContainerHasEnough(length, TType.BYTE);
    byte[] buf = new byte[length];
    trans_.readAll(buf, 0, length);
    return buf;
  }

  private void checkReadLength(int length) throws TProtocol<fix-suffix>Exception {
    if (length < 0) {
      throw new TProtocolException("Negative length: " + length);
    }
    if (maxNetworkBytes_ != -1 && length > maxNetworkBytes_) {
      throw new TProtocolException("Length exceeded max allowed: " + length);
    }
  }

  //
  // These methods are here for the struct to call, but don't have any wire
  // encoding.
  //
  public void readMessageEnd() throws TException {}

  public void readFieldEnd() throws TException {}

  public void readMapEnd() throws TException {}

  public void readListEnd() throws TException {}

  public void readSetEnd() throws TException {}

  //
  // Internal reading methods
  //

  /**
   * Read an i32 from the wire as a varint. The MSB of each byte is set if there is another byte to
   * follow. This can read up to 5 bytes.
   */
  private int readVarint32() throws TException {
    int result = 0;
    int shift = 0;
    if (trans_.getBytesRemainingInBuffer() >= 5) {
      byte[] buf = trans_.getBuffer();
      int pos = <|endoftext|>