Logo

index : blog

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/blog.git/html/src/marshal.jai blob: b3a7da872f61e618c37e72f6ef25cf1465901fd2 [raw] [clear marker]

        
0#import "osor_serialization";
1
2
3/** From my game: proto2 */
4
5
6marshal :: inline (input: *$T) -> []u8 {
7 return serialize(input);
8}
9
10unmarshal :: inline (bytes: []u8, $Output_Type: Type) -> *Output_Type {
11 return deserialize(bytes, Output_Type);
12}
13
14marshal_and_save_to_disk :: (file_path: string, input: *$T) -> ok: bool {
15 bytes := marshal(input);
16
17 ok := write_entire_file(file_path, bytes.data, bytes.count);
18
19 // TODO(adam, 5): Error reporter
20 if !ok {
21 log_error("Could not write file: %", file_path);
22 return false;
23 }
24
25 return true;
26}
27
28read_from_disk_and_unmarshal :: (file_path: string, $Output_Type: Type)
29 -> (ok: bool, output: *Output_Type)
30{
31 bin, ok := read_entire_file(file_path, log_errors = true);
32 if !ok return ok, null;
33
34 return true, unmarshal(cast([]u8, bin), Output_Type);
35}
36
37
38
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit