Function bytesToValue [src]
Given a pointer to an array of bytes, returns a value of the specified type backed by a
copy of those bytes.
Prototype
pub fn bytesToValue(comptime T: type, bytes: anytype) T
Parameters
T: type
Example
test bytesToValue {
const deadbeef_bytes = switch (native_endian) {
.big => "\xDE\xAD\xBE\xEF",
.little => "\xEF\xBE\xAD\xDE",
};
const deadbeef = bytesToValue(u32, deadbeef_bytes);
try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
}
Source
pub fn bytesToValue(comptime T: type, bytes: anytype) T {
return bytesAsValue(T, bytes).*;
}