| 157 | } |
| 158 | |
| 159 | void PacketReadCache::readPacket( unsigned oldestEntry, uint64_t packetLogicalOffset ) |
| 160 | { |
| 161 | #ifdef E57_VERBOSE |
| 162 | std::cout << "PacketReadCache::readPacket() called, oldestEntry=" << oldestEntry |
| 163 | << " packetLogicalOffset=" << packetLogicalOffset << std::endl; |
| 164 | #endif |
| 165 | |
| 166 | // Read header of packet first to get length. Use EmptyPacketHeader since it has the fields |
| 167 | // common to all packets. |
| 168 | EmptyPacketHeader header; |
| 169 | |
| 170 | cFile_->seek( packetLogicalOffset, CheckedFile::Logical ); |
| 171 | cFile_->read( reinterpret_cast<char *>( &header ), sizeof( header ) ); |
| 172 | |
| 173 | // Can't verify packet header here, because it is not really an EmptyPacketHeader. |
| 174 | unsigned packetLength = header.packetLogicalLengthMinus1 + 1; |
| 175 | |
| 176 | // Be paranoid about packetLength before read |
| 177 | if ( packetLength > DATA_PACKET_MAX ) |
| 178 | { |
| 179 | throw E57_EXCEPTION2( ErrorBadCVPacket, "packetLength=" + toString( packetLength ) ); |
| 180 | } |
| 181 | |
| 182 | auto &entry = entries_.at( oldestEntry ); |
| 183 | |
| 184 | // Now read in whole packet into preallocated buffer_. Note buffer is |
| 185 | cFile_->seek( packetLogicalOffset, CheckedFile::Logical ); |
| 186 | cFile_->read( entry.buffer_, packetLength ); |
| 187 | |
| 188 | // Verify that packet is good. |
| 189 | switch ( header.packetType ) |
| 190 | { |
| 191 | case DATA_PACKET: |
| 192 | { |
| 193 | auto dpkt = reinterpret_cast<DataPacket *>( entry.buffer_ ); |
| 194 | |
| 195 | dpkt->verify( packetLength ); |
| 196 | #ifdef E57_VERBOSE |
| 197 | std::cout << " data packet:" << std::endl; |
| 198 | dpkt->dump( 4 ); //??? |
| 199 | #endif |
| 200 | } |
| 201 | break; |
| 202 | case INDEX_PACKET: |
| 203 | { |
| 204 | auto ipkt = reinterpret_cast<IndexPacket *>( entry.buffer_ ); |
| 205 | |
| 206 | ipkt->verify( packetLength ); |
| 207 | #ifdef E57_VERBOSE |
| 208 | std::cout << " index packet:" << std::endl; |
| 209 | ipkt->dump( 4 ); //??? |
| 210 | #endif |
| 211 | } |
| 212 | break; |
| 213 | case EMPTY_PACKET: |
| 214 | { |
| 215 | auto hp = reinterpret_cast<EmptyPacketHeader *>( entry.buffer_ ); |
| 216 | |