src/bytestream.h

changeset 6
67b6ef6917ba
child 13
9bdddd2ccde6
equal deleted inserted replaced
5:3c04e05ab24f 6:67b6ef6917ba
1 #ifndef BYTESTREAM_H
2 #define BYTESTREAM_H
3
4 #include "types.h"
5
6 class Bytestream {
7 private:
8 uint8* m_data;
9 uint8* m_ptr;
10 ulong m_size, m_len;
11
12 void doWrite (uint8_t val);
13
14 public:
15 Bytestream (ulong len = 2048);
16 Bytestream (const char* data, ulong len);
17
18 void init (const char* data, ulong len);
19 void rewind ();
20 void seek (ulong pos);
21 void clear ();
22 void merge (const Bytestream& other);
23 bool tryMerge (const Bytestream& other);
24 void resize (ulong len);
25 size_t len () const;
26 ulong bytesLeft () const;
27 ulong spaceLeft () const;
28 void growToFit (ulong bytes);
29 const uint8* data () const;
30
31 bool readBytes (uint8 numbytes, uint8* val);
32 bool readByte (uint8& val);
33 bool readShort (uint16& val);
34 bool readLong (uint32& val);
35 bool readString (str& val);
36 bool readFloat (float& val);
37
38 void writeBytes (uint8 numbytes, const uint8* val);
39 void writeByte (uint8 val);
40 void writeShort (uint16 val);
41 void writeLong (uint32 val);
42 void writeFloat (float val);
43 void writeString (str val);
44
45 Bytestream& operator<< (const Bytestream& other) {
46 merge (other);
47 return *this;
48 }
49
50 uint8& subscript (ulong idx);
51 const uint8& const_subscript (ulong idx) const;
52
53 uint8& operator[] (ulong idx) {
54 return subscript (idx);
55 }
56
57 const uint8& operator[] (ulong idx) const {
58 return const_subscript (idx);
59 }
60 };
61
62 #endif // BYTESTREAM_H

mercurial