Function decode [src]
Use this function to increase idx.
Prototype
pub fn decode(d: *Decoder, comptime T: type) T
Parameters
d: *Decoder
T: type
Source
pub fn decode(d: *Decoder, comptime T: type) T {
switch (@typeInfo(T)) {
.int => |info| switch (info.bits) {
8 => {
skip(d, 1);
return d.buf[d.idx - 1];
},
16 => {
skip(d, 2);
const b0: u16 = d.buf[d.idx - 2];
const b1: u16 = d.buf[d.idx - 1];
return (b0 << 8) | b1;
},
24 => {
skip(d, 3);
const b0: u24 = d.buf[d.idx - 3];
const b1: u24 = d.buf[d.idx - 2];
const b2: u24 = d.buf[d.idx - 1];
return (b0 << 16) | (b1 << 8) | b2;
},
else => @compileError("unsupported int type: " ++ @typeName(T)),
},
.@"enum" => |info| {
if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");
return @enumFromInt(d.decode(info.tag_type));
},
else => @compileError("unsupported type: " ++ @typeName(T)),
}
}