| 26 | |
| 27 | template <typename LineType> |
| 28 | bool ReadEncodedBlock(const char* blockName, std::string& decodedData, |
| 29 | vtkLegacyStatisticalModelReader* self, LineType& line) |
| 30 | { |
| 31 | if (!self->ReadString(line) || strncmp(self->LowerCase(line), blockName, strlen(blockName)) != 0) |
| 32 | { |
| 33 | vtkErrorWithObjectMacro(self, << "Cannot read " << blockName << " \"" << line << "\"!"); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | vtkIdType encodedContentLength; |
| 38 | vtkIdType decodedContentLength; |
| 39 | if (!self->Read(&encodedContentLength) || !self->Read(&decodedContentLength)) |
| 40 | { |
| 41 | vtkErrorWithObjectMacro(self, << "Cannot read content length: " << line); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | // Now read encoded data, beginning with a newline. |
| 46 | if (!self->ReadLine(line)) |
| 47 | { |
| 48 | vtkErrorWithObjectMacro(self, << "Cannot read end-of-line past content length: " << line); |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | if (encodedContentLength > 0) |
| 53 | { |
| 54 | // Use 'char' instead of 'uint8_t' to avoid the following clang >= 19 error: |
| 55 | // "implicit instantiation of undefined template 'std::char_traits<unsigned char>'" |
| 56 | std::vector<char> raw; |
| 57 | raw.resize(encodedContentLength); |
| 58 | if (!self->GetIStream()->read(raw.data(), static_cast<std::streamsize>(encodedContentLength))) |
| 59 | { |
| 60 | vtkErrorWithObjectMacro(self, << "Cannot read encoded " << blockName << " content."); |
| 61 | return false; |
| 62 | } |
| 63 | decodedData.resize(decodedContentLength, '\0'); |
| 64 | auto decodedLength = static_cast<vtkIdType>(vtkBase64Utilities::DecodeSafely( |
| 65 | reinterpret_cast<const unsigned char*>(raw.data()), encodedContentLength, |
| 66 | reinterpret_cast<unsigned char*>(decodedData.data()), decodedData.size())); |
| 67 | decodedData.resize(decodedLength < decodedContentLength ? decodedLength : decodedContentLength); |
| 68 | } |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | } // anonymous namespace |
| 73 |
no test coverage detected