Skip to content

Commit

Permalink
Move index packet classes into Packet.h (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Jun 20, 2024
1 parent b5d9f5e commit bde7dc6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
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];
};
}

0 comments on commit bde7dc6

Please sign in to comment.