summaryrefslogtreecommitdiff
path: root/includes/Buffer.h
blob: a903ec96199652ecc7516e31ea507458d19101f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <Handle.h>

namespace Balau {

class Buffer : public SeekableHandle {
  public:
      Buffer(const uint8_t * buffer, size_t s) : m_buffer(const_cast<uint8_t *>(buffer)), m_bufSize(s), m_fromConst(true) { }
      Buffer() throw (GeneralException) { }
      virtual ~Buffer();
    virtual void close() throw (GeneralException);
    virtual ssize_t read(void * buf, size_t count) throw (GeneralException);
    virtual ssize_t write(const void * buf, size_t count) throw (GeneralException);
    virtual bool isClosed();
    virtual bool isEOF();
    virtual bool canRead();
    virtual bool canWrite();
    virtual const char * getName();
    virtual off_t getSize();
    const uint8_t * getBuffer() { return m_buffer + rtell(); }
    void reset();
    void rewind() { rseek(0); wseek(0); }
  private:
    uint8_t * m_buffer = NULL;
    bool m_fromConst = false;
    off_t m_bufSize = 0, m_numBlocks = 0;
};

};