Selfie
Loading...
Searching...
No Matches
selfie_lib.Roundtrip.Roundtrip Class Reference
Inheritance diagram for selfie_lib.Roundtrip.Roundtrip:

Public Member Functions

SerializedForm serialize (self, T value)
 
T parse (self, SerializedForm serialized)
 
"Roundtrip[T, T]" identity (cls)
 
"Roundtrip[T, str]" json (cls)
 

Detailed Description

Definition at line 8 of file Roundtrip.py.

Member Function Documentation

◆ identity()

"Roundtrip[T, T]" selfie_lib.Roundtrip.Roundtrip.identity (   cls)
Return an identity Roundtrip that does no transformation.

Definition at line 18 of file Roundtrip.py.

18 def identity(cls) -> "Roundtrip[T, T]":
19 """Return an identity Roundtrip that does no transformation."""
20
21 class Identity(Roundtrip[Any, Any]):
22 def serialize(self, value: Any) -> Any:
23 return value
24
25 def parse(self, serialized: Any) -> Any:
26 return serialized
27
28 return Identity()
29

◆ json()

"Roundtrip[T, str]" selfie_lib.Roundtrip.Roundtrip.json (   cls)
Return a Roundtrip that serializes to/from JSON strings.

Definition at line 31 of file Roundtrip.py.

31 def json(cls) -> "Roundtrip[T, str]":
32 """Return a Roundtrip that serializes to/from JSON strings."""
33 import json
34
35 class JsonRoundtrip(Roundtrip[Any, str]):
36 def serialize(self, value: Any) -> str:
37 return json.dumps(value, indent=4)
38
39 def parse(self, serialized: str) -> Any:
40 return json.loads(serialized)
41
42 return JsonRoundtrip()

◆ parse()

T selfie_lib.Roundtrip.Roundtrip.parse (   self,
SerializedForm  serialized 
)
Parse the SerializedForm back to type T.

Definition at line 13 of file Roundtrip.py.

13 def parse(self, serialized: SerializedForm) -> T:
14 """Parse the SerializedForm back to type T."""
15 raise NotImplementedError
16

◆ serialize()

SerializedForm selfie_lib.Roundtrip.Roundtrip.serialize (   self,
T  value 
)
Serialize a value of type T to its SerializedForm.

Definition at line 9 of file Roundtrip.py.

9 def serialize(self, value: T) -> SerializedForm:
10 """Serialize a value of type T to its SerializedForm."""
11 raise NotImplementedError
12

The documentation for this class was generated from the following file: