MCPcopy Create free account
hub / github.com/pytorch/executorch / to_bytes

Method to_bytes

exir/_serialize/_program.py:239–265  ·  view source on GitHub ↗

Returns the binary representation of the extended header. Note that this will ignore self.magic and self.length and will always write the proper magic/length.

(self)

Source from the content-addressed store, hash-verified

237 )
238
239 def to_bytes(self) -> bytes:
240 """Returns the binary representation of the extended header.
241
242 Note that this will ignore self.magic and self.length and will always
243 write the proper magic/length.
244 """
245 data: bytes = (
246 # Extended header magic. This lets consumers detect whether the
247 # header was inserted or not. Always use the proper magic value
248 # (i.e., ignore self.magic) since there's no reason to create an
249 # invalid header.
250 self.EXPECTED_MAGIC
251 # uint32_t: Size of this header. This makes it easier to add new
252 # fields to this header in the future. Always use the proper size
253 # (i.e., ignore self.length) since there's no reason to create an
254 # invalid header.
255 + self.EXPECTED_LENGTH.to_bytes(4, byteorder=_HEADER_BYTEORDER)
256 # uint64_t: Size of the flatbuffer data, including this header.
257 + self.program_size.to_bytes(8, byteorder=_HEADER_BYTEORDER)
258 # uint64_t: Offset to the start of the first segment, or zero if
259 # there are no segments.
260 + self.segment_base_offset.to_bytes(8, byteorder=_HEADER_BYTEORDER)
261 # uint64_t: size of the segment data, or zero if there are no
262 # segments.
263 + self.segment_data_size.to_bytes(8, byteorder=_HEADER_BYTEORDER)
264 )
265 return data
266
267
268def _get_extended_header(program_data: bytes) -> Optional[_ExtendedHeader]:

Callers 4

serialize_pte_binaryFunction · 0.45
test_to_bytesMethod · 0.45

Calls

no outgoing calls

Tested by 2

test_to_bytesMethod · 0.36