File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
binding/python/py/synlink Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ from typing import NewType , Protocol , runtime_checkable
2
+
3
+ from .utils import _check_minimum_version
4
+
5
+ if _check_minimum_version (3 , 11 ):
6
+ from typing import Self
7
+ else :
8
+ from typing_extensions import Self
9
+
10
+ __all__ = ["TProtocol" ]
11
+
12
+
13
+ @runtime_checkable
14
+ class Serializable (Protocol ):
15
+ """
16
+ Such protocol can be used to check if an object can be translated
17
+ and format into a bit repersentation
18
+
19
+ Example:
20
+ ```
21
+ from synlink.crypto import PrivateKey, PublicKey, create_new_key_pair
22
+
23
+ keypair : Keypair = create_new_key_pair()
24
+ assert not isinstance(keypair.seceret, Serializable), "seceret key should be able to serializable."
25
+ assert not isinstance(keypair.public, Serializable), "public key should be able to serializable."
26
+
27
+ layout : bytes = keypair.to_bytes()
28
+ del keypair
29
+ ```
30
+ """
31
+
32
+ def to_bytes (self ) -> bytes :
33
+ """serialize the object into bytes."""
34
+ ...
35
+
36
+ @classmethod
37
+ def from_bytes (cls , data : bytes ) -> Self :
38
+ """deserialize the object from bytes."""
39
+ ...
40
+
41
+
42
+ TProtocol = NewType ("TProtocol" , str )
You can’t perform that action at this time.
0 commit comments