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

Move index packet classes into Packet.h #294

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
41 changes: 8 additions & 33 deletions src/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,6 @@

using namespace e57;

struct IndexPacketHeader
{
const uint8_t packetType = INDEX_PACKET;

uint8_t packetFlags = 0; // flag bitfields
uint16_t packetLogicalLengthMinus1 = 0;
uint16_t entryCount = 0;
uint8_t indexLevel = 0;
uint8_t reserved1[9] = {}; // must be zero
};

struct IndexPacket
{
IndexPacketHeader header;

static constexpr unsigned MAX_ENTRIES = 2048;

struct IndexPacketEntry
{
uint64_t chunkRecordNumber = 0;
uint64_t chunkPhysicalOffset = 0;
} entries[MAX_ENTRIES];

void verify( unsigned bufferLength = 0, uint64_t totalRecordCount = 0,
uint64_t fileSize = 0 ) const;

#ifdef E57_ENABLE_DIAGNOSTIC_OUTPUT
void dump( int indent = 0, std::ostream &os = std::cout ) const;
#endif
};

struct EmptyPacketHeader
{
const uint8_t packetType = EMPTY_PACKET;
Expand Down Expand Up @@ -558,6 +527,13 @@ void DataPacket::dump( int indent, std::ostream &os ) const

//=============================================================================
// IndexPacket
IndexPacket::IndexPacket()
{
// Double check that packet struct is correct length. Watch out for RTTI increasing the size.
// sizeof( IndexPacketHeader ) + ( MAX_ENTRIES * sizeof( IndexPacket::Entry ) )
static_assert( sizeof( IndexPacket ) == ( 16 + ( 2048 * 16 ) ),
"Unexpected size of IndexPacket" );
}

void IndexPacket::verify( unsigned bufferLength, uint64_t totalRecordCount,
uint64_t fileSize ) const
Expand Down Expand Up @@ -643,8 +619,7 @@ void IndexPacket::verify( unsigned bufferLength, uint64_t totalRecordCount,
}

// Check if entries will fit in space provided
const unsigned cNeededLength =
sizeof( IndexPacketHeader ) + sizeof( IndexPacketEntry ) * header.entryCount;
const unsigned cNeededLength = sizeof( IndexPacketHeader ) + sizeof( Entry ) * header.entryCount;
if ( packetLength < cNeededLength )
{
throw E57_EXCEPTION2( ErrorBadCVPacket, "INDEX; packetLength=" + toString( packetLength ) +
Expand Down
35 changes: 35 additions & 0 deletions src/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,39 @@ namespace e57

uint8_t payload[PayloadSize]; // No need to init since it's a data buffer
};

class IndexPacketHeader
{
public:
const uint8_t packetType = INDEX_PACKET;

uint8_t packetFlags = 0; // flag bitfields
uint16_t packetLogicalLengthMinus1 = 0;
uint16_t entryCount = 0;
uint8_t indexLevel = 0;
uint8_t reserved1[9] = {}; // must be zero
};

class IndexPacket
{
public:
IndexPacket();

void verify( unsigned bufferLength = 0, uint64_t totalRecordCount = 0,
uint64_t fileSize = 0 ) const;

#ifdef E57_ENABLE_DIAGNOSTIC_OUTPUT
void dump( int indent = 0, std::ostream &os = std::cout ) const;
#endif

IndexPacketHeader header;

static constexpr unsigned MAX_ENTRIES = 2048;

struct Entry
{
uint64_t chunkRecordNumber = 0;
uint64_t chunkPhysicalOffset = 0;
} entries[MAX_ENTRIES];
};
}
Loading