Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extension/flat_tensor/serialize/flat_tensor_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ uint64_t GetUInt64LE(const uint8_t* data) {
if (size < FlatTensorHeader::kNumHeadBytes) {
return Error::InvalidArgument;
}
const uint8_t* header = reinterpret_cast<const uint8_t*>(data);
const uint8_t* header =
reinterpret_cast<const uint8_t*>(data) + kHeaderOffset;

// Check magic bytes.
if (std::memcmp(
Expand Down
6 changes: 6 additions & 0 deletions extension/flat_tensor/serialize/flat_tensor_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ struct FlatTensorHeader {
*/
static constexpr size_t kNumHeadBytes = 64;

/**
* The offset into the serialized FlatTensor data where the FlatTensor
* header should begin.
*/
static constexpr size_t kHeaderOffset = 8;

/**
* The magic bytes that identify the header. This should be in sync with
* the magic in executorch/extension/flat_tensor/serialize/serialize.py
Expand Down
2 changes: 1 addition & 1 deletion extension/flat_tensor/test/flat_tensor_header_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::vector<uint8_t> CreateExampleFlatTensorHeader() {
memset(ret.data(), 0x55, ret.size());
// Copy the example header into the right offset.
memcpy(
ret.data(),
ret.data() + FlatTensorHeader::kHeaderOffset,
kExampleHeaderData,
sizeof(kExampleHeaderData));
return ret;
Expand Down
Loading