Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ build/VS2010/FlatBuffers.opensdf
build/VS2010/ipch/**/*.ipch
*.so
Testing/Temporary
.cproject
.settings/
.project
net/**/obj

node_modules/
2 changes: 2 additions & 0 deletions include/flatbuffers/code_generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class BaseGenerator {

std::string WrapInNameSpace(const Definition &def) const;

std::string GetNameSpace(const Definition &def) const;

const Parser &parser_;
const std::string &path_;
const std::string &file_name_;
Expand Down
9 changes: 7 additions & 2 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ struct IDLOptions {
bool allow_non_utf8;
std::string include_prefix;
bool binary_schema_comments;
bool skip_flatbuffers_import;
std::string go_namespace;
bool reexport_ts_modules;

// Possible options for the more general generator below.
enum Language {
Expand All @@ -371,6 +373,7 @@ struct IDLOptions {
kPhp = 1 << 6,
kJson = 1 << 7,
kBinary = 1 << 8,
kTs = 1 << 9,
kMAX
};

Expand Down Expand Up @@ -400,6 +403,8 @@ struct IDLOptions {
union_value_namespacing(true),
allow_non_utf8(false),
binary_schema_comments(false),
skip_flatbuffers_import(false),
reexport_ts_modules(true),
lang(IDLOptions::kJava),
lang_to_generate(0) {}
};
Expand Down Expand Up @@ -650,7 +655,7 @@ extern bool GenerateCPP(const Parser &parser,
const std::string &path,
const std::string &file_name);

// Generate JavaScript code from the definitions in the Parser object.
// Generate JavaScript or TypeScript code from the definitions in the Parser object.
// See idl_gen_js.
extern std::string GenerateJS(const Parser &parser);
extern bool GenerateJS(const Parser &parser,
Expand Down Expand Up @@ -701,7 +706,7 @@ extern bool GenerateFBS(const Parser &parser,
const std::string &path,
const std::string &file_name);

// Generate a make rule for the generated JavaScript code.
// Generate a make rule for the generated JavaScript or TypeScript code.
// See idl_gen_js.cpp.
extern std::string JSMakeRule(const Parser &parser,
const std::string &path,
Expand Down
29 changes: 29 additions & 0 deletions js/flatbuffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,15 @@ flatbuffers.ByteBuffer.prototype.writeInt16 = function(offset, value) {
this.bytes_[offset + 1] = value >> 8;
};

/**
* @param {number} offset
* @param {number} value
*/
flatbuffers.ByteBuffer.prototype.writeUint16 = function(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
};

/**
* @param {number} offset
* @param {number} value
Expand All @@ -978,6 +987,17 @@ flatbuffers.ByteBuffer.prototype.writeInt32 = function(offset, value) {
this.bytes_[offset + 3] = value >> 24;
};

/**
* @param {number} offset
* @param {number} value
*/
flatbuffers.ByteBuffer.prototype.writeUint32 = function(offset, value) {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
this.bytes_[offset + 2] = value >> 16;
this.bytes_[offset + 3] = value >> 24;
};

/**
* @param {number} offset
* @param {flatbuffers.Long} value
Expand All @@ -987,6 +1007,15 @@ flatbuffers.ByteBuffer.prototype.writeInt64 = function(offset, value) {
this.writeInt32(offset + 4, value.high);
};

/**
* @param {number} offset
* @param {flatbuffers.Long} value
*/
flatbuffers.ByteBuffer.prototype.writeUint64 = function(offset, value) {
this.writeUint32(offset, value.low);
this.writeUint32(offset + 4, value.high);
};

/**
* @param {number} offset
* @param {number} value
Expand Down
14 changes: 14 additions & 0 deletions src/code_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ std::string BaseGenerator::WrapInNameSpace(const Definition &def) const {
return WrapInNameSpace(def.defined_namespace, def.name);
}

std::string BaseGenerator::GetNameSpace(const Definition &def) const {
const Namespace *ns = def.defined_namespace;
if (CurrentNameSpace() == ns) return "";
std::string qualified_name = qualifying_start_;
for (auto it = ns->components.begin(); it != ns->components.end(); ++it) {
qualified_name += *it;
if (std::next(it) != ns->components.end()) {
qualified_name += qualifying_separator_;
}
}

return qualified_name;
}

// Generate a documentation comment, if available.
void GenComment(const std::vector<std::string> &dc, std::string *code_ptr,
const CommentConfig *config, const char *prefix) {
Expand Down
6 changes: 6 additions & 0 deletions src/flatc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
" PATH \n"
" --include-prefix Prefix this path to any generated include statements.\n"
" PATH\n"
" --no-fb-import Don't include flatbuffers import statement for TypeScript.\n"
" --no-ts-reexport Don't re-export imported dependencies for TypeScript.\n"
"FILEs may be schemas, or JSON files (conforming to preceding schema)\n"
"FILEs after the -- must be binary flatbuffer format files.\n"
"Output files are named using the base file name of the input,\n"
Expand Down Expand Up @@ -216,6 +218,10 @@ int FlatCompiler::Compile(int argc, const char** argv) {
grpc_enabled = true;
} else if(arg == "--bfbs-comments") {
opts.binary_schema_comments = true;
} else if(arg == "--no-fb-import") {
opts.skip_flatbuffers_import = true;
} else if(arg == "--no-ts-reexport") {
opts.reexport_ts_modules = false;
} else {
for (size_t i = 0; i < params_.num_generators; ++i) {
if (arg == params_.generators[i].generator_opt_long ||
Expand Down
5 changes: 5 additions & 0 deletions src/flatc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ int main(int argc, const char *argv[]) {
flatbuffers::IDLOptions::kJs,
"Generate JavaScript code for tables/structs",
flatbuffers::JSMakeRule },
{ flatbuffers::GenerateJS, "-T", "--ts", "TypeScript",
nullptr,
flatbuffers::IDLOptions::kTs,
"Generate TypeScript code for tables/structs",
flatbuffers::JSMakeRule },
{ flatbuffers::GenerateGeneral, "-n", "--csharp", "C#",
nullptr,
flatbuffers::IDLOptions::kCSharp,
Expand Down
Loading