18 std::vector<char> data_;
25 Segment(
const Segment&) =
default;
30 Segment(Segment&& rhp) :
32 data_(std::move(rhp.data_)),
50 Segment& operator=(
const Segment& rhp) =
delete;
56 idx_(idx), bytes_(bytes)
59 "Attempted to create segment of " << bytes <<
" bytes with invalid line index");
61 ::memcpy(data_.data(), data, bytes);
64 template <
typename Archive>
65 void serialize(Archive& ar,
const unsigned int ) {
75 uint32_t getSize()
const {
76 return sizeof(
decltype(*this)) + bytes_;
79 void copyTo(
char* buf, uint32_t size)
const {
81 "Attempted to restore checkpoint data for a line where the "
82 "data was " << bytes_ <<
" bytes but the loader requested "
83 << size <<
" bytes. The sizes must match up or something is "
85 memcpy(buf, data_.data(), bytes_);
88 void dump(std::ostream& o)
const {
90 std::cout <<
"\nEnd of ArchData";
94 std::cout <<
"\nLine: " << std::dec << idx_ <<
" (" << bytes_ <<
") bytes";
95 for(uint32_t off = 0; off < bytes_;){
96 char chr = data_[off];
98 o << std::endl << std::setw(7) << std::hex << off;
103 o <<
' ' << std::setfill(
'0') << std::setw(2) << std::hex << (0xff & (uint16_t)chr);
113 std::vector<Segment> data_;
123 uint32_t next_restore_idx_ = 0;
129 decltype(data_)::const_iterator cur_restore_itr_;
140 template <
typename Archive>
141 void serialize(Archive& ar,
const unsigned int ) {
145 void dump(std::ostream& o)
const {
146 for(
auto const &seg : data_){
151 uint32_t getSize()
const {
152 uint32_t bytes =
sizeof(
decltype(*this));
153 for(Segment
const & seg : data_){
154 bytes += seg.getSize();
159 void prepareForLoad() {
160 next_restore_idx_ = 0;
161 cur_restore_itr_ = data_.begin();
166 "Cannot begin line with INVALID_LINE_IDX index");
170 void writeLineBytes(
const char* data,
size_t size) {
171 sparta_assert(data_.size() == 0 || data_.back().getLineIdx() != next_idx_,
172 "Cannot store the same line idx twice in a checkpoint. Line "
173 << next_idx_ <<
" detected twice in a row");
175 "Cannot write line bytes with INVALID_LINE_IDX index");
176 data_.emplace_back(next_idx_, data, size);
183 data_.emplace_back();
191 return next_restore_idx_ <= data_.size();
199 if(next_restore_idx_ == data_.size()){
202 }
else if(next_restore_idx_ > data_.size()){
204 <<
"caller tried to keep getting next line even after "
205 "reaching the end of the restore data";
207 if(next_restore_idx_ != 0){
212 const auto next_line_idx = cur_restore_itr_->getLineIdx();
213 return next_line_idx;
221 "Attempted to copy line bytes from an invalid line iterator");
223 "About to return line from checkpoint data segment with INVALID_LINE_IDX index");
224 cur_restore_itr_->copyTo(buf, size);