Better support for repeated fields in the config language. Add a helper

for showing all config fields in a proto.
This commit is contained in:
David Given
2025-08-10 22:22:58 +01:00
parent 8f233f55e9
commit df4d27eefe
11 changed files with 290 additions and 133 deletions

View File

@@ -5,13 +5,14 @@ encoders = {}
@Rule
def protoencode_single(self, name, srcs: Targets, proto, symbol):
def protoencode_single(self, name, srcs: Targets, proto, include, symbol):
if proto not in encoders:
r = cxxprogram(
name="protoencode_" + proto,
srcs=["scripts/protoencode.cc"],
cflags=["-DPROTO=" + proto],
cflags=["-DPROTO=" + proto, "-DINCLUDE="+include],
deps=[
"lib/core",
"lib/config+proto_lib",
"lib/fluxsource+proto_lib",
"lib/fluxsink+proto_lib",
@@ -41,12 +42,13 @@ def protoencode_single(self, name, srcs: Targets, proto, symbol):
@Rule
def protoencode(self, name, proto, srcs: TargetsMap, symbol):
def protoencode(self, name, proto, include,srcs: TargetsMap, symbol):
encoded = [
protoencode_single(
name=f"{k}_cc",
srcs=[v],
proto=proto,
include=include,
symbol=f"{symbol}_{k}_pb",
)
for k, v in srcs.items()

View File

@@ -3,12 +3,13 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <fstream>
#include "fmt/format.h"
#include "lib/core/globals.h"
#include "tests/testproto.pb.h"
#include "lib/config/config.pb.h"
#include <sstream>
#include <locale>
#define STRINGIFY(s) #s
const std::string protoname = STRINGIFY(PROTO);
static uint32_t readu8(std::string::iterator& it, std::string::iterator end)
{
@@ -125,6 +126,7 @@ int main(int argc, const char* argv[])
output << "#include \"lib/core/globals.h\"\n"
<< "#include \"lib/config/proto.h\"\n"
<< "#include \"" STRINGIFY(INCLUDE) "\"\n"
<< "#include <string_view>\n"
<< "static const uint8_t " << name << "_rawData[] = {";
@@ -143,11 +145,11 @@ int main(int argc, const char* argv[])
output << "\n};\n";
output << "extern const std::string_view " << name << "_data;\n";
output << "const std::string_view " << name
<< "_data = std::string_view((const char*)" << name << "_rawData, " << data.size()
<< ");\n";
output << "extern const ConfigProto " << name << ";\n";
output << "const ConfigProto " << name << " = parseConfigBytes("
<< argv[3] << "_data);\n";
<< "_data = std::string_view((const char*)" << name << "_rawData, "
<< data.size() << ");\n";
output << "extern const " << protoname << " " << name << ";\n";
output << "const " << protoname << " " << name << " = parseProtoBytes<"
<< protoname << ">(" << argv[3] << "_data);\n";
return 0;
}