View source code
Display the source code in std/bitmanip.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.bitmanip.peek
Takes a range
of ubyte
s and converts the first T.sizeof
bytes to
T
. The value returned is converted from the given endianness to the
native endianness. The range
is not consumed.
Prototypes
T peek(T, std.system.Endian endianness, R)( R range ) if (canSwapEndianness!T && isForwardRange!R && is(ElementType!R : const(ubyte))); T peek(T, std.system.Endian endianness, R)( R range, size_t index ) if (canSwapEndianness!T && isForwardRange!R && hasSlicing!R && is(ElementType!R : const(ubyte))); T peek(T, std.system.Endian endianness, R)( R range, size_t* index ) if (canSwapEndianness!T && isForwardRange!R && hasSlicing!R && is(ElementType!R : const(ubyte)));
Parameters
Name | Description |
---|---|
T | The integral type to convert the first T.sizeof bytes to. |
endianness | The endianness that the bytes are assumed to be in. |
range | The range to read from. |
index | The index to start reading from (instead of starting at the
front). If index is a pointer, then it is updated to the index
after the bytes read . The overloads with index are only
available if hasSlicing!R is true . |
Example
ubyte[] buffer = [1, 5, 22, 9, 44, 255, 8]; assert(buffer.peek!uint() == 17110537); assert(buffer.peek!ushort() == 261); assert(buffer.peek!ubyte() == 1); assert(buffer.peek!uint(2) == 369700095); assert(buffer.peek!ushort(2) == 5641); assert(buffer.peek!ubyte(2) == 22); size_t index = 0; assert(buffer.peek!ushort(&index) == 261); assert(index == 2); assert(buffer.peek!uint(&index) == 369700095); assert(index == 6); assert(buffer.peek!ubyte(&index) == 8); assert(index == 7);
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba Amaury SECHET