11
11
import tempfile
12
12
from typing import Union
13
13
14
- # pyre-ignore[21]: Could not find module `executorch.exir._serialize._bindings`.
15
- import executorch .exir ._serialize ._bindings as bindings # @manual=//executorch/exir/_serialize:_bindings
16
-
17
14
import pkg_resources
18
15
19
16
from executorch .exir ._serialize ._dataclass import _DataclassEncoder , _json_to_dataclass
17
+
18
+ from executorch .exir ._serialize ._flatbuffer import _flatc_compile , _flatc_decompile
20
19
from executorch .sdk .etdump .schema import ETDump
21
20
from executorch .sdk .etdump .schema_flatcc import ETDumpFlatCC
22
21
@@ -55,8 +54,7 @@ def _convert_to_flatbuffer(etdump_json: str) -> bytes:
55
54
with open (json_path , "wb" ) as json_file :
56
55
json_file .write (etdump_json .encode ("ascii" ))
57
56
58
- # pyre-ignore
59
- bindings .flatc_compile (d , schema_path , json_path )
57
+ _flatc_compile (d , schema_path , json_path )
60
58
output_path = os .path .join (d , "{}.etdp" .format (ETDUMP_SCHEMA_NAME ))
61
59
with open (output_path , "rb" ) as output_file :
62
60
return output_file .read ()
@@ -71,8 +69,7 @@ def _convert_from_flatbuffer(etdump_flatbuffer: bytes) -> bytes:
71
69
bin_path = os .path .join (d , "schema.bin" )
72
70
with open (bin_path , "wb" ) as bin_file :
73
71
bin_file .write (etdump_flatbuffer )
74
- # pyre-ignore
75
- bindings .flatc_decompile (d , schema_path , bin_path )
72
+ _flatc_decompile (d , schema_path , bin_path )
76
73
output_path = os .path .join (d , "schema.json" )
77
74
with open (output_path , "rb" ) as output_file :
78
75
return output_file .read ()
@@ -126,14 +123,13 @@ def _convert_to_flatcc(etdump_json: str) -> bytes:
126
123
with open (json_path , "wb" ) as json_file :
127
124
json_file .write (etdump_json .encode ("ascii" ))
128
125
129
- # pyre-ignore
130
- bindings .flatc_compile (d , schema_path , json_path )
126
+ _flatc_compile (d , schema_path , json_path )
131
127
output_path = os .path .join (d , "{}.etdp" .format (ETDUMP_FLATCC_SCHEMA_NAME ))
132
128
with open (output_path , "rb" ) as output_file :
133
129
return output_file .read ()
134
130
135
131
136
- def _convert_from_flatcc (etdump_flatbuffer : bytes ) -> bytes :
132
+ def _convert_from_flatcc (etdump_flatbuffer : bytes , size_prefixed : bool = True ) -> bytes :
137
133
with tempfile .TemporaryDirectory () as d :
138
134
_write_schema (d , ETDUMP_FLATCC_SCHEMA_NAME )
139
135
_write_schema (d , SCALAR_TYPE_SCHEMA_NAME )
@@ -142,8 +138,10 @@ def _convert_from_flatcc(etdump_flatbuffer: bytes) -> bytes:
142
138
bin_path = os .path .join (d , "schema.bin" )
143
139
with open (bin_path , "wb" ) as bin_file :
144
140
bin_file .write (etdump_flatbuffer )
145
- # pyre-ignore
146
- bindings .flatc_decompile (d , schema_path , bin_path )
141
+ additional_args = []
142
+ if size_prefixed :
143
+ additional_args = ["--size-prefixed" ]
144
+ _flatc_decompile (d , schema_path , bin_path , additional_args )
147
145
output_path = os .path .join (d , "schema.json" )
148
146
with open (output_path , "rb" ) as output_file :
149
147
return output_file .read ()
@@ -163,7 +161,9 @@ def serialize_to_etdump_flatcc(
163
161
return _convert_to_flatcc (_serialize_from_etdump_to_json (etdump ))
164
162
165
163
166
- def deserialize_from_etdump_flatcc (data : bytes ) -> ETDumpFlatCC :
164
+ def deserialize_from_etdump_flatcc (
165
+ data : bytes , size_prefixed : bool = True
166
+ ) -> ETDumpFlatCC :
167
167
"""
168
168
Given an etdump binary blob (constructed using the FlatCC schema) this function will deserialize
169
169
it and return the FlatCC python object representation of etdump.
@@ -172,4 +172,6 @@ def deserialize_from_etdump_flatcc(data: bytes) -> ETDumpFlatCC:
172
172
Returns:
173
173
Deserialized ETDump python object.
174
174
"""
175
- return _deserialize_from_json_to_etdump_flatcc (_convert_from_flatcc (data ))
175
+ return _deserialize_from_json_to_etdump_flatcc (
176
+ _convert_from_flatcc (data , size_prefixed )
177
+ )
0 commit comments