writer.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <util/ysaveload.h>
  2. #include "writer.h"
  3. static inline void WriteAux(IOutputStream* out, const TVector<ui64>& data) {
  4. ::SavePodArray(out, data.data(), data.size());
  5. }
  6. /*************************** TBuffersWriter ***************************/
  7. TChunkedDataWriter::TChunkedDataWriter(IOutputStream& slave)
  8. : Slave(slave)
  9. , Offset(0)
  10. {
  11. }
  12. TChunkedDataWriter::~TChunkedDataWriter() {
  13. }
  14. void TChunkedDataWriter::NewBlock() {
  15. if (Offsets.size()) {
  16. Lengths.push_back(Offset - Offsets.back());
  17. }
  18. Pad(16);
  19. Offsets.push_back(Offset);
  20. }
  21. void TChunkedDataWriter::WriteFooter() {
  22. Lengths.push_back(Offset - Offsets.back());
  23. WriteAux(this, Lengths);
  24. WriteAux(this, Offsets);
  25. WriteBinary<ui64>(Offsets.size());
  26. WriteBinary<ui64>(Version);
  27. WriteBinary<ui64>(0);
  28. }
  29. size_t TChunkedDataWriter::GetCurrentBlockOffset() const {
  30. Y_ASSERT(!Offsets.empty());
  31. Y_ASSERT(Offset >= Offsets.back());
  32. return Offset - Offsets.back();
  33. }
  34. size_t TChunkedDataWriter::GetBlockCount() const {
  35. return Offsets.size();
  36. }