| 88 | } |
| 89 | |
| 90 | uint64_t Dg3Block::Write(std::streambuf& buffer) { |
| 91 | const bool update = |
| 92 | FilePosition() > 0; // Write or update the values inside the block |
| 93 | nof_cg_blocks_ = static_cast<uint16_t>(cg_list_.size()); |
| 94 | nof_record_id_ = nof_cg_blocks_ > 1 ? 1 : 0; |
| 95 | if (!update) { |
| 96 | block_type_ = "DG"; |
| 97 | block_size_ = (2 + 2) + (4 * 4) + 2 + 2 + 4; |
| 98 | link_list_.resize(4, 0); |
| 99 | } |
| 100 | |
| 101 | uint64_t bytes = update ? MdfBlock::Update(buffer) : MdfBlock::Write(buffer); |
| 102 | bytes += WriteNumber(buffer, nof_cg_blocks_); |
| 103 | bytes += WriteNumber(buffer, nof_record_id_); |
| 104 | const std::vector<uint8_t> reserved(4, 0); |
| 105 | bytes += WriteByte(buffer, reserved); |
| 106 | |
| 107 | if (tr_block_ && Link(kIndexTr) <= 0) { |
| 108 | tr_block_->Write(buffer); |
| 109 | UpdateLink(buffer, kIndexTr, tr_block_->FilePosition()); |
| 110 | } |
| 111 | |
| 112 | for (size_t cg_index = 0; cg_index < cg_list_.size(); ++cg_index) { |
| 113 | auto &cg3 = cg_list_[cg_index]; |
| 114 | if (!cg3) { |
| 115 | continue; |
| 116 | } |
| 117 | cg3->Write(buffer); |
| 118 | if (cg_index == 0) { |
| 119 | UpdateLink(buffer, kIndexCg, cg3->FilePosition()); |
| 120 | } else { |
| 121 | auto &prev = cg_list_[cg_index - 1]; |
| 122 | if (prev) { |
| 123 | prev->UpdateLink(buffer, kIndexNext, cg3->FilePosition()); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | for (size_t ii = 0; ii < block_list_.size(); ++ii) { |
| 129 | auto &data = block_list_[ii]; |
| 130 | if (!data) { |
| 131 | continue; |
| 132 | } |
| 133 | if (data->FilePosition() > 0) { |
| 134 | continue; |
| 135 | } |
| 136 | data->Write(buffer); |
| 137 | if (ii == 0) { |
| 138 | UpdateLink(buffer, kIndexData, data->FilePosition()); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return bytes; |
| 143 | } |
| 144 | |
| 145 | void Dg3Block::AddCg3(std::unique_ptr<Cg3Block> &cg3) { |
| 146 | cg3->Init(*this); |
nothing calls this directly
no test coverage detected