~alva/zig-bare

d22f2ae3365e34f53de79fa80edac9209eb56ff4 — ugla 4 months ago 30f529a
Compatibility updates for Zig master
1 files changed, 12 insertions(+), 8 deletions(-)

M src/bare.zig
M src/bare.zig => src/bare.zig +12 -8
@@ 81,8 81,12 @@ pub const Decoder = struct {

            x |= @as(u64, b & 0x7f) << s;

            if (@addWithOverflow(@TypeOf(s), s, 7, &s))
            const ov = @addWithOverflow(s, 7);

            if (0 != ov[1])
                return DecodeError.Overflow;

            s = ov[0];
        }

        return 0;


@@ 91,7 95,7 @@ pub const Decoder = struct {
    fn decodeInt(self: *Self, comptime T: type, reader: anytype) !T {
        _ = self;

        return switch (meta.bitCount(T)) {
        return switch (@bitSizeOf(T)) {
            8, 16, 32, 64 => reader.readIntLittle(T),
            else => @compileError("unsupported integer type " ++ @typeName(T)),
        };


@@ 100,7 104,7 @@ pub const Decoder = struct {
    fn decodeFloat(self: *Self, comptime T: type, reader: anytype) !T {
        _ = self;

        const bits = meta.bitCount(T);
        const bits = @bitSizeOf(T);
        return switch (bits) {
            32, 64 => @bitCast(T, try reader.readIntLittle(meta.Int(.unsigned, bits))),
            else => @compileError("unsupported float type " ++ @typeName(T)),


@@ 121,7 125,7 @@ pub const Decoder = struct {
            @compileError("structs must have 1 or more fields");

        inline for (ti.fields) |f|
            @field(s, f.name) = try self.decode(f.field_type, reader);
            @field(s, f.name) = try self.decode(f.type, reader);

        return s;
    }


@@ 163,7 167,7 @@ pub const Decoder = struct {

        inline for (ti.fields) |f| {
            if (tag == @enumToInt(@field(ti.tag_type.?, f.name))) {
                const v = try self.decodeAllowVoid(f.field_type, reader);
                const v = try self.decodeAllowVoid(f.type, reader);
                return @unionInit(T, f.name, v);
            }
        }


@@ 280,7 284,7 @@ pub const Encoder = struct {
    fn encodeInt(self: *Self, comptime T: type, value: T, writer: anytype) !void {
        _ = self;

        return switch (meta.bitCount(T)) {
        return switch (@bitSizeOf(T)) {
            8, 16, 32, 64 => writer.writeIntLittle(T, value),
            else => @compileError("unsupported integer type " ++ @typeName(T)),
        };


@@ 289,7 293,7 @@ pub const Encoder = struct {
    fn encodeFloat(self: *Self, comptime T: type, value: T, writer: anytype) !void {
        _ = self;

        return switch (meta.bitCount(T)) {
        return switch (@bitSizeOf(T)) {
            32 => writer.writeIntLittle(u32, @bitCast(u32, value)),
            64 => writer.writeIntLittle(u64, @bitCast(u64, value)),
            else => @compileError("unsupported float type " ++ @typeName(T)),


@@ 406,7 410,7 @@ fn HashMapType(comptime T: type, comptime field_name: []const u8) type {

    inline for (fields) |f|
        if (comptime mem.eql(u8, f.name, field_name))
            return f.field_type;
            return f.type;
}

fn isValidHashMapKeyType(comptime T: type) bool {