Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple examples in docstrings of serializers #653

Merged
merged 1 commit into from Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,8 +18,12 @@
class ArraySerializer(CairoDataSerializer[Iterable, List]):
"""
Serializer for arrays. In abi they are represented as a pointer to a type.
Can serialize any iterable.
Can serialize any iterable and prepends its length to resulting list.
Deserializes data to a TupleDataclass.

Examples:
[1,2,3] => [3,1,2,3]
[] => [0]
"""

inner_serializer: CairoDataSerializer
Expand Down
Expand Up @@ -23,6 +23,9 @@ class NamedTupleSerializer(
Serializer for tuples with named fields.
Can serialize a dictionary, a named tuple and TupleDataclass.
Deserializes data to a TupleDataclass.

Example:
{"a": 1, "b": 2} => [1,2]
"""

serializers: OrderedDict[str, CairoDataSerializer]
Expand Down
Expand Up @@ -31,6 +31,9 @@ class PayloadSerializer(CairoDataSerializer[Dict, TupleDataclass]):
Serializer for payloads like function arguments/function outputs/events.
Can serialize a dictionary.
Deserializes data to a TupleDataclass.

Example:
{"a": 1, "b": 2} => [1,2]
"""

# Value present only in constructor.
Expand Down
Expand Up @@ -20,6 +20,9 @@ class StructSerializer(CairoDataSerializer[Dict, Dict]):
Serializer of custom structures.
Can serialize a dictionary.
Deserializes data to a dictionary.

Example:
{"a": 1, "b": 2} => [1,2]
"""

serializers: OrderedDict[str, CairoDataSerializer]
Expand Down
Expand Up @@ -20,6 +20,9 @@ class TupleSerializer(CairoDataSerializer[Iterable, Tuple]):
Serializer for tuples without named fields.
Can serialize any iterable.
Deserializes data to a python tuple.

Example:
(1,2,(3,4)) => [1,2,3,4]
"""

serializers: List[CairoDataSerializer]
Expand Down
Expand Up @@ -19,6 +19,12 @@ class Uint256Serializer(CairoDataSerializer[int, int]):
Serializer of Uint256. In Cairo it is represented by structure {low: Uint128, high: Uint128}.
Can serialize an int.
Deserializes data to an int.

Examples:
0 => [0,0]
1 => [1,0]
2**128 => [0,1]
3 + 2**128 => [3,1]
"""

def deserialize_with_context(self, context: DeserializationContext) -> int:
Expand Down