mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Add a few more useful functions.
This commit is contained in:
10
lib/bytes.cc
10
lib/bytes.cc
@@ -273,6 +273,16 @@ ByteWriter Bytes::writer()
|
|||||||
return ByteWriter(*this);
|
return ByteWriter(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteWriter& ByteWriter::operator +=(std::istream& stream)
|
||||||
|
{
|
||||||
|
Bytes buffer(4096);
|
||||||
|
|
||||||
|
while (stream.read((char*) buffer.begin(), buffer.size()))
|
||||||
|
this->append(buffer);
|
||||||
|
this->append(buffer.slice(0, stream.gcount()));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void BitWriter::push(uint32_t bits, size_t size)
|
void BitWriter::push(uint32_t bits, size_t size)
|
||||||
{
|
{
|
||||||
bits <<= 32-size;
|
bits <<= 32-size;
|
||||||
|
|||||||
15
lib/bytes.h
15
lib/bytes.h
@@ -69,7 +69,7 @@ public:
|
|||||||
|
|
||||||
unsigned pos = 0;
|
unsigned pos = 0;
|
||||||
bool eof() const
|
bool eof() const
|
||||||
{ return pos == _bytes.size(); }
|
{ return pos >= _bytes.size(); }
|
||||||
|
|
||||||
ByteReader& seek(unsigned pos)
|
ByteReader& seek(unsigned pos)
|
||||||
{
|
{
|
||||||
@@ -77,6 +77,12 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteReader& skip(int delta)
|
||||||
|
{
|
||||||
|
this->pos += delta;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const Bytes read(unsigned len)
|
const Bytes read(unsigned len)
|
||||||
{
|
{
|
||||||
const Bytes bytes = _bytes.slice(pos, len);
|
const Bytes bytes = _bytes.slice(pos, len);
|
||||||
@@ -256,11 +262,18 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteWriter& operator += (std::istream& stream);
|
||||||
|
|
||||||
ByteWriter& append(const Bytes data)
|
ByteWriter& append(const Bytes data)
|
||||||
{
|
{
|
||||||
return *this += data;
|
return *this += data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteWriter& append(std::istream& stream)
|
||||||
|
{
|
||||||
|
return *this += stream;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Bytes& _bytes;
|
Bytes& _bytes;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user