bool Protocol::encodeHeader()

in Protocol.cpp [141:168]


bool Protocol::encodeHeader(int senderProtocolVersion, char *dest, int64_t &off,
                            const int64_t max,
                            const BlockDetails &blockDetails) {
  WDT_CHECK_GE(max, 0);
  const size_t umax = static_cast<size_t>(max);  // we made sure it's not < 0
  bool ok = encodeString(dest, max, off, blockDetails.fileName) &&
            encodeVarI64C(dest, umax, off, blockDetails.seqId) &&
            encodeVarI64C(dest, umax, off, blockDetails.dataSize) &&
            encodeVarI64C(dest, umax, off, blockDetails.offset) &&
            encodeVarI64C(dest, umax, off, blockDetails.fileSize);
  if (ok && senderProtocolVersion >= HEADER_FLAG_AND_PREV_SEQ_ID_VERSION) {
    uint8_t flags = blockDetails.allocationStatus;
    if (off >= max) {
      ok = false;
    } else {
      dest[off++] = static_cast<char>(flags);
      if (flags == EXISTS_TOO_SMALL || flags == EXISTS_TOO_LARGE) {
        // prev seq-id is only used in case the size is less on the sender side
        ok = encodeVarI64C(dest, umax, off, blockDetails.prevSeqId);
      }
    }
  }
  if (!ok) {
    WLOG(ERROR) << "Failed to encode header, ran out of space, " << off << " "
                << max;
  }
  return ok;
}