88 lines
2.0 KiB
C++
88 lines
2.0 KiB
C++
/*
|
|
ZBinaryBufferReader.hpp
|
|
Author: Chris Ertel <crertel@762studios.com>, Patrick Baggett <ptbaggett@762studios.com>
|
|
Created: 3/6/2013
|
|
|
|
Purpose:
|
|
|
|
Reads a binary stream from memory.
|
|
|
|
License:
|
|
|
|
TODO
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef _ZBINARYBUFFERREADER_HPP
|
|
#define _ZBINARYBUFFERREADER_HPP
|
|
|
|
#include <stddef.h>
|
|
#include <pstdint.h>
|
|
|
|
#include <ZUtil/ZBinaryReader.hpp>
|
|
|
|
class ZBinaryBufferReader : public ZBinaryReader
|
|
{
|
|
private:
|
|
const char* Data;
|
|
size_t Size;
|
|
size_t Offset;
|
|
|
|
//This is typed to char* so pointer arithmetic can occur
|
|
const char* GetPosition() const { return &Data[Offset]; }
|
|
public:
|
|
ZBinaryBufferReader(const void* _data, size_t _size, SST_ByteOrder bo)
|
|
: ZBinaryReader(bo), Data( (const char*) _data), Size(_size), Offset(0)
|
|
{
|
|
|
|
}
|
|
|
|
//Subclass implementation
|
|
uint8_t ReadU8();
|
|
|
|
//Subclass implementation
|
|
uint16_t ReadU16();
|
|
|
|
//Subclass implementation
|
|
uint32_t ReadU32();
|
|
|
|
//Subclass implementation
|
|
uint64_t ReadU64();
|
|
|
|
//Subclass implementation
|
|
void ReadU8Array(uint8_t* ptr, size_t count);
|
|
|
|
//Subclass implementation
|
|
void ReadU16Array(uint16_t* ptr, size_t count);
|
|
|
|
//Subclass implementation
|
|
void ReadU32Array(uint32_t* ptr, size_t count);
|
|
|
|
//Subclass implementation
|
|
void ReadU64Array(uint64_t* ptr, size_t count);
|
|
|
|
//Subclass implementation
|
|
size_t GetLength() const { return Size; }
|
|
|
|
//Subclass implementation
|
|
size_t GetOffset() const { return Offset; }
|
|
|
|
//Subclass implementation
|
|
void SeekTo(size_t offset) { Offset = offset; }
|
|
|
|
//New to ZBinaryBufferReader. Returns the current address that would be read by the next ReadXxx() call.
|
|
//Since 'const void*' is the constructor type, this returns 'const void*' as well. See [private] GetPosition().
|
|
const void* GetBufferReadAddress() const { return (const void*)GetPosition(); }
|
|
|
|
//New to ZBinaryBufferReader. Returns the original buffer address
|
|
const void* GetBufferBaseAddress() const { return (const void*)Data; }
|
|
|
|
//New to ZBinaryBufferReader. Reads a pointer
|
|
void* ReadPointer();
|
|
};
|
|
|
|
#endif
|
|
|