<<
path:
root/public/blog.git/html/src/marshal.jai
blob: b3a7da872f61e618c37e72f6ef25cf1465901fd2
[raw]
[clear marker]
0#import "osor_serialization";
3/** From my game: proto2 */
6marshal :: inline (input: *$T) -> []u8 {
7 return serialize(input);
10unmarshal :: inline (bytes: []u8, $Output_Type: Type) -> *Output_Type {
11 return deserialize(bytes, Output_Type);
14marshal_and_save_to_disk :: (file_path: string, input: *$T) -> ok: bool {
15 bytes := marshal(input);
17 ok := write_entire_file(file_path, bytes.data, bytes.count);
19 // TODO(adam, 5): Error reporter
21 log_error("Could not write file: %", file_path);
28read_from_disk_and_unmarshal :: (file_path: string, $Output_Type: Type)
29 -> (ok: bool, output: *Output_Type)
31 bin, ok := read_entire_file(file_path, log_errors = true);
32 if !ok return ok, null;
34 return true, unmarshal(cast([]u8, bin), Output_Type);