49#ifndef DVD_CORE_BYTE_BUFFER_INL_
50#define DVD_CORE_BYTE_BUFFER_INL_
55template<
class T,
size_t N>
58 for (
const T&
entry : pattern)
64template<
class T,
size_t N>
71 while (
bufferSize() >=
sizeof(T) && tempMarker != pattern[0])
73 read<T>( tempMarker );
78 assert(tempMarker == pattern[0]);
80 for (
size_t i = 1u; i < N; ++i)
82 read<T>( tempMarker );
83 if (tempMarker != pattern[i])
107 put(pos, (
Byte*)&value,
sizeof(T));
156 readNoSkipFrom<T>(
_rpos, value);
162 readNoSkipFrom<I8>(
_rpos, temp);
210inline void ByteBuffer::readSkip<char *>()
217inline void ByteBuffer::readSkip<char const *>()
223inline void ByteBuffer::readSkip<string>()
230 if (_rpos + skip > storageSize())
241 readNoSkipFrom<T>(
_rpos, out);
253 std::memcpy(&out, &
_storage[pos],
sizeof(T));
271 x = ((packed & 0x7FF) << 21 >> 21) * 0.25f;
272 y = ((packed >> 11 & 0x7FF) << 21 >> 21) * 0.25f;
273 z = (packed >> 22 << 22 >> 22) * 0.25f;
282 for (
I32 i = 0; i < 8; ++i)
284 if (guidmark &
U8_ONE << i)
288 guid |=
static_cast<U64>(bit) << i * 8;
310 for (
U8 i = 0; guid != 0; ++i)
314 packGUID[0] |=
U8_ONE << i;
315 packGUID[size] =
to_U8(guid & 0xFF);
327 readNoSkipFrom<Byte>( pos, ret );
395 return append((
const Byte*)src, cnt *
sizeof(T));
401 append(str.c_str(), str.length());
482 b >> elems.
x; q.
X(elems.
x);
483 b >> elems.
y; q.
Y(elems.
y);
484 b >> elems.
z; q.
Z(elems.
z);
485 b >> elems.
w; q.
W(elems.
w);
492 for (
U8 i = 0; i < 4; ++i) {
501 for (
U8 i = 0; i < 4; ++i) {
510 for (
U8 i = 0; i < 9; ++i) {
519 for (
U8 i = 0; i < 9; ++i) {
528 for (
U8 i = 0; i < 16; ++i) {
537 for (
U8 i = 0; i < 16; ++i) {
543template <
typename T,
size_t N>
545 b << static_cast<U64>(N);
551template <
typename T,
size_t N>
555 assert(size ==
static_cast<U64>(N));
556 b.
read((
Byte*)a.data(), N *
sizeof(T));
563 b << static_cast<U64>(N);
564 for (
const string& str : a) {
575 assert(size ==
static_cast<U64>(N));
576 for (
string& str : a) {
586 b.
append(v.data(), v.size());
596 b.
read((
Byte*)v.data(), vsize *
sizeof(T));
603 for (
const string& str : v) {
615 for (
string& str : v) {
623 for (
const T& i : v) {
643template <
typename K,
typename V>
646 for (
typename eastl::map<K, V>::value_type i : m) {
653template <
typename K,
typename V>
662 m.insert(eastl::make_pair(k, v));
686 const string temp{ s.c_str() };
ByteBuffer & operator<<(const T &value)
Appends 'value' to the buffer.
size_t storageSize() const noexcept
Returns the total size (in bytes) of the underlying storage, regardles of wpos and rpos.
void readNoSkip(T &value)
Reads sizeof(T) data from the buffer and saves it into 'value' but does NOT move the read head forwar...
void readSkipToMarker(const T(&pattern)[N])
Skip (consume) everything in the buffer until we find the specified list of items....
U64 readPackGUID()
Reads a packed U64 from the buffer and returns it. Reading moves the read head forward!
const Byte * contents() const noexcept
Returns a raw pointer to the underlying storage data. Does NOT depend on the read head position!...
size_t rpos() const noexcept
Returns the current read head position.
void readNoSkipFrom(size_t pos, T &out) const
Reads sizeof(T) data from the buffer and returns it but does NOT move the read head forward!
void resize(size_t newsize)
Resizes the underlying storage to 'newsize' bytes and resets the read and write head positions.
void append(const Byte *src, size_t cnt)
Appends 'cnt' bytes from 'src' to the buffer.
void read(T &out)
Reads sizeof(T) data from the buffer and returns it. Reading moves the read head forward!
size_t wpos() const noexcept
Returns the current write head position.
void clear() noexcept
Resets the entire storage and the read and write positions.
bool storageEmpty() const noexcept
Returns true if the underlying storage is empty, regardless of wpos and rpos.
ByteBuffer & operator>>(T &value)
Reads sizeof(T) data from the buffer and saves its contents into 'value'. Reading moves the read head...
void appendPackXYZ(F32 x, F32 y, F32 z)
Packes x,y and z into a single U32 and appends it to the buffer.
void addMarker(const T(&pattern)[N])
Add a specific list of items in order to mark a special point in the buffer. Can be used for skipping...
size_t bufferSize() const noexcept
Returns the size (in bytes) of the data inside of the buffer (wpos - rpos)
void readSkip()
Moves the read head sizeof(T) units forward.
void put(size_t pos, const T &value)
Inserts 'value' at the specified position overriding any existing data at that location....
void appendPackGUID(U64 guid)
Packes guid into a multiple I32s and appends them to the buffer.
Byte operator[](size_t pos) const
Read the byte at position 'pos' from the buffer without moving the read head.
void reserve(size_t resize)
Reserves 'resize' bytes of additional storage in the underlying storage structure without changing th...
void readPackXYZ(F32 &x, F32 &y, F32 &z)
Reads a packed U32 from the buffer and unpackes it into x,y,z. Reading moves the read head forward!
bool bufferEmpty() const noexcept
Returns true if the read position and the write position are identical.
Handle console commands that start with a forward slash.
constexpr U32 to_U32(const T value)
eastl::vector< Type > vector
ByteBuffer & operator<<(ByteBuffer &b, const vec2< T > &v)
ByteBuffer & operator>>(ByteBuffer &b, vec2< T > &v)
constexpr U8 to_U8(const T value)
constexpr I32 to_I32(const T value)
Project const SceneEntry & entry
StringReturnType< N > string() const noexcept
Helper for using >> instead of readSkip()