|
18 | 18 |
|
19 | 19 | const std = @import("std"); |
20 | 20 |
|
21 | | -pub const MsgSize = 16 * 1204; // 16KB |
22 | | -pub const HeaderSize = 2; |
| 21 | +pub const HeaderSize = 4; |
| 22 | +pub const MsgSize = 256 * 1204; // 256KB |
| 23 | +// NOTE: Theorically we could go up to 4GB with a 4 bytes binary encoding |
| 24 | +// but we prefer to put a lower hard limit for obvious memory size reasons. |
| 25 | + |
23 | 26 | pub const MaxSize = HeaderSize + MsgSize; |
24 | 27 |
|
25 | 28 | pub const Msg = struct { |
26 | 29 | pub fn getSize(data: []const u8) usize { |
27 | | - return std.mem.readInt(u16, data[0..HeaderSize], .little); |
| 30 | + return std.mem.readInt(u32, data[0..HeaderSize], .little); |
28 | 31 | } |
29 | 32 |
|
30 | | - pub fn setSize(len: usize, header: *[2]u8) void { |
31 | | - std.mem.writeInt(u16, header, @intCast(len), .little); |
| 33 | + pub fn setSize(len: usize, header: *[4]u8) void { |
| 34 | + std.mem.writeInt(u32, header, @intCast(len), .little); |
32 | 35 | } |
33 | 36 | }; |
34 | 37 |
|
@@ -121,26 +124,26 @@ test "Buffer" { |
121 | 124 |
|
122 | 125 | const cases = [_]Case{ |
123 | 126 | // simple |
124 | | - .{ .input = .{ 2, 0 } ++ "ok", .nb = 1 }, |
| 127 | + .{ .input = .{ 2, 0, 0, 0 } ++ "ok", .nb = 1 }, |
125 | 128 | // combined |
126 | | - .{ .input = .{ 2, 0 } ++ "ok" ++ .{ 3, 0 } ++ "foo", .nb = 2 }, |
| 129 | + .{ .input = .{ 2, 0, 0, 0 } ++ "ok" ++ .{ 3, 0, 0, 0 } ++ "foo", .nb = 2 }, |
127 | 130 | // multipart |
128 | | - .{ .input = .{ 9, 0 } ++ "multi", .nb = 0 }, |
| 131 | + .{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 }, |
129 | 132 | .{ .input = "part", .nb = 1 }, |
130 | 133 | // multipart & combined |
131 | | - .{ .input = .{ 9, 0 } ++ "multi", .nb = 0 }, |
132 | | - .{ .input = "part" ++ .{ 2, 0 } ++ "ok", .nb = 2 }, |
| 134 | + .{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 }, |
| 135 | + .{ .input = "part" ++ .{ 2, 0, 0, 0 } ++ "ok", .nb = 2 }, |
133 | 136 | // multipart & combined with other multipart |
134 | | - .{ .input = .{ 9, 0 } ++ "multi", .nb = 0 }, |
135 | | - .{ .input = "part" ++ .{ 8, 0 } ++ "co", .nb = 1 }, |
| 137 | + .{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 }, |
| 138 | + .{ .input = "part" ++ .{ 8, 0, 0, 0 } ++ "co", .nb = 1 }, |
136 | 139 | .{ .input = "mbined", .nb = 1 }, |
137 | 140 | // several multipart |
138 | | - .{ .input = .{ 23, 0 } ++ "multi", .nb = 0 }, |
| 141 | + .{ .input = .{ 23, 0, 0, 0 } ++ "multi", .nb = 0 }, |
139 | 142 | .{ .input = "several", .nb = 0 }, |
140 | 143 | .{ .input = "complex", .nb = 0 }, |
141 | 144 | .{ .input = "part", .nb = 1 }, |
142 | 145 | // combined & multipart |
143 | | - .{ .input = .{ 2, 0 } ++ "ok" ++ .{ 9, 0 } ++ "multi", .nb = 1 }, |
| 146 | + .{ .input = .{ 2, 0, 0, 0 } ++ "ok" ++ .{ 9, 0, 0, 0 } ++ "multi", .nb = 1 }, |
144 | 147 | .{ .input = "part", .nb = 1 }, |
145 | 148 | }; |
146 | 149 |
|
|
0 commit comments