From e40c3a2b4407bd8ccbea9afd137e24db416a358d Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 11 Dec 2024 16:30:09 -0500 Subject: [PATCH 1/4] fix: update references to std.builtin.Type via @typeInfo to v0.14 format --- src/any.zig | 50 +++++++++++++++--------------- src/bool.zig | 6 ++-- src/float.zig | 4 +-- src/int.zig | 84 +++++++++++++++++++++++++------------------------- src/null.zig | 2 +- src/struct.zig | 14 ++++----- 6 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/any.zig b/src/any.zig index 131444f..62b2eef 100644 --- a/src/any.zig +++ b/src/any.zig @@ -36,14 +36,14 @@ const unpackUnion = @import("union.zig").unpackUnion; inline fn isString(comptime T: type) bool { switch (@typeInfo(T)) { - .Pointer => |ptr_info| { + .pointer => |ptr_info| { if (ptr_info.size == .Slice) { if (ptr_info.child == u8) { return true; } } }, - .Optional => |opt_info| { + .optional => |opt_info| { return isString(opt_info.child); }, else => {}, @@ -53,10 +53,10 @@ inline fn isString(comptime T: type) bool { pub fn sizeOfPackedAny(comptime T: type, value: T) usize { switch (@typeInfo(NonOptional(T))) { - .Bool => return getBoolSize(), - .Int => return getIntSize(T, value), - .Float => return getFloatSize(T, value), - .Pointer => |ptr_info| { + .bool => return getBoolSize(), + .int => return getIntSize(T, value), + .float => return getFloatSize(T, value), + .pointer => |ptr_info| { if (ptr_info.size == .Slice) { if (isString(T)) { return sizeOfPackedString(value.len); @@ -73,13 +73,13 @@ pub fn sizeOfPackedAny(comptime T: type, value: T) usize { pub fn packAny(writer: anytype, value: anytype) !void { const T = @TypeOf(value); switch (@typeInfo(T)) { - .Void => return packNull(writer), - .Bool => return packBool(writer, value), - .Int => return packInt(writer, T, value), - .Float => return packFloat(writer, T, value), - .ComptimeInt => return packInt(writer, i64, @intCast(value)), - .ComptimeFloat => return packFloat(writer, f64, @floatCast(value)), - .Array => |arr_info| { + .void => return packNull(writer), + .bool => return packBool(writer, value), + .int => return packInt(writer, T, value), + .float => return packFloat(writer, T, value), + .comptime_int => return packInt(writer, i64, @intCast(value)), + .comptime_float => return packFloat(writer, f64, @floatCast(value)), + .array => |arr_info| { switch (arr_info.child) { u8 => { return packString(writer, &value); @@ -89,7 +89,7 @@ pub fn packAny(writer: anytype, value: anytype) !void { }, } }, - .Pointer => |ptr_info| { + .pointer => |ptr_info| { if (ptr_info.size == .Slice) { switch (ptr_info.child) { u8 => { @@ -103,9 +103,9 @@ pub fn packAny(writer: anytype, value: anytype) !void { return packAny(writer, value.*); } }, - .Struct => return packStruct(writer, T, value), - .Union => return packUnion(writer, T, value), - .Optional => { + .@"struct" => return packStruct(writer, T, value), + .@"union" => return packUnion(writer, T, value), + .optional => { if (value) |val| { return packAny(writer, val); } else { @@ -119,13 +119,13 @@ pub fn packAny(writer: anytype, value: anytype) !void { pub fn unpackAny(reader: anytype, allocator: std.mem.Allocator, comptime T: type) !T { switch (@typeInfo(T)) { - .Void => return unpackNull(reader), - .Bool => return unpackBool(reader, T), - .Int => return unpackInt(reader, T), - .Float => return unpackFloat(reader, T), - .Struct => return unpackStruct(reader, allocator, T), - .Union => return unpackUnion(reader, allocator, T), - .Pointer => |ptr_info| { + .void => return unpackNull(reader), + .bool => return unpackBool(reader, T), + .int => return unpackInt(reader, T), + .float => return unpackFloat(reader, T), + .@"struct" => return unpackStruct(reader, allocator, T), + .@"union" => return unpackUnion(reader, allocator, T), + .pointer => |ptr_info| { if (ptr_info.size == .Slice) { if (isString(T)) { return unpackString(reader, allocator); @@ -134,7 +134,7 @@ pub fn unpackAny(reader: anytype, allocator: std.mem.Allocator, comptime T: type } } }, - .Optional => |opt_info| { + .optional => |opt_info| { return unpackAny(reader, allocator, opt_info.child) catch |err| { if (isNullError(err)) { return null; diff --git a/src/bool.zig b/src/bool.zig index 2c49985..2ef7807 100644 --- a/src/bool.zig +++ b/src/bool.zig @@ -10,7 +10,7 @@ pub fn getBoolSize() usize { inline fn forceBoolType(value: anytype) type { const T = @TypeOf(value); - if (@typeInfo(T) == .Null) { + if (@typeInfo(T) == .null) { return ?bool; } assertBoolType(T); @@ -19,8 +19,8 @@ inline fn forceBoolType(value: anytype) type { inline fn assertBoolType(T: type) void { switch (@typeInfo(T)) { - .Bool => return, - .Optional => |opt_info| { + .bool => return, + .optional => |opt_info| { return assertBoolType(opt_info.child); }, else => @compileError("Expected bool, got " ++ @typeName(T)), diff --git a/src/float.zig b/src/float.zig index 2c9c05a..2b1e688 100644 --- a/src/float.zig +++ b/src/float.zig @@ -7,8 +7,8 @@ const maybeUnpackNull = @import("null.zig").maybeUnpackNull; inline fn assertFloatType(comptime T: type) type { switch (@typeInfo(T)) { - .Float => return T, - .Optional => |opt_info| { + .float => return T, + .optional => |opt_info| { return assertFloatType(opt_info.child); }, else => @compileError("Expected float, got " ++ @typeName(T)), diff --git a/src/int.zig b/src/int.zig index 6494e55..55e2a4e 100644 --- a/src/int.zig +++ b/src/int.zig @@ -7,8 +7,8 @@ const maybeUnpackNull = @import("null.zig").maybeUnpackNull; inline fn assertIntType(comptime T: type) type { switch (@typeInfo(T)) { - .Int => return T, - .Optional => |opt_info| { + .int => return T, + .optional => |opt_info| { return assertIntType(opt_info.child); }, else => @compileError("Expected int, got " ++ @typeName(T)), @@ -24,8 +24,8 @@ pub fn getIntSize(comptime T: type, value: T) usize { const Type = assertIntType(T); const type_info = @typeInfo(Type); - const is_signed = type_info.Int.signedness == .signed; - const bits = type_info.Int.bits; + const is_signed = type_info.int.signedness == .signed; + const bits = type_info.int.bits; if (is_signed) { if (value >= -32 and value <= -1) { @@ -45,7 +45,7 @@ pub fn getIntSize(comptime T: type, value: T) usize { if (bits == 64 or value >= std.math.minInt(i64) and value <= std.math.maxInt(i64)) { return 1 + @sizeOf(i64); } - @compileError("Unsupported signed int with " ++ type_info.Int.bits ++ "bits"); + @compileError("Unsupported signed int with " ++ type_info.int.bits ++ "bits"); } else { if (value <= 127) { return 1; @@ -77,8 +77,8 @@ pub fn packInt(writer: anytype, comptime T: type, value_or_maybe_null: T) !void const value: Type = try maybePackNull(writer, T, value_or_maybe_null) orelse return; const type_info = @typeInfo(Type); - const is_signed = type_info.Int.signedness == .signed; - const bits = type_info.Int.bits; + const is_signed = type_info.int.signedness == .signed; + const bits = type_info.int.bits; if (is_signed) { if (value >= -32 and value <= -1) { @@ -100,7 +100,7 @@ pub fn packInt(writer: anytype, comptime T: type, value_or_maybe_null: T) !void if (bits == 64 or value >= std.math.minInt(i64) and value <= std.math.maxInt(i64)) { return packFixedSizeInt(writer, i64, @intCast(value)); } - @compileError("Unsupported signed int with " ++ type_info.Int.bits ++ "bits"); + @compileError("Unsupported signed int with " ++ type_info.int.bits ++ "bits"); } else { if (value <= 127) { return writer.writeByte(@bitCast(@as(u8, @intCast(value)))); @@ -128,23 +128,23 @@ pub fn packFixedSizeInt(writer: anytype, comptime T: type, value: T) !void { inline fn resolveFixedSizeIntHeader(comptime T: type) u8 { const type_info = @typeInfo(T); - switch (type_info.Int.signedness) { + switch (type_info.int.signedness) { .signed => { - switch (type_info.Int.bits) { + switch (type_info.int.bits) { 8 => return hdrs.INT8, 16 => return hdrs.INT16, 32 => return hdrs.INT32, 64 => return hdrs.INT64, - else => @compileError("Unsupported signed int with " ++ type_info.Int.bits ++ "bits"), + else => @compileError("Unsupported signed int with " ++ type_info.int.bits ++ "bits"), } }, .unsigned => { - switch (type_info.Int.bits) { + switch (type_info.int.bits) { 8 => return hdrs.UINT8, 16 => return hdrs.UINT16, 32 => return hdrs.UINT32, 64 => return hdrs.UINT64, - else => @compileError("Unsupported unsigned int with " ++ type_info.Int.bits ++ "bits"), + else => @compileError("Unsupported unsigned int with " ++ type_info.int.bits ++ "bits"), } }, } @@ -169,8 +169,8 @@ pub fn unpackIntValue(reader: anytype, comptime SourceType: type, comptime Targe } const value = std.mem.readInt(SourceType, &buf, .big); - const source_type_info = @typeInfo(SourceType).Int; - const target_type_info = @typeInfo(TargetType).Int; + const source_type_info = @typeInfo(SourceType).int; + const target_type_info = @typeInfo(TargetType).int; if (source_type_info.signedness == target_type_info.signedness and source_type_info.bits <= target_type_info.bits) { return @intCast(value); @@ -193,7 +193,7 @@ pub fn unpackInt(reader: anytype, comptime T: type) !T { if (header >= hdrs.NEGATIVE_FIXINT_MIN) { const value: i8 = @bitCast(header); - if (type_info.Int.signedness == .signed) { + if (type_info.int.signedness == .signed) { return value; } else if (value >= 0) { return @intCast(value); @@ -236,7 +236,7 @@ test "readInt: negative fixint" { const buffer = [_]u8{0xe0}; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -249,7 +249,7 @@ test "readInt: uint8" { const buffer = [_]u8{ 0xcc, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 8 or (info.bits == 8 and info.signedness == .signed)) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -262,7 +262,7 @@ test "readInt: uint16" { const buffer = [_]u8{ 0xcd, 0xff, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 16 or (info.bits == 16 and info.signedness == .signed)) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -275,7 +275,7 @@ test "readInt: uint32" { const buffer = [_]u8{ 0xce, 0xff, 0xff, 0xff, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 32 or (info.bits == 32 and info.signedness == .signed)) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -288,7 +288,7 @@ test "readInt: uint64" { const buffer = [_]u8{ 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 64 or (info.bits == 64 and info.signedness == .signed)) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -301,7 +301,7 @@ test "readInt: negative int8" { const buffer = [_]u8{ 0xd0, 0x80 }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned or info.bits < 8) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -314,7 +314,7 @@ test "readInt: positive int8" { const buffer = [_]u8{ 0xd0, 0x7f }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 7) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -327,7 +327,7 @@ test "readInt: negative int16" { const buffer = [_]u8{ 0xd1, 0x80, 0x00 }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned or info.bits < 16) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -340,7 +340,7 @@ test "readInt: positive int16" { const buffer = [_]u8{ 0xd1, 0x7f, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 15) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -353,7 +353,7 @@ test "readInt: negative int32" { const buffer = [_]u8{ 0xd2, 0x80, 0x00, 0x00, 0x00 }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned or info.bits < 32) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -366,7 +366,7 @@ test "readInt: positive int32" { const buffer = [_]u8{ 0xd2, 0x7f, 0xff, 0xff, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 31) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -379,7 +379,7 @@ test "readInt: negative int64" { const buffer = [_]u8{ 0xd3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned or info.bits < 64) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -392,7 +392,7 @@ test "readInt: positive int64" { const buffer = [_]u8{ 0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; inline for (int_types) |T| { var stream = std.io.fixedBufferStream(&buffer); - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.bits < 63) { try std.testing.expectError(error.IntegerOverflow, unpackInt(stream.reader(), T)); } else { @@ -413,7 +413,7 @@ test "writeInt: positive fixint" { test "writeInt: negative fixint" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, -32); @@ -425,7 +425,7 @@ test "writeInt: negative fixint" { test "writeInt: uint8" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned and info.bits >= 8) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 200); @@ -437,7 +437,7 @@ test "writeInt: uint8" { test "writeInt: uint16" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned and info.bits >= 16) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 40000); @@ -449,7 +449,7 @@ test "writeInt: uint16" { test "writeInt: uint32" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned and info.bits >= 32) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 3000000000); @@ -461,7 +461,7 @@ test "writeInt: uint32" { test "writeInt: uint64" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .unsigned and info.bits >= 64) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 9000000000000000000); @@ -473,7 +473,7 @@ test "writeInt: uint64" { test "writeInt: positive int8" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits > 8) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 100); @@ -485,7 +485,7 @@ test "writeInt: positive int8" { test "writeInt: negative int8" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 8) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, -100); @@ -497,7 +497,7 @@ test "writeInt: negative int8" { test "writeInt: positive int16" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 16) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 20000); @@ -509,7 +509,7 @@ test "writeInt: positive int16" { test "writeInt: negative int16" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 16) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, -20000); @@ -521,7 +521,7 @@ test "writeInt: negative int16" { test "writeInt: positive int32" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 32) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 2000000000); @@ -533,7 +533,7 @@ test "writeInt: positive int32" { test "writeInt: negative int32" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 32) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, -2000000000); @@ -545,7 +545,7 @@ test "writeInt: negative int32" { test "writeInt: positive int64" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 64) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, 8000000000000000000); @@ -557,7 +557,7 @@ test "writeInt: positive int64" { test "writeInt: negative int64" { var buffer: [100]u8 = undefined; inline for (int_types) |T| { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; if (info.signedness == .signed and info.bits >= 64) { var stream = std.io.fixedBufferStream(&buffer); try packInt(stream.writer(), T, -9000000000000000000); diff --git a/src/null.zig b/src/null.zig index 219d050..737a750 100644 --- a/src/null.zig +++ b/src/null.zig @@ -18,7 +18,7 @@ pub fn unpackNull(reader: anytype) !void { } pub fn maybePackNull(writer: anytype, comptime T: type, value: T) !?NonOptional(T) { - if (@typeInfo(T) == .Optional) { + if (@typeInfo(T) == .optional) { if (value == null) { try packNull(writer); return null; diff --git a/src/struct.zig b/src/struct.zig index fd2f0df..4e09c9f 100644 --- a/src/struct.zig +++ b/src/struct.zig @@ -92,7 +92,7 @@ fn strPrefix(src: []const u8, len: usize) []const u8 { pub fn packStructAsMap(writer: anytype, comptime T: type, value: T, comptime opts: StructAsMapOptions) !void { const type_info = @typeInfo(T); - const fields = type_info.Struct.fields; + const fields = type_info.@"struct".fields; const FieldEnum = std.meta.FieldEnum(T); try packMapHeader(writer, countUsedStructFields(fields, value, opts)); @@ -121,7 +121,7 @@ pub fn packStructAsMap(writer: anytype, comptime T: type, value: T, comptime opt pub fn packStructAsArray(writer: anytype, comptime T: type, value: T, comptime opts: StructAsArrayOptions) !void { const type_info = @typeInfo(T); - const fields = type_info.Struct.fields; + const fields = type_info.@"struct".fields; try packArrayHeader(writer, fields.len); @@ -137,7 +137,7 @@ pub fn packStruct(writer: anytype, comptime T: type, value_or_maybe_null: T) !vo const Type = @TypeOf(value); const type_info = @typeInfo(Type); - if (type_info != .Struct) { + if (type_info != .@"struct") { @compileError("Expected struct type"); } @@ -158,14 +158,14 @@ pub fn packStruct(writer: anytype, comptime T: type, value_or_maybe_null: T) !vo } pub fn unpackStructAsMap(reader: anytype, allocator: std.mem.Allocator, comptime T: type, comptime opts: StructAsMapOptions) !T { - const len = if (@typeInfo(T) == .Optional) + const len = if (@typeInfo(T) == .optional) try unpackMapHeader(reader, ?u16) orelse return null else try unpackMapHeader(reader, u16); const Type = NonOptional(T); const type_info = @typeInfo(Type); - const fields = type_info.Struct.fields; + const fields = type_info.@"struct".fields; const FieldEnum = std.meta.FieldEnum(T); var fields_seen = std.bit_set.StaticBitSet(fields.len).initEmpty(); @@ -235,7 +235,7 @@ pub fn unpackStructAsMap(reader: anytype, allocator: std.mem.Allocator, comptime const default_field_value = @as(*field.type, @ptrCast(@alignCast(@constCast(default_field_value_ptr)))).*; @field(result, field.name) = default_field_value; fields_seen.set(i); - } else if (@typeInfo(field.type) == .Optional) { + } else if (@typeInfo(field.type) == .optional) { @field(result, field.name) = null; fields_seen.set(i); } @@ -257,7 +257,7 @@ pub fn unpackStructAsArray(reader: anytype, allocator: std.mem.Allocator, compti const Type = NonOptional(T); const type_info = @typeInfo(Type); - const fields = type_info.Struct.fields; + const fields = type_info.@"struct".fields; if (len != fields.len) { return error.InvalidFormat; From 63bc9670c7637083a58f96c4e2bedb5647c12867 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 11 Dec 2024 16:30:09 -0500 Subject: [PATCH 2/4] fix: update references to std.builtin.Type via @typeInfo to v0.14 format --- src/utils.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.zig b/src/utils.zig index e1c33cd..61d664d 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -2,8 +2,8 @@ const std = @import("std"); pub fn NonOptional(comptime T: type) type { const type_info = @typeInfo(T); - if (type_info == .Optional) { - return type_info.Optional.child; + if (type_info == .optional) { + return type_info.optional.child; } return T; } @@ -13,7 +13,7 @@ pub fn Optional(comptime T: type, comptime is_optional: bool) type { } pub inline fn isOptional(comptime T: type) bool { - return @typeInfo(T) == .Optional; + return @typeInfo(T) == .optional; } test isOptional { From 7b2ee0eb137041f198fa8aa8127aa2f7b8776d74 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 11 Dec 2024 16:30:09 -0500 Subject: [PATCH 3/4] fix: update references to std.builtin.Type via @typeInfo to v0.14 format fix: update references to std.builtin.Type via @typeInfo to v0.14 format --- src/struct.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struct.zig b/src/struct.zig index 4e09c9f..c43e742 100644 --- a/src/struct.zig +++ b/src/struct.zig @@ -66,7 +66,7 @@ fn isStructFieldUsed(field: std.builtin.Type.StructField, value: anytype, opts: } if (opts.omit_nulls) { - if (field_type_info == .Optional) { + if (field_type_info == .optional) { if (field_value == null) { return false; } @@ -250,7 +250,7 @@ pub fn unpackStructAsMap(reader: anytype, allocator: std.mem.Allocator, comptime } pub fn unpackStructAsArray(reader: anytype, allocator: std.mem.Allocator, comptime T: type, comptime opts: StructAsArrayOptions) !T { - const len = if (@typeInfo(T) == .Optional) + const len = if (@typeInfo(T) == .optional) try unpackArrayHeader(reader, ?u16) orelse return null else try unpackArrayHeader(reader, u16); From f136d6bf12a5900a8a0e22863c68d518936f7980 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 11 Dec 2024 16:30:09 -0500 Subject: [PATCH 4/4] fix: update references to std.builtin.Type via @typeInfo to v0.14 format fix: update references to std.builtin.Type via @typeInfo to v0.14 format --- src/float.zig | 14 +++++++------- src/union.zig | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/float.zig b/src/float.zig index 2b1e688..0c5c3ae 100644 --- a/src/float.zig +++ b/src/float.zig @@ -32,7 +32,7 @@ pub fn packFloat(writer: anytype, comptime T: type, value_or_maybe_null: T) !voi comptime var TargetType: type = undefined; const type_info = @typeInfo(Type); - switch (type_info.Float.bits) { + switch (type_info.float.bits) { 0...32 => { try writer.writeByte(hdrs.FLOAT32); TargetType = f32; @@ -88,10 +88,10 @@ const packed_float64_inf = [_]u8{ 0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00 const float_types = [_]type{ f16, f32, f64 }; -fn minFloatType(comptime T1: type, comptime T2: type) type { +fn MinFloatType(comptime T1: type, comptime T2: type) type { const ti1 = @typeInfo(T1); const ti2 = @typeInfo(T2); - return std.meta.Float(@min(ti1.Float.bits, ti2.Float.bits)); + return std.meta.Float(@min(ti1.float.bits, ti2.float.bits)); } test "readFloat: null" { @@ -105,7 +105,7 @@ test "readFloat: float32 (zero)" { inline for (float_types) |T| { var stream = std.io.fixedBufferStream(&packed_float32_zero); const value = try unpackFloat(stream.reader(), T); - try std.testing.expectApproxEqAbs(0.0, value, std.math.floatEpsAt(minFloatType(T, f32), @floatCast(value))); + try std.testing.expectApproxEqAbs(0.0, value, std.math.floatEpsAt(MinFloatType(T, f32), @floatCast(value))); } } @@ -113,7 +113,7 @@ test "readFloat: float64 (zero)" { inline for (float_types) |T| { var stream = std.io.fixedBufferStream(&packed_float64_zero); const value = try unpackFloat(stream.reader(), T); - try std.testing.expectApproxEqAbs(0.0, value, std.math.floatEpsAt(minFloatType(T, f64), @floatCast(value))); + try std.testing.expectApproxEqAbs(0.0, value, std.math.floatEpsAt(MinFloatType(T, f64), @floatCast(value))); } } @@ -121,7 +121,7 @@ test "readFloat: float32 (pi)" { inline for (float_types) |T| { var stream = std.io.fixedBufferStream(&packed_float32_pi); const value = try unpackFloat(stream.reader(), T); - try std.testing.expectApproxEqAbs(std.math.pi, value, std.math.floatEpsAt(minFloatType(T, f32), @floatCast(value))); + try std.testing.expectApproxEqAbs(std.math.pi, value, std.math.floatEpsAt(MinFloatType(T, f32), @floatCast(value))); } } @@ -129,7 +129,7 @@ test "readFloat: float64 (pi)" { inline for (float_types) |T| { var stream = std.io.fixedBufferStream(&packed_float64_pi); const value = try unpackFloat(stream.reader(), T); - try std.testing.expectApproxEqAbs(std.math.pi, value, std.math.floatEpsAt(minFloatType(T, f64), @floatCast(value))); + try std.testing.expectApproxEqAbs(std.math.pi, value, std.math.floatEpsAt(MinFloatType(T, f64), @floatCast(value))); } } diff --git a/src/union.zig b/src/union.zig index 134fa45..3bcd971 100644 --- a/src/union.zig +++ b/src/union.zig @@ -50,9 +50,9 @@ fn strPrefix(src: []const u8, len: usize) []const u8 { pub fn packUnionAsMap(writer: anytype, comptime T: type, value: T, opts: UnionAsMapOptions) !void { const type_info = @typeInfo(T); - const fields = type_info.Union.fields; + const fields = type_info.@"union".fields; - const TagType = @typeInfo(T).Union.tag_type.?; + const TagType = @typeInfo(T).@"union".tag_type.?; try packMapHeader(writer, 1); @@ -79,7 +79,7 @@ pub fn packUnion(writer: anytype, comptime T: type, value_or_maybe_null: T) !voi const Type = @TypeOf(value); const type_info = @typeInfo(Type); - if (type_info != .Union) { + if (type_info != .@"union") { @compileError("Expected union type"); } @@ -92,7 +92,7 @@ pub fn packUnion(writer: anytype, comptime T: type, value_or_maybe_null: T) !voi } pub fn unpackUnionAsMap(reader: anytype, allocator: std.mem.Allocator, comptime T: type, opts: UnionAsMapOptions) !T { - const len = if (@typeInfo(T) == .Optional) + const len = if (@typeInfo(T) == .optional) try unpackMapHeader(reader, ?u16) orelse return null else try unpackMapHeader(reader, u16); @@ -103,7 +103,7 @@ pub fn unpackUnionAsMap(reader: anytype, allocator: std.mem.Allocator, comptime const Type = NonOptional(T); const type_info = @typeInfo(Type); - const fields = type_info.Union.fields; + const fields = type_info.@"union".fields; var field_name_buffer: [256]u8 = undefined;