MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / scHttpFormatChunkHeader

Function scHttpFormatChunkHeader

Libraries/Http/HttpConnection.cpp:66–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66static SC::Result scHttpFormatChunkHeader(uint64_t size, SC::Span<char> storage, SC::StringSpan& header)
67{
68 static constexpr const char HexDigits[] = "0123456789ABCDEF";
69
70 SC_TRY_MSG(storage.sizeInBytes() >= 4, "HttpOutgoingMessage chunk header buffer too small");
71
72 char reversed[16];
73 size_t numDigits = 0;
74 do
75 {
76 reversed[numDigits++] = HexDigits[size & 0xF];
77 size >>= 4;
78 } while (size > 0 and numDigits < sizeof(reversed));
79
80 SC_TRY_MSG(size == 0, "HttpOutgoingMessage chunk size overflow");
81 SC_TRY_MSG(numDigits + 2 <= storage.sizeInBytes(), "HttpOutgoingMessage chunk header buffer too small");
82
83 for (size_t idx = 0; idx < numDigits; ++idx)
84 {
85 storage[idx] = reversed[numDigits - idx - 1];
86 }
87 storage[numDigits + 0] = '\r';
88 storage[numDigits + 1] = '\n';
89 header = SC::StringSpan({storage.data(), numDigits + 2}, false, SC::StringEncoding::Ascii);
90 return SC::Result(true);
91}
92
93static bool scHttpMultipartBoundaryIsSafe(SC::StringSpan value)
94{

Callers 1

asyncWriteMethod · 0.85

Calls 4

StringSpanFunction · 0.85
ResultClass · 0.50
sizeInBytesMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected