Copy documentation into the config definitions.

This commit is contained in:
dg
2023-05-07 16:48:17 +00:00
parent de59e781b5
commit 2fe0cec04a
42 changed files with 1558 additions and 350 deletions

View File

@@ -2,12 +2,72 @@
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <fstream>
#include "fmt/format.h"
#include <fmt/format.h>
#include "tests/testproto.pb.h"
#include "lib/config.pb.h"
#include <sstream>
#include <locale>
#define STRINGIFY(s) #s
static uint32_t readu8(std::string::iterator& it, std::string::iterator end)
{
int len;
uint32_t c = *it++;
if (c < 0x80)
{
/* Do nothing! */
len = 0;
}
else if (c < 0xc0)
{
/* Invalid character */
c = -1;
len = 0;
}
else if (c < 0xe0)
{
/* One trailing byte */
c &= 0x1f;
len = 1;
}
else if (c < 0xf0)
{
/* Two trailing bytes */
c &= 0x0f;
len = 2;
}
else if (c < 0xf8)
{
/* Three trailing bytes */
c &= 0x07;
len = 3;
}
else if (c < 0xfc)
{
/* Four trailing bytes */
c &= 0x03;
len = 4;
}
else
{
/* Five trailing bytes */
c &= 0x01;
len = 5;
}
while (len)
{
if (it == end)
break;
uint8_t d = *it++;
c <<= 6;
c += d & 0x3f;
}
return c;
}
int main(int argc, const char* argv[])
{
PROTO message;
@@ -19,10 +79,37 @@ int main(int argc, const char* argv[])
exit(1);
}
google::protobuf::io::IstreamInputStream istream(&input);
if (!google::protobuf::TextFormat::Parse(&istream, &message))
std::stringstream ss;
std::string s;
while (std::getline(input, s, '\n'))
{
if (s == "<<<")
{
while (std::getline(input, s, '\n'))
{
if (s == ">>>")
break;
ss << '"';
auto it = s.begin();
for (;;)
{
uint32_t u = readu8(it, s.end());
if (!u)
break;
ss << fmt::format("\\u000{:02x}", u);
}
ss << "\\n\"\n";
}
}
else
ss << s << '\n';
}
if (!google::protobuf::TextFormat::ParseFromString(ss.str(), &message))
{
fprintf(stderr, "cannot parse text proto");
fprintf(stderr, "cannot parse text proto: %s\n", argv[1]);
exit(1);
}