| ... | @@ -58,11 +58,11 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -58,11 +58,11 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 58 | | 58 | |
| 59 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. | 59 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. |
| 60 | /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned and the `std.ArrayList` has exactly `max_append_size` bytes appended. | 60 | /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned and the `std.ArrayList` has exactly `max_append_size` bytes appended. |
| 61 | fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void { | 61 | fn readAllArrayList(self: Self, array_list: *std.array_list.Managed(u8), max_append_size: usize) !void { |
| 62 | return readAllArrayListAligned(self, null, array_list, max_append_size); | 62 | return readAllArrayListAligned(self, null, array_list, max_append_size); |
| 63 | } | 63 | } |
| 64 | | 64 | |
| 65 | fn readAllArrayListAligned(self: Self, comptime alignment: ?u29, array_list: *std.ArrayListAligned(u8, alignment), max_append_size: usize) !void { | 65 | fn readAllArrayListAligned(self: Self, comptime alignment: ?std.mem.Alignment, array_list: *std.array_list.AlignedManaged(u8, alignment), max_append_size: usize) !void { |
| 66 | try array_list.ensureTotalCapacity(@min(max_append_size, 4096)); | 66 | try array_list.ensureTotalCapacity(@min(max_append_size, 4096)); |
| 67 | const original_len = array_list.items.len; | 67 | const original_len = array_list.items.len; |
| 68 | var start_index: usize = original_len; | 68 | var start_index: usize = original_len; |
| ... | @@ -92,7 +92,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -92,7 +92,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 92 | /// Caller owns returned memory. | 92 | /// Caller owns returned memory. |
| 93 | /// If this function returns an error, the contents from the stream read so far are lost. | 93 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 94 | pub fn readAllAlloc(self: Self, allocator: std.mem.Allocator, max_size: usize) ![]u8 { | 94 | pub fn readAllAlloc(self: Self, allocator: std.mem.Allocator, max_size: usize) ![]u8 { |
| 95 | var array_list = std.ArrayList(u8).init(allocator); | 95 | var array_list = std.array_list.Managed(u8).init(allocator); |
| 96 | defer array_list.deinit(); | 96 | defer array_list.deinit(); |
| 97 | try readAllArrayList(self, &array_list, max_size); | 97 | try readAllArrayList(self, &array_list, max_size); |
| 98 | return try array_list.toOwnedSlice(); | 98 | return try array_list.toOwnedSlice(); |
| ... | @@ -109,7 +109,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -109,7 +109,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 109 | } | 109 | } |
| 110 | | 110 | |
| 111 | /// Returned slice is not suffixed by needle but array_list will contain it. | 111 | /// Returned slice is not suffixed by needle but array_list will contain it. |
| 112 | pub fn readUntilDelimiterArrayList(self: Self, array_list: *std.ArrayList(u8), needle: u8, max_size: usize) ![]u8 { | 112 | pub fn readUntilDelimiterArrayList(self: Self, array_list: *std.array_list.Managed(u8), needle: u8, max_size: usize) ![]u8 { |
| 113 | const initial_len = array_list.items.len; | 113 | const initial_len = array_list.items.len; |
| 114 | for (0..max_size) |i| { | 114 | for (0..max_size) |i| { |
| 115 | try array_list.append(try readByte(self)); | 115 | try array_list.append(try readByte(self)); |
| ... | @@ -120,14 +120,14 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -120,14 +120,14 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 120 | | 120 | |
| 121 | /// Returned slice is suffixed by needle. | 121 | /// Returned slice is suffixed by needle. |
| 122 | pub fn readUntilDelimiterAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) ![]u8 { | 122 | pub fn readUntilDelimiterAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) ![]u8 { |
| 123 | var list: std.ArrayList(u8) = .init(allocator); | 123 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 124 | errdefer list.deinit(); | 124 | errdefer list.deinit(); |
| 125 | _ = try readUntilDelimiterArrayList(self, &list, needle, max_size); | 125 | _ = try readUntilDelimiterArrayList(self, &list, needle, max_size); |
| 126 | return list.toOwnedSlice(); | 126 | return list.toOwnedSlice(); |
| 127 | } | 127 | } |
| 128 | | 128 | |
| 129 | pub fn readUntilDelimiterOrEofAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) !?[]u8 { | 129 | pub fn readUntilDelimiterOrEofAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) !?[]u8 { |
| 130 | var list: std.ArrayList(u8) = .init(allocator); | 130 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 131 | defer list.deinit(); | 131 | defer list.deinit(); |
| 132 | _ = readUntilDelimiterArrayList(self, &list, needle, max_size) catch |err| switch (err) { | 132 | _ = readUntilDelimiterArrayList(self, &list, needle, max_size) catch |err| switch (err) { |
| 133 | error.EndOfStream => return null, | 133 | error.EndOfStream => return null, |
| ... | @@ -149,7 +149,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -149,7 +149,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 149 | } | 149 | } |
| 150 | | 150 | |
| 151 | /// Returned slice is not suffixed by needle but array_list will contain it. | 151 | /// Returned slice is not suffixed by needle but array_list will contain it. |
| 152 | pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.ArrayList(u8), needle: []const u8, max_size: usize) ![]u8 { | 152 | pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.array_list.Managed(u8), needle: []const u8, max_size: usize) ![]u8 { |
| 153 | const initial_len = array_list.items.len; | 153 | const initial_len = array_list.items.len; |
| 154 | for (0..max_size) |i| { | 154 | for (0..max_size) |i| { |
| 155 | try array_list.append(try readByte(self)); | 155 | try array_list.append(try readByte(self)); |
| ... | @@ -159,7 +159,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -159,7 +159,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 159 | } | 159 | } |
| 160 | | 160 | |
| 161 | pub fn readAlloc(self: Self, allocator: std.mem.Allocator, size: usize) ![]u8 { | 161 | pub fn readAlloc(self: Self, allocator: std.mem.Allocator, size: usize) ![]u8 { |
| 162 | var array_list = try std.ArrayList(u8).initCapacity(allocator, size); | 162 | var array_list = try std.array_list.Managed(u8).initCapacity(allocator, size); |
| 163 | defer array_list.deinit(); | 163 | defer array_list.deinit(); |
| 164 | try array_list.ensureUnusedCapacity(size); | 164 | try array_list.ensureUnusedCapacity(size); |
| 165 | const len = try readAll(self, array_list.allocatedSlice()); | 165 | const len = try readAll(self, array_list.allocatedSlice()); |
| ... | @@ -176,7 +176,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -176,7 +176,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 176 | | 176 | |
| 177 | /// Returned slice is suffixed by needle. | 177 | /// Returned slice is suffixed by needle. |
| 178 | pub fn readUntilDelimitersAlloc(self: Self, allocator: std.mem.Allocator, needle: []const u8, max_size: usize) ![]u8 { | 178 | pub fn readUntilDelimitersAlloc(self: Self, allocator: std.mem.Allocator, needle: []const u8, max_size: usize) ![]u8 { |
| 179 | var list: std.ArrayList(u8) = .init(allocator); | 179 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 180 | errdefer list.deinit(); | 180 | errdefer list.deinit(); |
| 181 | _ = try readUntilDelimitersArrayList(self, &list, needle, max_size); | 181 | _ = try readUntilDelimitersArrayList(self, &list, needle, max_size); |
| 182 | return list.toOwnedSlice(); | 182 | return list.toOwnedSlice(); |