@@ -12,6 +12,8 @@ def serialize(obj: typing.Any) -> BitBuffer:
12
12
"""
13
13
Serializes generated object to the bit buffer.
14
14
15
+ Before serialization, the method calls on the given zserio object method initialize_offsets().
16
+
15
17
Because serialization to the bit buffer does not have to be byte aligned (divisible by 8), it's possible
16
18
that not all bits of the last byte are used. In this case, only most significant bits of the corresponded
17
19
size are used.
@@ -31,6 +33,7 @@ def serialize(obj: typing.Any) -> BitBuffer:
31
33
"""
32
34
33
35
writer = BitStreamWriter ()
36
+ obj .initialize_offsets (writer .bitposition )
34
37
obj .write (writer )
35
38
36
39
return BitBuffer (writer .byte_array , writer .bitposition )
@@ -63,6 +66,8 @@ def serialize_to_bytes(obj: typing.Any) -> bytes:
63
66
"""
64
67
Serializes generated object to the byte buffer.
65
68
69
+ Before serialization, the method calls on the given zserio object method initialize_offsets().
70
+
66
71
This is a convenient method for users which do not need exact number of bits to which the given object
67
72
will be serialized.
68
73
@@ -117,7 +122,9 @@ def deserialize_bytes(obj_class: typing.Type[typing.Any], buffer: bytes, *args)
117
122
118
123
def serialize_to_file (obj : typing .Any , filename : str ) -> None :
119
124
"""
120
- Serializes generated object to the byte buffer.
125
+ Serializes generated object to the file.
126
+
127
+ Before serialization, the method calls on the given zserio object method initialize_offsets().
121
128
122
129
This is a convenient method for users to easily write given generated object to file.
123
130
@@ -136,6 +143,7 @@ def serialize_to_file(obj: typing.Any, filename: str) -> None:
136
143
"""
137
144
138
145
writer = BitStreamWriter ()
146
+ obj .initialize_offsets (writer .bitposition )
139
147
obj .write (writer )
140
148
writer .to_file (filename )
141
149
0 commit comments