public Status AddRecord(Slice slice) {
		byte[] data = slice.data();
		int ptr = 0;
		int left = slice.size();

		// Fragment the record if necessary and emit it. Note that if slice
		// is empty, we still want to iterate once to emit a single
		// zero-length record
		Status s;
		boolean begin = true;
		do {
			int leftover = logformat.kBlockSize - block_offset_;
			assert (leftover >= 0);
			if (leftover < logformat.kHeaderSize) {
				// Switch to a new block
				if (leftover > 0) {
					// Fill the trailer with 0s(literal below relies on
					// kHeaderSize being 7)
					//assert (logformat.kHeaderSize == 7);
					dest_.Append(new Slice(new byte[] { 0, 0, 0, 0, 0, 0 },
							leftover));
				}
				block_offset_ = 0;
			}

			// Invariant: we never leave < kHeaderSize bytes in a block.
			assert (logformat.kBlockSize - block_offset_
					- logformat.kHeaderSize >= 0);

			int avail = logformat.kBlockSize - block_offset_
					- logformat.kHeaderSize;
			int fragment_length = (left < avail) ? left : avail;

			int type;
			boolean end = (left == fragment_length);
			if (begin && end) {
				type = RecordType.kFullType;
			} else if (begin) {
				type = RecordType.kFirstType;
			} else if (end) {
				type = RecordType.kLastType;
			} else {
				type = RecordType.kMiddleType;
			}

			// TODO: think about it: do not copy the bytes, add offset here
			byte[] tmp = util.subN(data, ptr, fragment_length);
			s = EmitPhysicalRecord(new RecordType(type), tmp, fragment_length);
			
			ptr += fragment_length;
			left -= fragment_length;
			begin = false;
		} while (s.ok() && left > 0);
		return s;
	}