aboutsummaryrefslogtreecommitdiff
path: root/src/proto
diff options
context:
space:
mode:
Diffstat (limited to 'src/proto')
-rw-r--r--src/proto/command_complete.zig7
-rw-r--r--src/proto/data_row.zig8
-rw-r--r--src/proto/row_description.zig8
3 files changed, 23 insertions, 0 deletions
diff --git a/src/proto/command_complete.zig b/src/proto/command_complete.zig
index ed8e052..f9a9e26 100644
--- a/src/proto/command_complete.zig
+++ b/src/proto/command_complete.zig
@@ -30,6 +30,13 @@ pub fn deinit(self: *CommandComplete, a: std.mem.Allocator) void {
if (self.buf != null) a.free(self.buf.?);
}
+pub fn clone(self: CommandComplete, a: std.mem.Allocator) !CommandComplete {
+ var ba = ByteArrayList.init(a);
+ errdefer ba.deinit();
+ try self.write(a, ba.writer());
+ return try CommandComplete.read(a, ba.items);
+}
+
test "round trip" {
const allocator = std.testing.allocator;
var sm = CommandComplete{
diff --git a/src/proto/data_row.zig b/src/proto/data_row.zig
index 43c4526..6bfcc1d 100644
--- a/src/proto/data_row.zig
+++ b/src/proto/data_row.zig
@@ -54,6 +54,14 @@ pub fn deinit(self: *DataRow, a: std.mem.Allocator) void {
a.free(self.columns);
}
+// Caller owns the new DataRow.
+pub fn clone(self: DataRow, a: std.mem.Allocator) !DataRow {
+ var ba = ByteArrayList.init(a);
+ errdefer ba.deinit();
+ try self.write(a, ba.writer());
+ return try DataRow.read(a, ba.items);
+}
+
test "round trip" {
const allocator = std.testing.allocator;
const columns = try allocator.alloc([]const u8, 3);
diff --git a/src/proto/row_description.zig b/src/proto/row_description.zig
index ff17716..50e4cb0 100644
--- a/src/proto/row_description.zig
+++ b/src/proto/row_description.zig
@@ -74,6 +74,14 @@ pub fn write(self: RowDescription, a: std.mem.Allocator, stream_writer: anytype)
try stream_writer.writeAll(al.items);
}
+// Caller owns the result.
+pub fn clone(self: RowDescription, a: std.mem.Allocator) !RowDescription {
+ var ba = ByteArrayList.init(a);
+ errdefer ba.deinit();
+ try self.write(a, ba.writer());
+ return try RowDescription.read(a, ba.items);
+}
+
pub fn deinit(self: *RowDescription, a: std.mem.Allocator) void {
a.free(self.fields);
if (self.buf != null) a.free(self.buf.?);