Skip to content

Instantly share code, notes, and snippets.

@alanw
Last active December 11, 2015 22:39
Show Gist options
  • Save alanw/4671177 to your computer and use it in GitHub Desktop.
Save alanw/4671177 to your computer and use it in GitHub Desktop.
SkipBuffer::SkipBuffer(IndexInputPtr input, int32_t length)
{
std::cout << "SkipBuffer::SkipBuffer (" << this << ") [length = " << length << "]" << std::endl;
pos = 0;
data = ByteArray::newInstance(length);
pointer = input->getFilePointer();
input->readBytes(data.get(), 0, length);
}
SkipBuffer::~SkipBuffer()
{
}
void SkipBuffer::close()
{
std::cout << "SkipBuffer::close (" << this << ")" << std::endl;
data.reset();
}
int64_t SkipBuffer::getFilePointer()
{
return (pointer + pos);
}
int64_t SkipBuffer::length()
{
return data.size();
}
uint8_t SkipBuffer::readByte()
{
std::cout << "SkipBuffer::readByte (" << this << ") [array size = " << data.size() << ", pos = " << pos << "]" << std::endl;
return data[pos++];
}
void SkipBuffer::readBytes(uint8_t* b, int32_t offset, int32_t length)
{
MiscUtils::arrayCopy(data.get(), pos, b, offset, length);
pos += length;
std::cout << "SkipBuffer::readBytes (" << this << ") [array size = " << data.size() << ", pos = " << pos << "]" << std::endl;
}
void SkipBuffer::seek(int64_t pos)
{
this->pos = (int32_t)(pos - pointer);
std::cout << "SkipBuffer::seek (" << this << ") [array size = " << data.size() << ", pos = " << this->pos << "]" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment