Pl_RunLength::flush_encode()
{
    if (this->length == 128)
    {
        QTC::TC("libtests", "Pl_RunLength flush full buffer",
                (this->state == st_copying ? 0 :
                 this->state == st_run ? 1 :
                 -1));
    }
    if (this->length == 0)
    {
        QTC::TC("libtests", "Pl_RunLength flush empty buffer");
    }
    if (this->state == st_run)
    {
        if ((this->length < 2) || (this->length > 128))
        {
            throw std::logic_error(
                "Pl_RunLength: invalid length in flush_encode for run");
        }
        unsigned char ch = static_cast<unsigned char>(257 - this->length);
        this->getNext()->write(&ch, 1);
        this->getNext()->write(&this->buf[0], 1);
    }
    else if (this->length > 0)
    {
        unsigned char ch = static_cast<unsigned char>(this->length - 1);
        this->getNext()->write(&ch, 1);
        this->getNext()->write(this->buf, this->length);
    }
    this->state = st_top;
    this->length = 0;
}
Pl_RunLength::flush_encode()
{
    if (this->length == 128)
    {
        QTC::TC("libtests", "Pl_RunLength flush full buffer",
                (this->state == st_copying ? 0 :
                 this->state == st_run ? 1 :
                 -1));
    }
    if (this->length == 0)
    {
        QTC::TC("libtests", "Pl_RunLength flush empty buffer");
    }
    if (this->state == st_run)
    {
        if ((this->length < 2) || (this->length > 128))
        {
            throw std::logic_error(
                "Pl_RunLength: invalid length in flush_encode for run");
        }
        unsigned char ch = static_cast<unsigned char>(257 - this->length);
        this->getNext()->write(&ch, 1);
        this->getNext()->write(&this->buf[0], 1);
    }
    else if (this->length > 0)
    {
        unsigned char ch = static_cast<unsigned char>(this->length - 1);
        this->getNext()->write(&ch, 1);
        this->getNext()->write(this->buf, this->length);
    }
    this->state = st_top;
    this->length = 0;
}