summaryrefslogtreecommitdiff
path: root/src/message.zig
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-09-23 16:16:12 -0400
committerRobby Zambito <contact@robbyzambito.me>2025-09-23 16:22:57 -0400
commitb06cb6dadac809322b6a293fbedf401870028d6e (patch)
tree4f53d71d846f6a0aed6b0f95199d45b2c35bf8e6 /src/message.zig
parentb8313e4fa4ced3462e2fadaa123c917fcb063c18 (diff)
it works well!
Diffstat (limited to 'src/message.zig')
-rw-r--r--src/message.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/message.zig b/src/message.zig
index 1308d54..59864ba 100644
--- a/src/message.zig
+++ b/src/message.zig
@@ -71,7 +71,7 @@ pub const Message = packed struct {
};
const Self = @This();
- const SelfBytes = []align(@alignOf(Self)) u8;
+ const SelfBytes = []align(1) u8;
type: PacketType,
length: u16,
@@ -81,9 +81,9 @@ pub const Message = packed struct {
/// This properly initializes the top level headers within the slice.
/// This is used for creating new messages. For reading messages from the network,
/// see: networkBytesAsValue.
- pub fn init(@"type": PacketType, bytes: []align(@alignOf(Self)) u8) *Self {
+ pub fn init(@"type": PacketType, bytes: []u8) *align(1) Self {
std.debug.assert(bytes.len >= @sizeOf(Self));
- const res: *Self = @ptrCast(bytes.ptr);
+ const res: *align(1) Self = @ptrCast(bytes.ptr);
res.type = @"type";
res.length = @intCast(bytes.len - @sizeOf(Self));
return res;
@@ -100,15 +100,15 @@ pub const Message = packed struct {
return @intCast(payload_len + @sizeOf(Self) + header_size);
}
- fn getRelay(self: *Self) *align(1) Relay {
+ fn getRelay(self: *align(1) Self) *align(1) Relay {
return std.mem.bytesAsValue(Relay, &self.bytes);
}
- fn getConnection(self: *Self) *align(1) Connection {
+ fn getConnection(self: *align(1) Self) *align(1) Connection {
return std.mem.bytesAsValue(Connection, &self.bytes);
}
/// Access the message Saprus payload.
- pub fn getSaprusTypePayload(self: *Self) MessageTypeError!(union(PacketType) {
+ pub fn getSaprusTypePayload(self: *align(1) Self) MessageTypeError!(union(PacketType) {
relay: *align(1) Relay,
file_transfer: void,
connection: *align(1) Connection,
@@ -122,7 +122,7 @@ pub const Message = packed struct {
}
/// Convert the message to native endianness from network endianness in-place.
- pub fn nativeFromNetworkEndian(self: *Self) MessageTypeError!void {
+ pub fn nativeFromNetworkEndian(self: *align(1) Self) MessageTypeError!void {
self.type = @enumFromInt(bigToNative(
@typeInfo(@TypeOf(self.type)).@"enum".tag_type,
@intFromEnum(self.type),
@@ -146,7 +146,7 @@ pub const Message = packed struct {
}
/// Convert the message to network endianness from native endianness in-place.
- pub fn networkFromNativeEndian(self: *Self) MessageTypeError!void {
+ pub fn networkFromNativeEndian(self: *align(1) Self) MessageTypeError!void {
try switch (try self.getSaprusTypePayload()) {
.relay => {},
.connection => |*con| con.*.networkFromNativeEndian(),
@@ -161,7 +161,7 @@ pub const Message = packed struct {
}
/// Convert network endian bytes to a native endian value in-place.
- pub fn networkBytesAsValue(bytes: SelfBytes) MessageParseError!*Self {
+ pub fn networkBytesAsValue(bytes: SelfBytes) MessageParseError!*align(1) Self {
const res = std.mem.bytesAsValue(Self, bytes);
try res.nativeFromNetworkEndian();
return .bytesAsValue(bytes);
@@ -169,7 +169,7 @@ pub const Message = packed struct {
/// Create a structured view of the bytes without initializing the length or type,
/// and without converting the endianness.
- pub fn bytesAsValue(bytes: SelfBytes) MessageParseError!*Self {
+ pub fn bytesAsValue(bytes: SelfBytes) MessageParseError!*align(1) Self {
const res = std.mem.bytesAsValue(Self, bytes);
return switch (res.type) {
.relay, .connection => if (bytes.len == res.length + @sizeOf(Self))
@@ -183,9 +183,9 @@ pub const Message = packed struct {
/// Deprecated.
/// If I need the bytes, I should just pass around the slice that is backing this to begin with.
- pub fn asBytes(self: *Self) SelfBytes {
+ pub fn asBytes(self: *align(1) Self) SelfBytes {
const size = @sizeOf(Self) + self.length;
- return @as([*]align(@alignOf(Self)) u8, @ptrCast(self))[0..size];
+ return @as([*]align(1) u8, @ptrCast(self))[0..size];
}
};