From feaa963f704ab5b677ad8978c4f9a42f0ceb145d Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Thu, 20 Jun 2024 16:37:55 -0400 Subject: [PATCH] {standard} Always write a CV index packet (#295) This is required by the standard. 9.3.5: "A CompressedVector shall contain at least one index packet and at least one data packet." To satisfy this requirement, we write one index packet containing one entry which points to the first data packet. --- src/CompressedVectorWriterImpl.cpp | 28 ++++++++++++++++++++++++++++ src/CompressedVectorWriterImpl.h | 1 + 2 files changed, 29 insertions(+) diff --git a/src/CompressedVectorWriterImpl.cpp b/src/CompressedVectorWriterImpl.cpp index 01159da..52a938e 100644 --- a/src/CompressedVectorWriterImpl.cpp +++ b/src/CompressedVectorWriterImpl.cpp @@ -183,6 +183,9 @@ namespace e57 flush(); } + // Write one index packet (required by standard). + packetWriteIndex(); + // Compute length of whole section we just wrote (from section start to // current start of free space). sectionLogicalLength_ = imf->unusedLogicalStart_ - sectionHeaderLogicalStart_; @@ -660,6 +663,31 @@ namespace e57 dataPacketsCount_++; } + // Write one index packet. + // We don't have an interface to work with index packets, but one is required by the standard, so + // write one index packet with one entry pointing to the first data packet. + void e57::CompressedVectorWriterImpl::packetWriteIndex() + { + ImageFileImplSharedPtr imf( cVector_->destImageFile_ ); + + IndexPacket indexPacket; + + indexPacket.entries[0].chunkPhysicalOffset = dataPhysicalOffset_; + + const auto cPacketLength = sizeof( IndexPacketHeader ) + sizeof( IndexPacket::Entry ); + + indexPacket.header.packetLogicalLengthMinus1 = cPacketLength - 1; + indexPacket.header.entryCount = 1; + + uint64_t packetLogicalOffset = imf->allocateSpace( cPacketLength, false ); + topIndexPhysicalOffset_ = imf->file_->logicalToPhysical( packetLogicalOffset ); + + imf->file_->seek( packetLogicalOffset ); + imf->file_->write( reinterpret_cast( &indexPacket ), cPacketLength ); + + indexPacketsCount_++; + } + void CompressedVectorWriterImpl::flush() { for ( auto &bytestream : bytestreams_ ) diff --git a/src/CompressedVectorWriterImpl.h b/src/CompressedVectorWriterImpl.h index 6fa2760..5596267 100644 --- a/src/CompressedVectorWriterImpl.h +++ b/src/CompressedVectorWriterImpl.h @@ -58,6 +58,7 @@ namespace e57 size_t currentPacketSize() const; uint64_t packetWrite(); void packetWriteZeroRecords(); + void packetWriteIndex(); void flush();