aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/flatbuffers/src/idl_gen_binary.cpp
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2023-09-06 12:00:15 +0300
committerthegeorg <thegeorg@yandex-team.com>2023-09-06 12:35:38 +0300
commit23225dd61414039ed8f923ca08c96efecc8894eb (patch)
treec35c77c85c0bca5f54ba4ceb397f442d9adfdf97 /contrib/libs/flatbuffers/src/idl_gen_binary.cpp
parentee92fee2d806dd933291766e2f42948c481b6398 (diff)
downloadydb-23225dd61414039ed8f923ca08c96efecc8894eb.tar.gz
Update contrib/libs/flatbuffers to 23.5.26
Diffstat (limited to 'contrib/libs/flatbuffers/src/idl_gen_binary.cpp')
-rw-r--r--contrib/libs/flatbuffers/src/idl_gen_binary.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/contrib/libs/flatbuffers/src/idl_gen_binary.cpp b/contrib/libs/flatbuffers/src/idl_gen_binary.cpp
index feb4e2f55e..7ed0a99ca6 100644
--- a/contrib/libs/flatbuffers/src/idl_gen_binary.cpp
+++ b/contrib/libs/flatbuffers/src/idl_gen_binary.cpp
@@ -31,9 +31,46 @@
#include "flatbuffers/util.h"
namespace flatbuffers {
-
namespace {
+static std::string BinaryFileName(const Parser &parser, const std::string &path,
+ const std::string &file_name) {
+ auto ext = parser.file_extension_.length() ? parser.file_extension_ : "bin";
+ return path + file_name + "." + ext;
+}
+
+static bool GenerateBinary(const Parser &parser, const std::string &path,
+ const std::string &file_name) {
+ if (parser.opts.use_flexbuffers) {
+ auto data_vec = parser.flex_builder_.GetBuffer();
+ auto data_ptr = reinterpret_cast<char *>(data(data_vec));
+ return !parser.flex_builder_.GetSize() ||
+ flatbuffers::SaveFile(
+ BinaryFileName(parser, path, file_name).c_str(), data_ptr,
+ parser.flex_builder_.GetSize(), true);
+ }
+ return !parser.builder_.GetSize() ||
+ flatbuffers::SaveFile(
+ BinaryFileName(parser, path, file_name).c_str(),
+ reinterpret_cast<char *>(parser.builder_.GetBufferPointer()),
+ parser.builder_.GetSize(), true);
+}
+
+static std::string BinaryMakeRule(const Parser &parser, const std::string &path,
+ const std::string &file_name) {
+ if (!parser.builder_.GetSize()) return "";
+ std::string filebase =
+ flatbuffers::StripPath(flatbuffers::StripExtension(file_name));
+ std::string make_rule =
+ BinaryFileName(parser, path, filebase) + ": " + file_name;
+ auto included_files =
+ parser.GetIncludedFilesRecursive(parser.root_struct_def_->file);
+ for (auto it = included_files.begin(); it != included_files.end(); ++it) {
+ make_rule += " " + *it;
+ }
+ return make_rule;
+}
+
class BinaryCodeGenerator : public CodeGenerator {
public:
Status GenerateCode(const Parser &parser, const std::string &path,
@@ -44,9 +81,8 @@ class BinaryCodeGenerator : public CodeGenerator {
// Generate code from the provided `buffer` of given `length`. The buffer is a
// serialized reflection.fbs.
- Status GenerateCode(const uint8_t *buffer, int64_t length) override {
- (void)buffer;
- (void)length;
+ Status GenerateCode(const uint8_t *, int64_t,
+ const CodeGenOptions &) override {
return Status::NOT_IMPLEMENTED;
}