| 421 | } |
| 422 | |
| 423 | uint64_t CompressedVectorWriterImpl::packetWrite() |
| 424 | { |
| 425 | #ifdef E57_VERBOSE |
| 426 | std::cout << "CompressedVectorWriterImpl::packetWrite() called" << std::endl; //??? |
| 427 | #endif |
| 428 | |
| 429 | // Double check that we have work to do |
| 430 | const size_t cTotalOutput = totalOutputAvailable(); |
| 431 | if ( cTotalOutput == 0 ) |
| 432 | { |
| 433 | return ( 0 ); |
| 434 | } |
| 435 | |
| 436 | // const bytestreams_ so it's clear it isn't modified in this function |
| 437 | const auto &cStreams = bytestreams_; |
| 438 | const auto cNumByteStreams = cStreams.size(); |
| 439 | |
| 440 | // Calc maximum number of bytestream values can put in data packet. |
| 441 | const size_t cPacketMaxPayloadBytes = |
| 442 | DATA_PACKET_MAX - sizeof( DataPacketHeader ) - cNumByteStreams * sizeof( uint16_t ); |
| 443 | |
| 444 | #ifdef E57_VERBOSE |
| 445 | std::cout << " totalOutput=" << cTotalOutput << std::endl; |
| 446 | std::cout << " cNumByteStreams=" << cNumByteStreams << std::endl; |
| 447 | std::cout << " packetMaxPayloadBytes=" << cPacketMaxPayloadBytes << std::endl; |
| 448 | #endif |
| 449 | |
| 450 | // Allocate vector for number of bytes that each bytestream will write to file. |
| 451 | std::vector<size_t> count( cNumByteStreams ); |
| 452 | |
| 453 | // See if we can fit into a single data packet |
| 454 | if ( cTotalOutput < cPacketMaxPayloadBytes ) |
| 455 | { |
| 456 | // We can fit everything in one packet |
| 457 | for ( unsigned i = 0; i < cNumByteStreams; ++i ) |
| 458 | { |
| 459 | count.at( i ) = cStreams.at( i )->outputAvailable(); |
| 460 | } |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | // We have too much data for one packet. Send proportional amounts from |
| 465 | // each bytestream. Adjust packetMaxPayloadBytes down by one so have a |
| 466 | // little slack for floating point weirdness. |
| 467 | const float cFractionToSend = |
| 468 | ( cPacketMaxPayloadBytes - 1 ) / static_cast<float>( cTotalOutput ); |
| 469 | for ( unsigned i = 0; i < cNumByteStreams; ++i ) |
| 470 | { |
| 471 | // Round down here so sum <= packetMaxPayloadBytes |
| 472 | count.at( i ) = static_cast<unsigned>( |
| 473 | std::floor( cFractionToSend * cStreams.at( i )->outputAvailable() ) ); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | #ifdef E57_VERBOSE |
| 478 | for ( unsigned i = 0; i < cNumByteStreams; ++i ) |
| 479 | { |
| 480 | std::cout << " count[" << i << "]=" << count.at( i ) << std::endl; |
nothing calls this directly
no test coverage detected