Exemple #1
0
void
RLECompressor::decompress(const ::Compression::Buffer &source, ::Compression::Buffer &target)
{
    ACE_UINT64 out_len = ACE_RLECompression::instance()->decompress(source.get_buffer(),
                                                                    source.length(),
                                                                    target.get_buffer(),
                                                                    target.maximum() );
    if (ACE_UINT64(-1) == out_len) { // Overrun
        throw ::Compression::CompressionException();
    }

    target.length(static_cast<CORBA::ULong>(out_len));
}
Exemple #2
0
// Decompress using Run Length Encoding (RLE)
ACE_UINT64
ACE_RLECompressor::decompress( const void *in_ptr,
                               ACE_UINT64 in_len,
                               void *out_ptr,
                               ACE_UINT64 max_out_len )
{
    ACE_UINT64  out_len     = 0;

    const ACE_Byte *in_p    = static_cast<const ACE_Byte *>(in_ptr);
    ACE_Byte *out_p         = static_cast<ACE_Byte *>(out_ptr);

    if (in_p && out_p) while(in_len-- > 0) {

        ACE_Byte    cur_byte    = *in_p++;
        ACE_UINT32  cpy_len     = ACE_UINT32((cur_byte & ACE_CHAR_MAX) + 1);

        if (cpy_len > max_out_len) {
            return ACE_UINT64(-1); // Output Exhausted
        } else if ((cur_byte & 0x80) != 0) {  // compressed
            if (in_len-- > 0) {
                ACE_OS::memset(out_p, *in_p++, cpy_len);
            } else {
                return ACE_UINT64(-1); // Output Exhausted
            }
        } else if (in_len >= cpy_len) {
            ACE_OS::memcpy(out_p, in_p, cpy_len);
            in_p    += cpy_len;
            in_len  -= cpy_len;
        } else {
            return ACE_UINT64(-1); // Output Exhausted
        }

        out_p       += cpy_len;
        max_out_len -= cpy_len;
        out_len     += cpy_len;
    }

    return out_len;
}
    std::string
    DDS_Dissector::format (const DCPS::TransportHeader& header)
    {
      std::ostringstream os;

      os << "Length: " << std::dec << header.length_;
      if (header.first_fragment_) os << ", First Fragment";
      if (header.last_fragment_) os << ", Last Fragment";
      os << ", Sequence: 0x" << std::hex << std::setw(8) << std::setfill('0')
         << header.sequence_.getValue();
      os << ", Source: 0x" << std::hex << std::setw(16) << std::setfill('0')
         << ACE_UINT64(header.source_);

      return os.str();
    }
Exemple #4
0
void
RLECompressor::compress(const ::Compression::Buffer &source, ::Compression::Buffer &target)
{
    // Ensure maximum is at least X 1.1 input length.
    target.length(static_cast<CORBA::ULong>((source.length() * 1.1) + 32U));

    ACE_UINT64 out_len = ACE_RLECompression::instance()->compress( source.get_buffer(),
                                                                   source.length(),
                                                                   target.get_buffer(),
                                                                   target.maximum() );
    if (ACE_UINT64(-1) == out_len) { // Overrun
        throw ::Compression::CompressionException();
    }

    target.length(static_cast< CORBA::ULong>(out_len)); // Set Output Buffer to the right size now.

    // Update statistics for this compressor
    this->update_stats(source.length(), target.length());
}
Exemple #5
0
// Compress using Run Length Encoding (RLE)
ACE_UINT64
ACE_RLECompressor::compress( const void *in_ptr,
                             ACE_UINT64 in_len,
                             void *out_ptr,
                             ACE_UINT64 max_out_len )
{
    const ACE_Byte *in_p    = static_cast<const ACE_Byte *>(in_ptr);
    ACE_Byte *out_p         = static_cast<ACE_Byte *>(out_ptr);

    ACE_UINT64 src_len      = in_len;  // Save for stats
    ACE_UINT64 out_index    = 0;
    ACE_UINT64 out_base     = 0;
    size_t     run_count    = 0;
    bool       run_code     = false;

    if (in_p && out_p && in_len) {

        while (in_len-- > 0) {

            ACE_Byte cur_byte = *in_p++;

            switch (out_index ? run_count : 128U) {  // BootStrap to 128

            case 128:

                if ((out_base = out_index++) >= max_out_len) {
                    return ACE_UINT64(-1);      // Output Exhausted
                }
                run_code  = false;
                run_count = 0; // Switch off compressing

                // Fall Through

            default:

                // Fix problem where input exhaused but maybe compressing
                if (in_len ? cur_byte == *in_p : run_code) {

                    if (run_code) {             // In Compression?
                        out_p[out_base] = ACE_Byte(run_count++ | 0x80);
                        continue;               // Stay in Compression
                    } else if (run_count) {     // Xfering to Compression
                        if ((out_base = out_index++) >= max_out_len) {
                            return ACE_UINT64(-1); // Output Exhausted
                        }
                        run_count = 0;
                    }
                    run_code  = true;           // We Are Now Compressing

                } else if (run_code) {          // Are we in Compression?
                    // Finalise the Compression Run Length
                    out_p[out_base] = ACE_Byte(run_count | 0x80);
                    // Reset for Uncmpressed
                    if (in_len && (out_base = out_index++) >= max_out_len) {
                        return ACE_UINT64(-1);  // Output Exhausted
                    }
                    run_code    = false;
                    run_count   = 0;
                    continue;   // Now restart Uncompressed
                }

                break;
            }

            out_p[out_base] = ACE_Byte(run_count++ | (run_code ? 0x80 : 0));

            if (out_index >= max_out_len) {
                return ACE_UINT64(-1);          // Output Exhausted
            }
            out_p[out_index++] = cur_byte;
        }
        this->update_stats(src_len, out_index);
    }

    return out_index;  // return as our output length
}
Exemple #6
0
ACE_UINT64
to_hrtime (double seconds,
           ACE_High_Res_Timer::global_scale_factor_type sf)
{
  return ACE_UINT64 (seconds * sf * ACE_HR_SCALE_CONVERSION);
}
Exemple #7
0
ACE_UINT64
ACE_RLECompressor::compress( const void *in_ptr,
                             ACE_UINT64 in_len,
                             void *out_ptr,
                             ACE_UINT64 max_out_len )
{
    const ACE_UINT8 *in_p   = static_cast<const ACE_UINT8*>(in_ptr);
    ACE_UINT8 *out_p        = static_cast<ACE_UINT8*>(out_ptr);

    ACE_UINT64  src_len     = in_len;  // Save for stats
    ACE_UINT64  out_len     = 0;
    ACE_UINT64  out_index   = 0;
    ACE_UINT64  out_base    = 0;

    ACE_UINT32  run_count   = 0;
    ACE_UINT32  dup_count   = 0;

    bool        run_code    = false;

    ACE_UINT8   nxt_byte, cur_byte;

    if (in_p && out_p) while (in_len-- > 0) {

        if (run_code) switch (run_count) {

        default:

            out_p[out_index = out_base] = ACE_UINT8(run_count++ | 0x80);
            out_p[++out_index] = cur_byte = *in_p++;

            if (in_len ? cur_byte == (nxt_byte = *in_p) : true) {
                continue;
            }

            // Fall Through

        case 128:

            if (++out_index >= max_out_len) {
                return ACE_UINT64(-1); // Output Exhausted
            } else if (in_len == 0) {
                continue;
            }

            run_code  = false;
            out_p[out_base = out_index] = 0;
            dup_count = run_count = 0;
            continue;
        }

        switch (run_count) {

        case 128:

            if (++out_index >= max_out_len) {
                return ACE_UINT64(-1); // Output Exhausted
            }
            out_p[out_base = out_index] = 0;
            dup_count = run_count = 0;

            // Fall Through

        default :

            cur_byte = *in_p++;

            if (in_len > 0) {
                if (cur_byte == (nxt_byte = *in_p)) {
                    if (dup_count++ == 1) {
                        if (run_count >= dup_count) {
                            out_p[out_base] = static_cast<ACE_UINT8>(run_count - dup_count);
                            out_base += run_count;
                        }
                        run_code  = true;
                        run_count = dup_count - 1;
                        dup_count = 0;
                        out_p[out_index = out_base] = static_cast<ACE_UINT8>(run_count++ | 0x80);
                        break;
                    }
                } else dup_count = 0;
            }
            out_p[out_base] = char(run_count++);
            break;
        }

        if (++out_index >= max_out_len) {
            return ACE_UINT64(-1); // Output Exhausted
        }

        out_p[out_index] = cur_byte;
    }

    out_len = ++out_index;  // Update our output length

    this->update_stats(src_len, out_len);

    return out_len;
}