msg: return error if input does not have "size:"

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-09 15:13:06 +02:00
parent e53b9d984b
commit 17c641845e

View File

@@ -73,7 +73,7 @@ pub const MsgBuffer = struct {
var msg_size: usize = undefined; var msg_size: usize = undefined;
if (self.isEmpty()) { if (self.isEmpty()) {
// parse msg size metadata // parse msg size metadata
const size_pos = std.mem.indexOfScalar(u8, _input, ':').?; const size_pos = std.mem.indexOfScalar(u8, _input, ':') orelse return error.InputWithoutSize;
const size_str = _input[0..size_pos]; const size_str = _input[0..size_pos];
msg_size = try std.fmt.parseInt(u32, size_str, 10); msg_size = try std.fmt.parseInt(u32, size_str, 10);
_input = _input[size_pos + 1 ..]; _input = _input[size_pos + 1 ..];