aboutsummaryrefslogtreecommitdiff
path: root/src/proto/copy_x_response.zig
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-09-28 10:54:58 +0100
committerMartin Ashby <martin@ashbysoft.com>2023-09-28 10:54:58 +0100
commit35494bc81b59165ee9264cd1004bb05a120279a3 (patch)
tree8d11946f8fc20e1f254301100e860f28bade5ee0 /src/proto/copy_x_response.zig
parent0c063d42430077881e563120ebfcf92c2cecf463 (diff)
downloadpgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.gz
pgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.bz2
pgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.xz
pgz-35494bc81b59165ee9264cd1004bb05a120279a3.zip
Reduce allocations, the message takes ownership of the bytes read from
the stream and is responsible for deallocating, rather than copying them to their own storage.
Diffstat (limited to 'src/proto/copy_x_response.zig')
-rw-r--r--src/proto/copy_x_response.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/proto/copy_x_response.zig b/src/proto/copy_x_response.zig
index 9d1b26c..a4370a7 100644
--- a/src/proto/copy_x_response.zig
+++ b/src/proto/copy_x_response.zig
@@ -13,8 +13,9 @@ pub fn CopyXResponse(comptime tag: u8) type {
overall_format_code: u8,
format_codes: []const FormatCode, // owned
- pub fn read(a: std.mem.Allocator, b: []const u8) !@This() {
- var fbs = std.io.fixedBufferStream(b);
+ pub fn read(a: std.mem.Allocator, buf: []const u8) !@This() {
+ defer a.free(buf);
+ var fbs = std.io.fixedBufferStream(buf);
var reader = fbs.reader();
const overall_format_code = try reader.readIntBig(u8);
const n_columns = try reader.readIntBig(u16);
@@ -76,7 +77,6 @@ test "round trip" {
try std.testing.expectEqual(Tag, tag);
const len = try reader.readIntBig(u32);
const buf = try allocator.alloc(u8, len - 4);
- defer allocator.free(buf);
try reader.readNoEof(buf);
var sm2 = try CopyInResponse.read(allocator, buf);
defer sm2.deinit(allocator);