MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadEncodedBlock

Function ReadEncodedBlock

IO/Legacy/vtkLegacyStatisticalModelReader.cxx:28–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27template <typename LineType>
28bool 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

Callers 1

ReadMeshSimpleMethod · 0.85

Calls 8

ReadStringMethod · 0.80
LowerCaseMethod · 0.45
ReadMethod · 0.45
ReadLineMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected