Marmos
v juptune
v asn1
v lang
v ast
v Classes
v Enums
v ir
v parser
v Enums
v Structs
v core
v crypto
v keyexchange
v memory
v data
v alphabet
v buffer
v json
v builder
v parser
v Enums
v Structs
v serialise
v Structs
v Templates
v pem
v Enums
v Structs

Structs MemoryReader

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
module juptune.data.buffer;

struct MemoryReader
{
    /++ ALIASES ++/
    
    ///
    alias __xpostblit = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekBytes = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI16(Endian endian) = ;
    /// ditto 
    alias enforcePeekI16BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI16LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI32(Endian endian) = ;
    /// ditto 
    alias enforcePeekI32BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI32LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI64(Endian endian) = ;
    /// ditto 
    alias enforcePeekI64BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI64LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekI8 = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU16(Endian endian) = ;
    /// ditto 
    alias enforcePeekU16BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU16LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU32(Endian endian) = ;
    /// ditto 
    alias enforcePeekU32BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU32LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU64(Endian endian) = ;
    /// ditto 
    alias enforcePeekU64BE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU64LE = __MARMOS_BUG__;
    /// ditto 
    alias enforcePeekU8 = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadBytes = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI16(Endian endian) = ;
    /// ditto 
    alias enforceReadI16BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI16LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI32(Endian endian) = ;
    /// ditto 
    alias enforceReadI32BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI32LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI64(Endian endian) = ;
    /// ditto 
    alias enforceReadI64BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI64LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadI8 = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU16(Endian endian) = ;
    /// ditto 
    alias enforceReadU16BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU16LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU32(Endian endian) = ;
    /// ditto 
    alias enforceReadU32BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU32LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU64(Endian endian) = ;
    /// ditto 
    alias enforceReadU64BE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU64LE = __MARMOS_BUG__;
    /// ditto 
    alias enforceReadU8 = __MARMOS_BUG__;
    /// ditto 
    alias peekBytes = __MARMOS_BUG__;
    /// ditto 
    alias peekI16(Endian endian) = ;
    /// ditto 
    alias peekI16BE = __MARMOS_BUG__;
    /// ditto 
    alias peekI16LE = __MARMOS_BUG__;
    /// ditto 
    alias peekI32(Endian endian) = ;
    /// ditto 
    alias peekI32BE = __MARMOS_BUG__;
    /// ditto 
    alias peekI32LE = __MARMOS_BUG__;
    /// ditto 
    alias peekI64(Endian endian) = ;
    /// ditto 
    alias peekI64BE = __MARMOS_BUG__;
    /// ditto 
    alias peekI64LE = __MARMOS_BUG__;
    /// ditto 
    alias peekI8 = __MARMOS_BUG__;
    /// ditto 
    alias peekNullTerminatedString = __MARMOS_BUG__;
    /// ditto 
    alias peekU16(Endian endian) = ;
    /// ditto 
    alias peekU16BE = __MARMOS_BUG__;
    /// ditto 
    alias peekU16LE = __MARMOS_BUG__;
    /// ditto 
    alias peekU32(Endian endian) = ;
    /// ditto 
    alias peekU32BE = __MARMOS_BUG__;
    /// ditto 
    alias peekU32LE = __MARMOS_BUG__;
    /// ditto 
    alias peekU64(Endian endian) = ;
    /// ditto 
    alias peekU64BE = __MARMOS_BUG__;
    /// ditto 
    alias peekU64LE = __MARMOS_BUG__;
    /// ditto 
    alias peekU8 = __MARMOS_BUG__;
    /// ditto 
    alias readBytes = __MARMOS_BUG__;
    /// ditto 
    alias readI16(Endian endian) = ;
    /// ditto 
    alias readI16BE = __MARMOS_BUG__;
    /// ditto 
    alias readI16LE = __MARMOS_BUG__;
    /// ditto 
    alias readI32(Endian endian) = ;
    /// ditto 
    alias readI32BE = __MARMOS_BUG__;
    /// ditto 
    alias readI32LE = __MARMOS_BUG__;
    /// ditto 
    alias readI64(Endian endian) = ;
    /// ditto 
    alias readI64BE = __MARMOS_BUG__;
    /// ditto 
    alias readI64LE = __MARMOS_BUG__;
    /// ditto 
    alias readI8 = __MARMOS_BUG__;
    /// ditto 
    alias readNullTerminatedString = __MARMOS_BUG__;
    /// ditto 
    alias readU16(Endian endian) = ;
    /// ditto 
    alias readU16BE = __MARMOS_BUG__;
    /// ditto 
    alias readU16LE = __MARMOS_BUG__;
    ///
    alias readU24BE = __MARMOS_BUG__;
    ///
    alias readU24LE = __MARMOS_BUG__;
    /// ditto 
    alias readU32(Endian endian) = ;
    /// ditto 
    alias readU32BE = __MARMOS_BUG__;
    /// ditto 
    alias readU32LE = __MARMOS_BUG__;
    /// ditto 
    alias readU64(Endian endian) = ;
    /// ditto 
    alias readU64BE = __MARMOS_BUG__;
    /// ditto 
    alias readU64LE = __MARMOS_BUG__;
    /// ditto 
    alias readU8 = __MARMOS_BUG__;
    
    /++ FUNCTIONS ++/
    
    /// Returns: The underlying buffer passed to the constructor. 
    const ubyte[] buffer();
    /// Returns: The number of bytes left in the buffer, for the current cursor position. 
    ulong bytesLeft();
    /// Returns: The current cursor position. 
    ulong cursor();
    /// Sets the cursor position. 
    void cursor(ulong newCursor);
    /// The same thing as tryBytes , but throws an Exception if there's not enough bytes to read, which allows the function to return the value directly and rely on try-catch for error handling. 
    const ubyte[] enforceBytes(bool advanceCursor)(size_t count);
    /// The same thing as tryIntegral , but throws an Exception if there's not enough bytes to read, which allows the function to return the value directly and rely on try-catch for error handling. 
    IntT enforceIntegral(IntT, Endian endian, bool advanceCursor)();
    /// Moves the cursor back by the given number of bytes. 
    void goBack(ulong count);
    /// Advances the cursor by the given number of bytes. 
    void goForward(ulong count);
    ///
    MemoryReader opAssign(MemoryReader p);
    /// Attempts to read a sequence of bytes from the buffer, and then optionally advances the cursor. 
    bool tryBytes(bool advanceCursor)(size_t count, const ubyte[] result);
    /// Attempts to read an integral type from the buffer; automatically converting it from big/little endian into the native endianess, and then optionally advances the cursor. 
    bool tryIntegral(IntT, Endian endian, bool advanceCursor)(IntT result);
    ///
    bool tryIntegral24(Endian endian, bool advanceCursor)(uint value);
    ///
    bool tryNullTerminatedString(bool advanceCursor)(const char[] result);
    
}

Documentation

A simple memory reader that allows reading bytes and integral types from a buffer.

Notes

As Juptune is @nogc-first, the "easy" named functions follow the pattern of returning a boolean to indicate success, and then passing the result as an out parameter.

This is really cumbersome, so for @gc code there are "enforce" functions that throw an exception if there's not enough bytes to read, so the caller can use try-catch for error handling rather than checking the return value.

Aliases

Name Description
__xpostblit
enforcePeekBytes

ditto

enforcePeekI16

ditto

enforcePeekI16BE

ditto

enforcePeekI16LE

ditto

enforcePeekI32

ditto

enforcePeekI32BE

ditto

enforcePeekI32LE

ditto

enforcePeekI64

ditto

enforcePeekI64BE

ditto

enforcePeekI64LE

ditto

enforcePeekI8

ditto

enforcePeekU16

ditto

enforcePeekU16BE

ditto

enforcePeekU16LE

ditto

enforcePeekU32

ditto

enforcePeekU32BE

ditto

enforcePeekU32LE

ditto

enforcePeekU64

ditto

enforcePeekU64BE

ditto

enforcePeekU64LE

ditto

enforcePeekU8

ditto

enforceReadBytes

ditto

enforceReadI16

ditto

enforceReadI16BE

ditto

enforceReadI16LE

ditto

enforceReadI32

ditto

enforceReadI32BE

ditto

enforceReadI32LE

ditto

enforceReadI64

ditto

enforceReadI64BE

ditto

enforceReadI64LE

ditto

enforceReadI8

ditto

enforceReadU16

ditto

enforceReadU16BE

ditto

enforceReadU16LE

ditto

enforceReadU32

ditto

enforceReadU32BE

ditto

enforceReadU32LE

ditto

enforceReadU64

ditto

enforceReadU64BE

ditto

enforceReadU64LE

ditto

enforceReadU8

ditto

peekBytes

ditto

peekI16

ditto

peekI16BE

ditto

peekI16LE

ditto

peekI32

ditto

peekI32BE

ditto

peekI32LE

ditto

peekI64

ditto

peekI64BE

ditto

peekI64LE

ditto

peekI8

ditto

peekNullTerminatedString

ditto

peekU16

ditto

peekU16BE

ditto

peekU16LE

ditto

peekU32

ditto

peekU32BE

ditto

peekU32LE

ditto

peekU64

ditto

peekU64BE

ditto

peekU64LE

ditto

peekU8

ditto

readBytes

ditto

readI16

ditto

readI16BE

ditto

readI16LE

ditto

readI32

ditto

readI32BE

ditto

readI32LE

ditto

readI64

ditto

readI64BE

ditto

readI64LE

ditto

readI8

ditto

readNullTerminatedString

ditto

readU16

ditto

readU16BE

ditto

readU16LE

ditto

readU24BE
readU24LE
readU32

ditto

readU32BE

ditto

readU32LE

ditto

readU64

ditto

readU64BE

ditto

readU64LE

ditto

readU8

ditto

Functions

Name Description
buffer

Returns: The underlying buffer passed to the constructor.

bytesLeft

Returns: The number of bytes left in the buffer, for the current cursor position.

cursor

Returns: The current cursor position.

cursor

Sets the cursor position.

enforceBytes

The same thing as tryBytes, but throws an Exceptionif there's not enough bytes to read, which allows the function to return the value directly and rely on try-catch for error handling.

enforceIntegral

The same thing as tryIntegral, but throws an Exceptionif there's not enough bytes to read, which allows the function to return the value directly and rely on try-catch for error handling.

goBack

Moves the cursor back by the given number of bytes.

goForward

Advances the cursor by the given number of bytes.

opAssign
tryBytes

Attempts to read a sequence of bytes from the buffer, and then optionally advances the cursor.

tryIntegral

Attempts to read an integral type from the buffer; automatically converting it from big/little endian into the native endianess, and then optionally advances the cursor.

tryIntegral24
tryNullTerminatedString