2022-02-27 15:49:00 +02:00
|
|
|
const std = @import("std");
|
|
|
|
|
2022-03-22 08:57:57 +02:00
|
|
|
pub fn downCast(comptime T: type, n: u64) error{InvalidRecord}!T {
|
2022-02-27 15:49:00 +02:00
|
|
|
return std.math.cast(T, n) catch |err| switch (err) {
|
|
|
|
error.Overflow => {
|
|
|
|
return error.InvalidRecord;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:57:57 +02:00
|
|
|
pub fn utf8(s: []const u8) error{InvalidRecord}!void {
|
2022-02-27 15:49:00 +02:00
|
|
|
if (!std.unicode.utf8ValidateSlice(s)) {
|
|
|
|
return error.InvalidRecord;
|
|
|
|
}
|
|
|
|
}
|