Function toBytes [src]

Given any value, returns a copy of its bytes in an array.

Prototype

pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8

Example

test toBytes { var my_bytes = toBytes(@as(u32, 0x12345678)); switch (native_endian) { .big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), .little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), } my_bytes[0] = '\x99'; switch (native_endian) { .big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), .little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), } }

Source

pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { return asBytes(&value).*; }