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
e78825e7
Commit
e78825e7
authored
Mar 09, 2018
by
desqaz
Committed by
Wouter van Oortmerssen
Mar 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Json : Add --size-prefixed option to flatc (#4645)
to be able to convert to json size prefixed buffers.
parent
cc158e70
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
11 deletions
+28
-11
flatbuffers.h
include/flatbuffers/flatbuffers.h
+5
-4
idl.h
include/flatbuffers/idl.h
+2
-0
flatc.cpp
src/flatc.cpp
+4
-1
idl_gen_text.cpp
src/idl_gen_text.cpp
+3
-2
idl_parser.cpp
src/idl_parser.cpp
+14
-4
No files found.
include/flatbuffers/flatbuffers.h
View file @
e78825e7
...
...
@@ -1664,13 +1664,14 @@ const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
/// This function is UNDEFINED for FlatBuffers whose schema does not include
/// a file_identifier (likely points at padding or the start of a the root
/// vtable).
inline
const
char
*
GetBufferIdentifier
(
const
void
*
buf
)
{
return
reinterpret_cast
<
const
char
*>
(
buf
)
+
sizeof
(
uoffset_t
);
inline
const
char
*
GetBufferIdentifier
(
const
void
*
buf
,
bool
size_prefixed
=
false
)
{
return
reinterpret_cast
<
const
char
*>
(
buf
)
+
((
size_prefixed
)
?
2
*
sizeof
(
uoffset_t
)
:
sizeof
(
uoffset_t
));
}
// Helper to see if the identifier in a buffer has the expected value.
inline
bool
BufferHasIdentifier
(
const
void
*
buf
,
const
char
*
identifier
)
{
return
strncmp
(
GetBufferIdentifier
(
buf
),
identifier
,
inline
bool
BufferHasIdentifier
(
const
void
*
buf
,
const
char
*
identifier
,
bool
size_prefixed
=
false
)
{
return
strncmp
(
GetBufferIdentifier
(
buf
,
size_prefixed
),
identifier
,
FlatBufferBuilder
::
kFileIdentifierLength
)
==
0
;
}
...
...
include/flatbuffers/idl.h
View file @
e78825e7
...
...
@@ -387,6 +387,7 @@ struct IDLOptions {
std
::
string
go_namespace
;
bool
reexport_ts_modules
;
bool
protobuf_ascii_alike
;
bool
size_prefixed
;
// Possible options for the more general generator below.
enum
Language
{
...
...
@@ -442,6 +443,7 @@ struct IDLOptions {
skip_flatbuffers_import
(
false
),
reexport_ts_modules
(
true
),
protobuf_ascii_alike
(
false
),
size_prefixed
(
false
),
lang
(
IDLOptions
::
kJava
),
mini_reflect
(
IDLOptions
::
kNone
),
lang_to_generate
(
0
)
{}
...
...
src/flatc.cpp
View file @
e78825e7
...
...
@@ -100,6 +100,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" (default is
\"
github.com/google/flatbuffers/go
\"
)
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" --size-prefixed Input binaries are size prefixed buffers.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
" --oneof-union Translate .proto oneofs to flatbuffer unions.
\n
"
" --grpc Generate GRPC interfaces for the specified languages
\n
"
...
...
@@ -233,6 +234,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
opts
.
one_file
=
true
;
}
else
if
(
arg
==
"--raw-binary"
)
{
raw_binary
=
true
;
}
else
if
(
arg
==
"--size-prefixed"
)
{
opts
.
size_prefixed
=
true
;
}
else
if
(
arg
==
"--"
)
{
// Separator between text and binary inputs.
binary_files_from
=
filenames
.
size
();
}
else
if
(
arg
==
"--proto"
)
{
...
...
@@ -325,7 +328,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
"
\"
matches the schema, use --raw-binary to read this file"
" anyway."
);
}
else
if
(
!
flatbuffers
::
BufferHasIdentifier
(
contents
.
c_str
(),
parser
->
file_identifier_
.
c_str
()))
{
contents
.
c_str
(),
parser
->
file_identifier_
.
c_str
()
,
opts
.
size_prefixed
))
{
Error
(
"binary
\"
"
+
filename
+
"
\"
does not have expected file_identifier
\"
"
+
parser
->
file_identifier_
+
...
...
src/idl_gen_text.cpp
View file @
e78825e7
...
...
@@ -263,8 +263,9 @@ bool GenerateText(const Parser &parser, const void *flatbuffer,
std
::
string
&
text
=
*
_text
;
assert
(
parser
.
root_struct_def_
);
// call SetRootType()
text
.
reserve
(
1024
);
// Reduce amount of inevitable reallocs.
if
(
!
GenStruct
(
*
parser
.
root_struct_def_
,
GetRoot
<
Table
>
(
flatbuffer
),
0
,
parser
.
opts
,
_text
))
{
auto
root
=
parser
.
opts
.
size_prefixed
?
GetSizePrefixedRoot
<
Table
>
(
flatbuffer
)
:
GetRoot
<
Table
>
(
flatbuffer
);
if
(
!
GenStruct
(
*
parser
.
root_struct_def_
,
root
,
0
,
parser
.
opts
,
_text
))
{
return
false
;
}
text
+=
NewLine
(
parser
.
opts
);
...
...
src/idl_parser.cpp
View file @
e78825e7
...
...
@@ -2412,9 +2412,15 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
}
uoffset_t
toff
;
ECHECK
(
ParseTable
(
*
root_struct_def_
,
nullptr
,
&
toff
));
builder_
.
Finish
(
Offset
<
Table
>
(
toff
),
file_identifier_
.
length
()
?
file_identifier_
.
c_str
()
:
nullptr
);
if
(
opts
.
size_prefixed
)
{
builder_
.
FinishSizePrefixed
(
Offset
<
Table
>
(
toff
),
file_identifier_
.
length
()
?
file_identifier_
.
c_str
()
:
nullptr
);
}
else
{
builder_
.
Finish
(
Offset
<
Table
>
(
toff
),
file_identifier_
.
length
()
?
file_identifier_
.
c_str
()
:
nullptr
);
}
}
else
if
(
IsIdent
(
"enum"
))
{
ECHECK
(
ParseEnum
(
false
,
nullptr
));
}
else
if
(
IsIdent
(
"union"
))
{
...
...
@@ -2521,7 +2527,11 @@ void Parser::Serialize() {
builder_
.
CreateString
(
file_identifier_
),
builder_
.
CreateString
(
file_extension_
),
root_struct_def_
?
root_struct_def_
->
serialized_location
:
0
);
builder_
.
Finish
(
schema_offset
,
reflection
::
SchemaIdentifier
());
if
(
opts
.
size_prefixed
)
{
builder_
.
FinishSizePrefixed
(
schema_offset
,
reflection
::
SchemaIdentifier
());
}
else
{
builder_
.
Finish
(
schema_offset
,
reflection
::
SchemaIdentifier
());
}
}
Offset
<
reflection
::
Object
>
StructDef
::
Serialize
(
FlatBufferBuilder
*
builder
,
...
...
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