| 173 | } |
| 174 | |
| 175 | static af_array readArrayV1(const char *filename, const unsigned index) { |
| 176 | char version = 0; |
| 177 | int n_arrays = 0; |
| 178 | |
| 179 | std::fstream fs(filename, std::fstream::in | std::fstream::binary); |
| 180 | |
| 181 | // Throw exception if file is not open |
| 182 | if (!fs.is_open()) { AF_ERROR("File failed to open", AF_ERR_ARG); } |
| 183 | |
| 184 | if (fs.peek() == std::fstream::traits_type::eof()) { |
| 185 | AF_ERROR("File is empty", AF_ERR_ARG); |
| 186 | } |
| 187 | |
| 188 | fs.read(&version, sizeof(char)); |
| 189 | fs.read(reinterpret_cast<char *>(&n_arrays), sizeof(int)); |
| 190 | |
| 191 | AF_ASSERT((int)index < n_arrays, "Index out of bounds"); |
| 192 | |
| 193 | for (unsigned i = 0; i < index; i++) { |
| 194 | // (int ) Length of the key |
| 195 | // (cstring) Key |
| 196 | // (intl ) Offset bytes to next array (type + dims + data) |
| 197 | // (char ) Type |
| 198 | // (intl ) dim4 (x 4) |
| 199 | // (T ) data (x elements) |
| 200 | int klen = -1; |
| 201 | fs.read(reinterpret_cast<char *>(&klen), sizeof(int)); |
| 202 | |
| 203 | // char* key = new char[klen]; |
| 204 | // fs.read((char*)&key, klen * sizeof(char)); |
| 205 | |
| 206 | // Skip the array name tag |
| 207 | fs.seekg(klen, std::ios_base::cur); |
| 208 | |
| 209 | // Read data offset |
| 210 | intl offset = -1; |
| 211 | fs.read(reinterpret_cast<char *>(&offset), sizeof(intl)); |
| 212 | |
| 213 | // Skip data |
| 214 | fs.seekg(offset, std::ios_base::cur); |
| 215 | } |
| 216 | |
| 217 | int klen = -1; |
| 218 | fs.read(reinterpret_cast<char *>(&klen), sizeof(int)); |
| 219 | |
| 220 | // char* key = new char[klen]; |
| 221 | // fs.read((char*)&key, klen * sizeof(char)); |
| 222 | |
| 223 | // Skip the array name tag |
| 224 | fs.seekg(klen, std::ios_base::cur); |
| 225 | |
| 226 | // Read data offset |
| 227 | intl offset = -1; |
| 228 | fs.read(reinterpret_cast<char *>(&offset), sizeof(intl)); |
| 229 | |
| 230 | // Read type and dims |
| 231 | char type_ = -1; |
| 232 | fs.read(&type_, sizeof(char)); |
no test coverage detected