123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215module 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);
}
A simple memory reader that allows reading bytes and integral types from a buffer.
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.
| 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 |
| enforceIntegral |
The same thing as |
| 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 |