Remove bytesAsValueUnchecked

Callers can instead use std.mem.bytesAsValue directly.
This commit is contained in:
2025-04-30 10:56:42 -04:00
parent 1512ec1a86
commit 1b7d9bbb1a

View File

@@ -71,6 +71,7 @@ pub const ZeroCopyMessage = packed struct {
};
const Self = @This();
const SelfBytes = []align(@alignOf(Self)) u8;
type: PacketType,
length: u16,
@@ -143,12 +144,8 @@ pub const ZeroCopyMessage = packed struct {
self.length = nativeToBig(@TypeOf(self.length), self.length);
}
pub fn bytesAsValueUnchecked(bytes: []align(@alignOf(Self)) u8) *Self {
return std.mem.bytesAsValue(Self, bytes);
}
pub fn bytesAsValue(bytes: []align(@alignOf(Self)) u8) !*Self {
const res = bytesAsValueUnchecked(bytes);
pub fn bytesAsValue(bytes: SelfBytes) !*Self {
const res = std.mem.bytesAsValue(Self, bytes);
return switch (res.type) {
.relay, .connection => if (bytes.len == res.length + @sizeOf(Self))
res
@@ -159,7 +156,7 @@ pub const ZeroCopyMessage = packed struct {
};
}
pub fn asBytes(self: *Self) []align(@alignOf(Self)) u8 {
pub fn asBytes(self: *Self) SelfBytes {
const size = @sizeOf(Self) + self.length;
return @as([*]align(@alignOf(Self)) u8, @ptrCast(self))[0..size];
}