| 80 | } |
| 81 | |
| 82 | Status Writer::EmitPhysicalRecord(RecordType t, const char* ptr, |
| 83 | size_t length) { |
| 84 | assert(length <= 0xffff); // Must fit in two bytes |
| 85 | assert(block_offset_ + kHeaderSize + length <= kBlockSize); |
| 86 | |
| 87 | // Format the header |
| 88 | char buf[kHeaderSize]; |
| 89 | buf[4] = static_cast<char>(length & 0xff); |
| 90 | buf[5] = static_cast<char>(length >> 8); |
| 91 | buf[6] = static_cast<char>(t); |
| 92 | |
| 93 | // Compute the crc of the record type and the payload. |
| 94 | uint32_t crc = crc32c::Extend(type_crc_[t], ptr, length); |
| 95 | crc = crc32c::Mask(crc); // Adjust for storage |
| 96 | EncodeFixed32(buf, crc); |
| 97 | |
| 98 | // Write the header and the payload |
| 99 | Status s = dest_->Append(Slice(buf, kHeaderSize)); |
| 100 | if (s.ok()) { |
| 101 | s = dest_->Append(Slice(ptr, length)); |
| 102 | if (s.ok()) { |
| 103 | s = dest_->Flush(); |
| 104 | } |
| 105 | } |
| 106 | block_offset_ += kHeaderSize + length; |
| 107 | return s; |
| 108 | } |
| 109 | |
| 110 | } // namespace log |
| 111 | } // namespace leveldb |