aboutsummaryrefslogtreecommitdiff
path: root/src/proto/ready_for_query.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/ready_for_query.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/ready_for_query.zig')
-rw-r--r--src/proto/ready_for_query.zig9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/proto/ready_for_query.zig b/src/proto/ready_for_query.zig
index ef99e60..6bf25f9 100644
--- a/src/proto/ready_for_query.zig
+++ b/src/proto/ready_for_query.zig
@@ -14,10 +14,10 @@ const TransactionStatus = enum(u8) {
transaction_status: TransactionStatus,
-pub fn read(allocator: std.mem.Allocator, b: []const u8) !ReadyForQuery {
- _ = allocator;
- if (b.len != 1) return ProtocolError.InvalidMessageLength;
- return .{ .transaction_status = enum_from_int(TransactionStatus, b[0]) orelse return ProtocolError.InvalidTransactionStatus };
+pub fn read(a: std.mem.Allocator, buf: []const u8) !ReadyForQuery {
+ defer a.free(buf);
+ if (buf.len != 1) return ProtocolError.InvalidMessageLength;
+ return .{ .transaction_status = enum_from_int(TransactionStatus, buf[0]) orelse return ProtocolError.InvalidTransactionStatus };
}
pub fn write(self: ReadyForQuery, allocator: std.mem.Allocator, stream_writer: anytype) !void {
_ = allocator;
@@ -44,7 +44,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 ReadyForQuery.read(allocator, buf);
defer sm2.deinit(allocator);