mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
41 lines
1.2 KiB
Zig
41 lines
1.2 KiB
Zig
data: Data = .{ .empty = {} },
|
|
|
|
pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReader(Container)) !void {
|
|
const length = try reader.length();
|
|
|
|
const data = try reader.read(@intCast(length -| 5));
|
|
this.* = .{
|
|
.data = data,
|
|
};
|
|
}
|
|
|
|
pub const decode = DecoderWrap(CopyData, decodeInternal).decode;
|
|
|
|
pub fn writeInternal(
|
|
this: *const @This(),
|
|
comptime Context: type,
|
|
writer: NewWriter(Context),
|
|
) !void {
|
|
const data = this.data.slice();
|
|
const count: u32 = @sizeOf((u32)) + data.len + 1;
|
|
const header = [_]u8{
|
|
'd',
|
|
} ++ toBytes(Int32(count));
|
|
try writer.write(&header);
|
|
try writer.string(data);
|
|
}
|
|
|
|
pub const write = WriteWrap(@This(), writeInternal).write;
|
|
|
|
// @sortImports
|
|
|
|
const CopyData = @This();
|
|
const std = @import("std");
|
|
const Data = @import("../Data.zig").Data;
|
|
const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
|
|
const Int32 = @import("../types/int_types.zig").Int32;
|
|
const NewReader = @import("./NewReader.zig").NewReader;
|
|
const NewWriter = @import("./NewWriter.zig").NewWriter;
|
|
const WriteWrap = @import("./WriteWrap.zig").WriteWrap;
|
|
const toBytes = std.mem.toBytes;
|