Source

pyGAP / game / engine / io / file / decoder.cpp

#include "io/file/decoder.h"

#include <algorithm>

#include "codec/base.h"
#include "io/file/base.h"


namespace io { namespace file {

enum {
    DECODER_SIZE = 16 * 1024
};


Decoder::Decoder() :
    codec_(codec::create()),
    size_(DECODER_SIZE),
    buffer_(new uint8_t [size_])
{
}


Decoder::~Decoder() {
    delete codec_;
    delete buffer_;
}


uint8_t* Decoder::decode(Base* file, uint32_t input_size, uint32_t output_size) {
    uint64_t size = input_size;
    uint8_t* output = new uint8_t [output_size];
    if (!codec_->init(output)) {
        delete output;
        return NULL;
    }
    do {
        size = file->read(buffer_, sizeof(uint8_t), std::min(input_size, size_));
        input_size -= size;
    } while (codec_->decode(NULL, output_size, buffer_, size) && input_size > 0);
    if (!codec_->finish()) {
        delete output;
        return NULL;
    }
    return output;
}


} /* namespace io */ } /* namespace file */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.