MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ParseHeader

Function ParseHeader

dali/operators/decoder/numpy.cc:36–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36numpy::HeaderData ParseHeader(const std::string_view data) {
37 const auto numpy_magic = "\x93NUMPY";
38 if (data.size() < 10 || data.substr(0, 6) != numpy_magic) {
39 DALI_FAIL("Got bad magic string for numpy header ",
40 to_hex_string(data.substr(0, std::min(6UL, data.size()))), ", expected ",
41 to_hex_string(numpy_magic));
42 } else if (data[6] != 1) {
43 DALI_FAIL("Unsupported numpy file version. Only major version 1 is supported.");
44 }
45
46 uint16_t header_len = 0;
47 std::memcpy(&header_len, &data[8], 2);
48 if (header_len + 10UL > data.size()) {
49 DALI_FAIL("Header length exceeds input size.");
50 }
51
52 numpy::HeaderData header;
53 numpy::ParseHeaderContents(header, data.substr(10, header_len));
54 header.data_offset = 10 + header_len;
55
56 const auto expected_size = header.data_offset + header.nbytes();
57 if (expected_size != data.size()) {
58 DALI_FAIL("Expected data numpy size ", expected_size, " bytes does not match the actual size ",
59 data.size(), " bytes.");
60 }
61
62 return header;
63}
64
65bool NumpyDecoder::SetupImpl(std::vector<OutputDesc> &output_desc, const Workspace &ws) {
66 const auto &input = ws.Input<CPUBackend>(0);

Callers 7

SetupImplMethod · 0.70
ReadSampleMethod · 0.50
ReadSampleMethod · 0.50
ReadHeaderMethod · 0.50
TarArchiveMethod · 0.50
NextFileMethod · 0.50
SeekArchiveMethod · 0.50

Calls 5

to_hex_stringFunction · 0.85
ParseHeaderContentsFunction · 0.85
minFunction · 0.50
sizeMethod · 0.45
nbytesMethod · 0.45

Tested by

no test coverage detected