Skip to content

Commit

Permalink
{standard} Always write a CV index packet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asmaloney committed Jun 20, 2024
1 parent bde7dc6 commit 3da882a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/CompressedVectorWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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<const char *>( &indexPacket ), cPacketLength );

indexPacketsCount_++;
}

void CompressedVectorWriterImpl::flush()
{
for ( auto &bytestream : bytestreams_ )
Expand Down
1 change: 1 addition & 0 deletions src/CompressedVectorWriterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace e57
size_t currentPacketSize() const;
uint64_t packetWrite();
void packetWriteZeroRecords();
void packetWriteIndex();

void flush();

Expand Down

0 comments on commit 3da882a

Please sign in to comment.