From c00a7cd57be154b5a770a397319c8c8ad35c98b6 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Thu, 28 Sep 2023 20:46:10 +0100 Subject: WIP --- src/proto/data_row.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/proto/data_row.zig') 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); -- cgit v1.2.3-ZIG