@@ -140,7 +140,6 @@ def _create_schema_topic_if_needed(self) -> None:
140140 return
141141
142142 self .init_admin_client ()
143-
144143 start_time = time .monotonic ()
145144 wait_time = constants .MINUTE
146145 while True :
@@ -210,9 +209,10 @@ def _restore_backup_version_1_single_array(self, fp: IO) -> None:
210209
211210 def _restore_backup_version_2 (self , fp : IO ) -> None :
212211 for line in fp :
213- hex_key , hex_value = line .split ("\t " )
214- key = base64 .b16decode (hex_key ).decode ("utf8" )
215- value = base64 .b16decode (hex_value .strip ()).decode ("utf8" ) # strip to remove the linefeed
212+ hex_key , hex_value = [val .strip () for val in line .split ("\t " )] # strip to remove the linefeed
213+
214+ key = base64 .b16decode (hex_key ).decode ("utf8" ) if hex_key != "null" else hex_key
215+ value = base64 .b16decode (hex_value .strip ()).decode ("utf8" ) if hex_value != "null" else hex_value
216216 self ._handle_restore_message ((key , value ))
217217
218218 def export (self , export_func ) -> None :
@@ -240,9 +240,9 @@ def export(self, export_func) -> None:
240240 LOG .info ("Schema export written to stdout" )
241241 self .close ()
242242
243- def encode_key (self , key : Optional [Union [JsonData , str ]]) -> bytes :
244- if not key :
245- return b""
243+ def encode_key (self , key : Optional [Union [JsonData , str ]]) -> Optional [ bytes ] :
244+ if key == "null" :
245+ return None
246246 if not self .key_formatter :
247247 if isinstance (key , str ):
248248 return key .encode ("utf8" )
@@ -261,12 +261,8 @@ def encode_value(value: Union[JsonData, str]) -> Optional[bytes]:
261261
262262
263263def serialize_record (key_bytes : Optional [bytes ], value_bytes : Optional [bytes ]) -> str :
264- key = b""
265- if key_bytes is not None :
266- key = base64 .b16encode (key_bytes ).decode ("utf8" )
267- value = b""
268- if value_bytes is not None :
269- value = base64 .b16encode (value_bytes ).decode ("utf8" )
264+ key = base64 .b16encode (key_bytes ).decode ("utf8" ) if key_bytes is not None else "null"
265+ value = base64 .b16encode (value_bytes ).decode ("utf8" ) if value_bytes is not None else "null"
270266 return f"{ key } \t { value } \n "
271267
272268
0 commit comments