Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{standard} Always write a CV index packet #295

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading