MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / serialize

Method serialize

bindings/frankenswig/struct.py:72–90  ·  view source on GitHub ↗

Add "from_json" and "to_json" methods.

(self)

Source from the content-addressed store, hash-verified

70class DeriveMixins(object):
71 '''Helpers for easily bindings #[derive]'d methods.'''
72 def serialize(self):
73 '''Add "from_json" and "to_json" methods.'''
74
75 args = [Var(self.program.strref.type, "s")]
76 type = self.type.result()
77 self.methods.append(Method(
78 type, self.c_name, "from_json", args,
79 make_safe_call(type, f'serde_json::from_str::<{self.module}::{self.name}>', args),
80 docs=f'Deserialize a {self.type.to_python()} from a JSON string',
81 static=True
82 ))
83
84 args = [Var(self.type.mut_ref(), 'this')]
85 type = self.program.string.type.result()
86 self.methods.append(Method(type, self.c_name, "to_json", args,
87 make_safe_call(type, 'serde_json::to_string', args), docs=f'Serialize a {self.type.to_python()} to a JSON string'
88 ))
89
90 return self
91
92 def debug(self):
93 args = [Var(self.type.mut_ref(), 'this')]

Callers 2

generate.pyFile · 0.80
serialize_structymapFunction · 0.80

Calls 6

VarClass · 0.85
MethodClass · 0.85
make_safe_callFunction · 0.85
resultMethod · 0.80
to_pythonMethod · 0.45
mut_refMethod · 0.45

Tested by

no test coverage detected