lib/choir/src/composition/module/serialization/call.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const composition = @import("../../root.zig");
3 const model = @import("../root.zig");
4 const serialization = @import("root.zig");
5
6 const source = composition.source;
7 const Reader = serialization.format.Reader;
8 const Writer = serialization.format.Writer;
9
10 pub fn write(writer: *Writer, value: model.CallSite) serialization.SerializeError!void {
11 try writer.writeInt(u64, value.id.value);
12 try writer.writeString(value.name);
13 try writer.writeInt(u64, value.caller.value);
14 try writer.writeString(value.caller_export);
15 try writer.writeString(value.runtime_import);
16 try writer.writeInt(u64, value.callee.value);
17 try writer.writeString(value.callee_export);
18 try serialization.source.writeBoundaryIds(writer, value.inputs);
19 try serialization.source.writeBoundaryIds(writer, value.outputs);
20 try writer.writeInt(u32, value.abi_version);
21 try serialization.provenance.write(writer, value.provenance);
22 }
23
24 pub fn read(
25 allocator: std.mem.Allocator,
26 reader: *Reader,
27 ) serialization.DeserializeError!model.CallSiteSpec {
28 const id = source.CallSiteId{ .value = try reader.readInt(u64) };
29 const name = try reader.readString();
30 const caller = source.FragmentId{ .value = try reader.readInt(u64) };
31 const caller_export = try reader.readString();
32 const runtime_import = try reader.readString();
33 const callee = source.FragmentId{ .value = try reader.readInt(u64) };
34 const callee_export = try reader.readString();
35 const inputs = try serialization.source.readBoundaryIds(allocator, reader);
36 errdefer allocator.free(inputs);
37 const outputs = try serialization.source.readBoundaryIds(allocator, reader);
38 errdefer allocator.free(outputs);
39 const abi_version = try reader.readInt(u32);
40 const provenance = try serialization.provenance.read(reader);
41 return .{
42 .id = id,
43 .name = name,
44 .caller = caller,
45 .caller_export = caller_export,
46 .runtime_import = runtime_import,
47 .callee = callee,
48 .callee_export = callee_export,
49 .inputs = inputs,
50 .outputs = outputs,
51 .abi_version = abi_version,
52 .provenance = provenance,
53 };
54 }
55
56 pub fn deinitReadSpec(allocator: std.mem.Allocator, spec: model.CallSiteSpec) void {
57 allocator.free(spec.outputs);
58 allocator.free(spec.inputs);
59 }