Пример #1
0
  // Save out the generated code for a Go Table type.
  bool SaveType(const Definition &def, const std::string &classcode,
                bool needs_imports) {
    if (!classcode.length()) return true;

    std::string code = "";
    BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
    code += classcode;
    std::string filename =
        NamespaceDir(*def.defined_namespace) + def.name + ".go";
    return SaveFile(filename.c_str(), code, false);
  }
 bool generate() {
   FlatBufFile file(parser_, file_name_, FlatBufFile::kLanguageGo);
   grpc_go_generator::Parameters p;
   p.custom_method_io_type = "flatbuffers.Builder";
   for (int i = 0; i < file.service_count(); i++) {
     auto service = file.service(i);
     const Definition *def = parser_.services_.vec[i];
     p.package_name = LastNamespacePart(*(def->defined_namespace));
     std::string output = grpc_go_generator::GenerateServiceSource(&file, service.get(), &p);
     std::string filename = NamespaceDir(*def->defined_namespace) + def->name + "_grpc.go";
     if (!flatbuffers::SaveFile(filename.c_str(), output, false))
       return false;
   }
   return true;
 }
Пример #3
0
  // Save out the generated code for a Python Table type.
  bool SaveType(const Definition &def, const std::string &classcode,
                bool needs_imports) {
    if (!classcode.length()) return true;

    std::string namespace_dir = path_;
    auto &namespaces = parser_.namespaces_.back()->components;
    for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
      if (it != namespaces.begin()) namespace_dir += kPathSeparator;
      namespace_dir += *it;
      std::string init_py_filename = namespace_dir + "/__init__.py";
      SaveFile(init_py_filename.c_str(), "", false);
    }

    std::string code = "";
    BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
    code += classcode;
    std::string filename = NamespaceDir(*def.defined_namespace) +
                           def.name + ".py";
    return SaveFile(filename.c_str(), code, false);
  }