bool Protocol::decodeHeader()

in Protocol.cpp [170:198]


bool Protocol::decodeHeader(int receiverProtocolVersion, char *src,
                            int64_t &off, const int64_t max,
                            BlockDetails &blockDetails) {
  ByteRange br = makeByteRange(src, max, off);  // will check for off>0 max>0
  const ByteRange obr = br;

  bool ok = decodeString(br, blockDetails.fileName) &&
            decodeInt64C(br, blockDetails.seqId) &&
            decodeInt64C(br, blockDetails.dataSize) &&
            decodeInt64C(br, blockDetails.offset) &&
            decodeInt64C(br, blockDetails.fileSize);
  if (ok && receiverProtocolVersion >= HEADER_FLAG_AND_PREV_SEQ_ID_VERSION) {
    if (br.empty()) {
      WLOG(ERROR) << "Invalid (too short) input len " << max << " at offset "
                  << (max - obr.size());
      return false;
    }
    uint8_t flags = br.front();
    // first 3 bits are used to represent allocation status
    blockDetails.allocationStatus = (FileAllocationStatus)(flags & 7);
    br.pop_front();
    if (blockDetails.allocationStatus == EXISTS_TOO_SMALL ||
        blockDetails.allocationStatus == EXISTS_TOO_LARGE) {
      ok = decodeInt64C(br, blockDetails.prevSeqId);
    }
  }
  off += offset(br, obr);
  return ok;
}