Add type to Item tagged union to enable decoding of session object

This commit is contained in:
Marco Zanon
2025-07-11 12:00:24 +02:00
parent dfca0c8752
commit 9599ba5f9e

View File

@ -278,6 +278,7 @@ pub const ItemType = enum {
pub const Item = union(enum) {
encoded: EncodedItem,
attachment: Attachment,
session: Session,
/// Convert the item to an encoded item. This modify the item
/// in place.
@ -288,6 +289,7 @@ pub const Item = union(enum) {
const result: EncodedItem = switch (self.*) {
.encoded => |v| return v,
.attachment => |*v| try v.encode(alloc),
.session => |*v| try v.encode(alloc),
};
self.* = .{ .encoded = result };
return result;
@ -299,6 +301,7 @@ pub const Item = union(enum) {
return switch (self) {
.encoded => |v| v.type,
.attachment => .attachment,
.session => .session,
};
}
@ -335,6 +338,10 @@ pub const Item = union(enum) {
alloc,
encoded,
) },
.session => .{ .session = try .decode(
alloc,
encoded,
) },
else => return error.UnsupportedType,
};
}