Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
b8f5f844
Commit
b8f5f844
authored
Mar 20, 2017
by
Flier Lu
Committed by
Wouter van Oortmerssen
Mar 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add command line argument for go namespace (#4222)
parent
f2071e4f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
6 deletions
+21
-6
idl.h
include/flatbuffers/idl.h
+1
-0
flatc.cpp
src/flatc.cpp
+4
-0
idl_gen_go.cpp
src/idl_gen_go.cpp
+16
-6
No files found.
include/flatbuffers/idl.h
View file @
b8f5f844
...
...
@@ -358,6 +358,7 @@ struct IDLOptions {
bool
allow_non_utf8
;
std
::
string
include_prefix
;
bool
binary_schema_comments
;
std
::
string
go_namespace
;
// Possible options for the more general generator below.
enum
Language
{
...
...
src/flatc.cpp
View file @
b8f5f844
...
...
@@ -90,6 +90,7 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
" T::c_str() and T::length() must be supported
\n
"
" --no-js-exports Removes Node.js style export lines in JS.
\n
"
" --goog-js-export Uses goog.exports* for closure compiler exporting in JS.
\n
"
" --go-namespace Generate the overrided namespace in Golang.
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
...
...
@@ -160,6 +161,9 @@ int FlatCompiler::Compile(int argc, const char** argv) {
opts
.
skip_js_exports
=
true
;
}
else
if
(
arg
==
"--goog-js-export"
)
{
opts
.
use_goog_js_export_format
=
true
;
}
else
if
(
arg
==
"--go-namespace"
)
{
if
(
++
argi
>=
argc
)
Error
(
"missing golang namespace"
+
arg
,
true
);
opts
.
go_namespace
=
argv
[
argi
];
}
else
if
(
arg
==
"--defaults-json"
)
{
opts
.
output_default_scalars_in_json
=
true
;
}
else
if
(
arg
==
"--unknown-json"
)
{
...
...
src/idl_gen_go.cpp
View file @
b8f5f844
...
...
@@ -17,6 +17,7 @@
// independent from idl_parser, since this code is not needed for most clients
#include <string>
#include <sstream>
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
...
...
@@ -740,9 +741,15 @@ static void GenStructBuilder(const StructDef &struct_def,
class
GoGenerator
:
public
BaseGenerator
{
public
:
GoGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
/* not used*/
,
""
/* not used */
){};
const
std
::
string
&
file_name
,
const
std
::
string
&
go_namespace
)
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
/* not used*/
,
""
/* not used */
)
{
std
::
istringstream
iss
(
go_namespace
);
std
::
string
component
;
while
(
std
::
getline
(
iss
,
component
,
'.'
))
{
go_namespace_
.
components
.
push_back
(
component
);
}
}
bool
generate
()
{
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
...
...
@@ -780,19 +787,22 @@ class GoGenerator : public BaseGenerator {
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
Namespace
&
ns
=
go_namespace_
.
components
.
empty
()
?
*
def
.
defined_namespace
:
go_namespace_
;
std
::
string
code
=
""
;
BeginFile
(
LastNamespacePart
(
*
def
.
defined_namespace
),
needs_imports
,
&
code
);
BeginFile
(
LastNamespacePart
(
ns
),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
NamespaceDir
(
*
def
.
defined_namespace
)
+
def
.
name
+
".go"
;
NamespaceDir
(
ns
)
+
def
.
name
+
".go"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
Namespace
go_namespace_
;
};
}
// namespace go
bool
GenerateGo
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
{
go
::
GoGenerator
generator
(
parser
,
path
,
file_name
);
go
::
GoGenerator
generator
(
parser
,
path
,
file_name
,
parser
.
opts
.
go_namespace
);
return
generator
.
generate
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment