mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 08:14:50 +00:00
Remove bytesAsValueUnchecked
Callers can instead use std.mem.bytesAsValue directly.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user