mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24: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 Self = @This();
|
||||||
|
const SelfBytes = []align(@alignOf(Self)) u8;
|
||||||
|
|
||||||
type: PacketType,
|
type: PacketType,
|
||||||
length: u16,
|
length: u16,
|
||||||
@@ -143,12 +144,8 @@ pub const ZeroCopyMessage = packed struct {
|
|||||||
self.length = nativeToBig(@TypeOf(self.length), self.length);
|
self.length = nativeToBig(@TypeOf(self.length), self.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytesAsValueUnchecked(bytes: []align(@alignOf(Self)) u8) *Self {
|
pub fn bytesAsValue(bytes: SelfBytes) !*Self {
|
||||||
return std.mem.bytesAsValue(Self, bytes);
|
const res = std.mem.bytesAsValue(Self, bytes);
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bytesAsValue(bytes: []align(@alignOf(Self)) u8) !*Self {
|
|
||||||
const res = bytesAsValueUnchecked(bytes);
|
|
||||||
return switch (res.type) {
|
return switch (res.type) {
|
||||||
.relay, .connection => if (bytes.len == res.length + @sizeOf(Self))
|
.relay, .connection => if (bytes.len == res.length + @sizeOf(Self))
|
||||||
res
|
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;
|
const size = @sizeOf(Self) + self.length;
|
||||||
return @as([*]align(@alignOf(Self)) u8, @ptrCast(self))[0..size];
|
return @as([*]align(@alignOf(Self)) u8, @ptrCast(self))[0..size];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user