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
c1b0abe0
Commit
c1b0abe0
authored
Aug 25, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
b04e21db
ef67a584
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
364 additions
and
134 deletions
+364
-134
PackageDebian.cmake
CMake/PackageDebian.cmake
+57
-0
CMakeLists.txt
CMakeLists.txt
+5
-0
cpp_generator.cc
grpc/src/compiler/cpp_generator.cc
+27
-26
cpp_generator.h
grpc/src/compiler/cpp_generator.h
+9
-72
schema_interface.h
grpc/src/compiler/schema_interface.h
+108
-0
flatbuffers.h
include/flatbuffers/flatbuffers.h
+0
-5
idl.h
include/flatbuffers/idl.h
+3
-1
FlatBufferBuilder.java
java/com/google/flatbuffers/FlatBufferBuilder.java
+36
-0
ByteBuffer.cs
net/FlatBuffers/ByteBuffer.cs
+17
-5
sample_text.cpp
samples/sample_text.cpp
+4
-1
idl_gen_go.cpp
src/idl_gen_go.cpp
+0
-3
idl_gen_grpc.cpp
src/idl_gen_grpc.cpp
+10
-10
idl_gen_text.cpp
src/idl_gen_text.cpp
+0
-0
ByteBufferTests.cs
tests/FlatBuffers.Test/ByteBufferTests.cs
+18
-0
JavaTest.java
tests/JavaTest.java
+42
-0
Monster.go
tests/MyGame/Example/Monster.go
+0
-6
test.cpp
tests/test.cpp
+28
-5
No files found.
CMake/PackageDebian.cmake
0 → 100644
View file @
c1b0abe0
# ------------------- Debianization ---------------------
if
(
UNIX
)
# Set build environment
SET
(
CPACK_GENERATOR
"TGZ;DEB"
)
SET
(
CPACK_SOURCE_TGZ
"ON"
)
# Common package information
SET
(
CPACK_PACKAGE_DESCRIPTION_SUMMARY
"FlatBuffers is an efficient cross platform serialization library for C++, with support for Java, C# and Go. It was created at Google specifically for game development and other performance-critical applications."
)
SET
(
CPACK_DEBIAN_PACKAGE_HOMEPAGE
"https://github.com/google/flatbuffers"
)
SET
(
CPACK_DEBIAN_PACKAGE_MAINTAINER
"Vitaly Isaev <vitalyisaev2@gmail.com>"
)
# Derive package version from git
EXECUTE_PROCESS
(
COMMAND date +%Y%m%d
OUTPUT_VARIABLE DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS
(
COMMAND git describe
WORKING_DIRECTORY
${
CMAKE_SOURCE_DIR
}
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string
(
REGEX REPLACE
"^v([0-9]+)
\\
..*"
"
\\
1"
VERSION_MAJOR
"
${
GIT_DESCRIBE_DIRTY
}
"
)
string
(
REGEX REPLACE
"^v[0-9]+
\\
.([0-9]+).*"
"
\\
1"
VERSION_MINOR
"
${
GIT_DESCRIBE_DIRTY
}
"
)
string
(
REGEX REPLACE
"^v[0-9]+
\\
.[0-9]+
\\
.([0-9]+).*"
"
\\
1"
VERSION_PATCH
"
${
GIT_DESCRIBE_DIRTY
}
"
)
string
(
REGEX REPLACE
"^v[0-9]+
\\
.[0-9]+
\\
.[0-9]+
\\
-([0-9]+).*"
"
\\
1"
VERSION_COMMIT
"
${
GIT_DESCRIBE_DIRTY
}
"
)
SET
(
CPACK_PACKAGE_VERSION_MAJOR
${
VERSION_MAJOR
}
)
SET
(
CPACK_PACKAGE_VERSION_MINOR
${
VERSION_MINOR
}
)
SET
(
CPACK_PACKAGE_VERSION_PATCH
${
VERSION_PATCH
}
)
SET
(
CPACK_PACKAGE_VERSION
"
${
VERSION_MAJOR
}
.
${
VERSION_MINOR
}
.
${
VERSION_PATCH
}
-
${
VERSION_COMMIT
}
"
)
SET
(
CPACK_DEBIAN_PACKAGE_VERSION
"
${
CPACK_PACKAGE_VERSION
}
"
)
# Derive architecture
IF
(
NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE
)
FIND_PROGRAM
(
DPKG_CMD dpkg
)
IF
(
NOT DPKG_CMD
)
MESSAGE
(
STATUS
"Can not find dpkg in your path, default to i386."
)
SET
(
CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386
)
ENDIF
(
NOT DPKG_CMD
)
EXECUTE_PROCESS
(
COMMAND
"
${
DPKG_CMD
}
"
--print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ENDIF
(
NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE
)
# Package name
SET
(
CPACK_DEBIAN_PACKAGE_NAME
"flatbuffers"
)
SET
(
CPACK_RESOURCE_FILE_LICENSE
${
CMAKE_SOURCE_DIR
}
/LICENSE.txt
)
SET
(
CPACK_PACKAGE_FILE_NAME
"
${
CPACK_DEBIAN_PACKAGE_NAME
}
_
${
CPACK_DEBIAN_PACKAGE_VERSION
}
_
${
CPACK_DEBIAN_PACKAGE_ARCHITECTURE
}
"
)
endif
(
UNIX
)
INCLUDE
(
CPack
)
CMakeLists.txt
View file @
c1b0abe0
...
...
@@ -44,6 +44,7 @@ set(FlatBuffers_Compiler_SRCS
src/idl_gen_fbs.cpp
src/idl_gen_grpc.cpp
src/flatc.cpp
grpc/src/compiler/schema_interface.h
grpc/src/compiler/cpp_generator.h
grpc/src/compiler/cpp_generator.cc
)
...
...
@@ -222,3 +223,7 @@ if(FLATBUFFERS_BUILD_TESTS)
endif
()
include
(
CMake/BuildFlatBuffers.cmake
)
if
(
FLATBUFFERS_PACKAGE_DEBIAN
)
include
(
CMake/PackageDebian.cmake
)
endif
()
grpc/src/compiler/cpp_generator.cc
View file @
c1b0abe0
...
...
@@ -67,7 +67,8 @@ grpc::string FilenameIdentifier(const grpc::string &filename) {
template
<
class
T
,
size_t
N
>
T
*
array_end
(
T
(
&
array
)[
N
])
{
return
array
+
N
;
}
void
PrintIncludes
(
Printer
*
printer
,
const
std
::
vector
<
grpc
::
string
>&
headers
,
const
Parameters
&
params
)
{
void
PrintIncludes
(
grpc_generator
::
Printer
*
printer
,
const
std
::
vector
<
grpc
::
string
>&
headers
,
const
Parameters
&
params
)
{
std
::
map
<
grpc
::
string
,
grpc
::
string
>
vars
;
vars
[
"l"
]
=
params
.
use_system_headers
?
'<'
:
'"'
;
...
...
@@ -86,7 +87,7 @@ void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, c
}
}
grpc
::
string
GetHeaderPrologue
(
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
GetHeaderPrologue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
output
;
{
// Scope the output stream so it closes and finalizes output to the string.
...
...
@@ -111,7 +112,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) {
return
output
;
}
grpc
::
string
GetHeaderIncludes
(
File
*
file
,
grpc
::
string
GetHeaderIncludes
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
)
{
grpc
::
string
output
;
{
...
...
@@ -154,7 +155,7 @@ grpc::string GetHeaderIncludes(File *file,
}
void
PrintHeaderClientMethodInterfaces
(
Printer
*
printer
,
const
Method
*
method
,
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
,
bool
is_public
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -303,8 +304,8 @@ void PrintHeaderClientMethodInterfaces(
}
}
void
PrintHeaderClientMethod
(
Printer
*
printer
,
const
Method
*
method
,
void
PrintHeaderClientMethod
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
,
bool
is_public
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
...
...
@@ -445,13 +446,13 @@ void PrintHeaderClientMethod(Printer *printer,
}
}
void
PrintHeaderClientMethodData
(
Printer
*
printer
,
const
Method
*
method
,
void
PrintHeaderClientMethodData
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
printer
->
Print
(
*
vars
,
"const ::grpc::RpcMethod rpcmethod_$Method$_;
\n
"
);
}
void
PrintHeaderServerMethodSync
(
Printer
*
printer
,
const
Method
*
method
,
void
PrintHeaderServerMethodSync
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -483,8 +484,8 @@ void PrintHeaderServerMethodSync(Printer *printer, const Method *method,
}
void
PrintHeaderServerMethodAsync
(
Printer
*
printer
,
const
Method
*
method
,
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -599,8 +600,8 @@ void PrintHeaderServerMethodAsync(
}
void
PrintHeaderServerMethodGeneric
(
Printer
*
printer
,
const
Method
*
method
,
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -669,8 +670,8 @@ void PrintHeaderServerMethodGeneric(
printer
->
Print
(
*
vars
,
"};
\n
"
);
}
void
PrintHeaderService
(
Printer
*
printer
,
const
Service
*
service
,
void
PrintHeaderService
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Service
*
service
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Service"
]
=
service
->
name
();
...
...
@@ -764,7 +765,7 @@ void PrintHeaderService(Printer *printer,
printer
->
Print
(
"};
\n
"
);
}
grpc
::
string
GetHeaderServices
(
File
*
file
,
grpc
::
string
GetHeaderServices
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
)
{
grpc
::
string
output
;
{
...
...
@@ -795,7 +796,7 @@ grpc::string GetHeaderServices(File *file,
return
output
;
}
grpc
::
string
GetHeaderEpilogue
(
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
GetHeaderEpilogue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
output
;
{
// Scope the output stream so it closes and finalizes output to the string.
...
...
@@ -821,7 +822,7 @@ grpc::string GetHeaderEpilogue(File *file, const Parameters & /*params*/) {
return
output
;
}
grpc
::
string
GetSourcePrologue
(
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
GetSourcePrologue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
output
;
{
// Scope the output stream so it closes and finalizes output to the string.
...
...
@@ -845,7 +846,7 @@ grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) {
return
output
;
}
grpc
::
string
GetSourceIncludes
(
File
*
file
,
grpc
::
string
GetSourceIncludes
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
)
{
grpc
::
string
output
;
{
...
...
@@ -880,8 +881,8 @@ grpc::string GetSourceIncludes(File *file,
return
output
;
}
void
PrintSourceClientMethod
(
Printer
*
printer
,
const
Method
*
method
,
void
PrintSourceClientMethod
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -981,8 +982,8 @@ void PrintSourceClientMethod(Printer *printer,
}
}
void
PrintSourceServerMethod
(
Printer
*
printer
,
const
Method
*
method
,
void
PrintSourceServerMethod
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Method
*
method
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Method"
]
=
method
->
name
();
(
*
vars
)[
"Request"
]
=
method
->
input_type_name
();
...
...
@@ -1040,8 +1041,8 @@ void PrintSourceServerMethod(Printer *printer,
}
}
void
PrintSourceService
(
Printer
*
printer
,
const
Service
*
service
,
void
PrintSourceService
(
grpc_generator
::
Printer
*
printer
,
const
grpc_generator
::
Service
*
service
,
std
::
map
<
grpc
::
string
,
grpc
::
string
>
*
vars
)
{
(
*
vars
)[
"Service"
]
=
service
->
name
();
...
...
@@ -1153,7 +1154,7 @@ void PrintSourceService(Printer *printer,
}
}
grpc
::
string
GetSourceServices
(
File
*
file
,
grpc
::
string
GetSourceServices
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
)
{
grpc
::
string
output
;
{
...
...
@@ -1182,7 +1183,7 @@ grpc::string GetSourceServices(File *file,
return
output
;
}
grpc
::
string
GetSourceEpilogue
(
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
GetSourceEpilogue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
/*params*/
)
{
grpc
::
string
temp
;
if
(
!
file
->
package
().
empty
())
{
...
...
grpc/src/compiler/cpp_generator.h
View file @
c1b0abe0
...
...
@@ -41,16 +41,7 @@
#include <memory>
#include <vector>
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#endif
namespace
grpc
{
typedef
GRPC_CUSTOM_STRING
string
;
}
// namespace grpc
#include "src/compiler/schema_interface.h"
namespace
grpc_cpp_generator
{
...
...
@@ -64,83 +55,29 @@ struct Parameters {
grpc
::
string
grpc_search_path
;
};
// An abstract interface representing a method.
struct
Method
{
virtual
~
Method
()
{}
virtual
grpc
::
string
name
()
const
=
0
;
virtual
grpc
::
string
input_type_name
()
const
=
0
;
virtual
grpc
::
string
output_type_name
()
const
=
0
;
virtual
bool
NoStreaming
()
const
=
0
;
virtual
bool
ClientOnlyStreaming
()
const
=
0
;
virtual
bool
ServerOnlyStreaming
()
const
=
0
;
virtual
bool
BidiStreaming
()
const
=
0
;
};
// An abstract interface representing a service.
struct
Service
{
virtual
~
Service
()
{}
virtual
grpc
::
string
name
()
const
=
0
;
virtual
int
method_count
()
const
=
0
;
virtual
std
::
unique_ptr
<
const
Method
>
method
(
int
i
)
const
=
0
;
};
struct
Printer
{
virtual
~
Printer
()
{}
virtual
void
Print
(
const
std
::
map
<
grpc
::
string
,
grpc
::
string
>
&
vars
,
const
char
*
template_string
)
=
0
;
virtual
void
Print
(
const
char
*
string
)
=
0
;
virtual
void
Indent
()
=
0
;
virtual
void
Outdent
()
=
0
;
};
// An interface that allows the source generated to be output using various
// libraries/idls/serializers.
struct
File
{
virtual
~
File
()
{}
virtual
grpc
::
string
filename
()
const
=
0
;
virtual
grpc
::
string
filename_without_ext
()
const
=
0
;
virtual
grpc
::
string
message_header_ext
()
const
=
0
;
virtual
grpc
::
string
service_header_ext
()
const
=
0
;
virtual
grpc
::
string
package
()
const
=
0
;
virtual
std
::
vector
<
grpc
::
string
>
package_parts
()
const
=
0
;
virtual
grpc
::
string
additional_headers
()
const
=
0
;
virtual
int
service_count
()
const
=
0
;
virtual
std
::
unique_ptr
<
const
Service
>
service
(
int
i
)
const
=
0
;
virtual
std
::
unique_ptr
<
Printer
>
CreatePrinter
(
grpc
::
string
*
str
)
const
=
0
;
};
// Return the prologue of the generated header file.
grpc
::
string
GetHeaderPrologue
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetHeaderPrologue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the includes needed for generated header file.
grpc
::
string
GetHeaderIncludes
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetHeaderIncludes
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the includes needed for generated source file.
grpc
::
string
GetSourceIncludes
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetSourceIncludes
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the epilogue of the generated header file.
grpc
::
string
GetHeaderEpilogue
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetHeaderEpilogue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the prologue of the generated source file.
grpc
::
string
GetSourcePrologue
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetSourcePrologue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the services for generated header file.
grpc
::
string
GetHeaderServices
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetHeaderServices
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the services for generated source file.
grpc
::
string
GetSourceServices
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetSourceServices
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
// Return the epilogue of the generated source file.
grpc
::
string
GetSourceEpilogue
(
File
*
file
,
const
Parameters
&
params
);
grpc
::
string
GetSourceEpilogue
(
grpc_generator
::
File
*
file
,
const
Parameters
&
params
);
}
// namespace grpc_cpp_generator
...
...
grpc/src/compiler/schema_interface.h
0 → 100644
View file @
c1b0abe0
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
#define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
#include <memory>
#include <vector>
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#endif
namespace
grpc
{
typedef
GRPC_CUSTOM_STRING
string
;
}
// namespace grpc
namespace
grpc_generator
{
// An abstract interface representing a method.
struct
Method
{
virtual
~
Method
()
{}
virtual
grpc
::
string
name
()
const
=
0
;
virtual
grpc
::
string
input_type_name
()
const
=
0
;
virtual
grpc
::
string
output_type_name
()
const
=
0
;
virtual
bool
NoStreaming
()
const
=
0
;
virtual
bool
ClientOnlyStreaming
()
const
=
0
;
virtual
bool
ServerOnlyStreaming
()
const
=
0
;
virtual
bool
BidiStreaming
()
const
=
0
;
};
// An abstract interface representing a service.
struct
Service
{
virtual
~
Service
()
{}
virtual
grpc
::
string
name
()
const
=
0
;
virtual
int
method_count
()
const
=
0
;
virtual
std
::
unique_ptr
<
const
Method
>
method
(
int
i
)
const
=
0
;
};
struct
Printer
{
virtual
~
Printer
()
{}
virtual
void
Print
(
const
std
::
map
<
grpc
::
string
,
grpc
::
string
>
&
vars
,
const
char
*
template_string
)
=
0
;
virtual
void
Print
(
const
char
*
string
)
=
0
;
virtual
void
Indent
()
=
0
;
virtual
void
Outdent
()
=
0
;
};
// An interface that allows the source generated to be output using various
// libraries/idls/serializers.
struct
File
{
virtual
~
File
()
{}
virtual
grpc
::
string
filename
()
const
=
0
;
virtual
grpc
::
string
filename_without_ext
()
const
=
0
;
virtual
grpc
::
string
message_header_ext
()
const
=
0
;
virtual
grpc
::
string
service_header_ext
()
const
=
0
;
virtual
grpc
::
string
package
()
const
=
0
;
virtual
std
::
vector
<
grpc
::
string
>
package_parts
()
const
=
0
;
virtual
grpc
::
string
additional_headers
()
const
=
0
;
virtual
int
service_count
()
const
=
0
;
virtual
std
::
unique_ptr
<
const
Service
>
service
(
int
i
)
const
=
0
;
virtual
std
::
unique_ptr
<
Printer
>
CreatePrinter
(
grpc
::
string
*
str
)
const
=
0
;
};
}
// namespace grpc_generator
#endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
include/flatbuffers/flatbuffers.h
View file @
c1b0abe0
...
...
@@ -1436,11 +1436,6 @@ class Struct FLATBUFFERS_FINAL_CLASS {
return
ReadScalar
<
T
>
(
&
data_
[
o
]);
}
template
<
typename
T
>
T
GetPointer
(
uoffset_t
o
)
const
{
auto
p
=
&
data_
[
o
];
return
reinterpret_cast
<
T
>
(
p
+
ReadScalar
<
uoffset_t
>
(
p
));
}
template
<
typename
T
>
T
GetStruct
(
uoffset_t
o
)
const
{
return
reinterpret_cast
<
T
>
(
&
data_
[
o
]);
}
...
...
include/flatbuffers/idl.h
View file @
c1b0abe0
...
...
@@ -596,7 +596,9 @@ extern void GenComment(const std::vector<std::string> &dc,
// if it is less than 0, no linefeeds will be generated either.
// See idl_gen_text.cpp.
// strict_json adds "quotes" around field names if true.
extern
void
GenerateText
(
const
Parser
&
parser
,
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
// byte arrays in String values), returns false.
extern
bool
GenerateText
(
const
Parser
&
parser
,
const
void
*
flatbuffer
,
std
::
string
*
text
);
extern
bool
GenerateTextFile
(
const
Parser
&
parser
,
...
...
java/com/google/flatbuffers/FlatBufferBuilder.java
View file @
c1b0abe0
...
...
@@ -367,6 +367,28 @@ public class FlatBufferBuilder {
}
/// @endcond
/**
* Create a new array/vector and return a ByteBuffer to be filled later.
* Call {@link #endVector} after this method to get an offset to the beginning
* of vector.
*
* @param elem_size the size of each element in bytes.
* @param num_elems number of elements in the vector.
* @param alignment byte alignment.
* @return ByteBuffer with position and limit set to the space allocated for the array.
*/
public
ByteBuffer
createUnintializedVector
(
int
elem_size
,
int
num_elems
,
int
alignment
)
{
int
length
=
elem_size
*
num_elems
;
startVector
(
elem_size
,
num_elems
,
alignment
);
bb
.
position
(
space
-=
length
);
// Slice and limit the copy vector to point to the 'array'
ByteBuffer
copy
=
bb
.
slice
().
order
(
ByteOrder
.
LITTLE_ENDIAN
);
copy
.
limit
(
length
);
return
copy
;
}
/**
* Encode the string `s` in the buffer using UTF-8. If {@code s} is
* already a {@link CharBuffer}, this method is allocation free.
...
...
@@ -413,6 +435,20 @@ public class FlatBufferBuilder {
return
endVector
();
}
/**
* Create a byte array in the buffer.
*
* @param arr A source array with data
* @return The offset in the buffer where the encoded array starts.
*/
public
int
createByteVector
(
byte
[]
arr
)
{
int
length
=
arr
.
length
;
startVector
(
1
,
length
,
1
);
bb
.
position
(
space
-=
length
);
bb
.
put
(
arr
);
return
endVector
();
}
/// @cond FLATBUFFERS_INTERNAL
/**
* Should not be accessing the final buffer before it is finished.
...
...
net/FlatBuffers/ByteBuffer.cs
View file @
c1b0abe0
...
...
@@ -14,7 +14,20 @@
* limitations under the License.
*/
//#define UNSAFE_BYTEBUFFER // uncomment this line to use faster ByteBuffer
// There are 2 #defines that have an impact on performance of this ByteBuffer implementation
//
// UNSAFE_BYTEBUFFER
// This will use unsafe code to manipulate the underlying byte array. This
// can yield a reasonable performance increase.
//
// BYTEBUFFER_NO_BOUNDS_CHECK
// This will disable the bounds check asserts to the byte array. This can
// yield a small performance gain in normal code..
//
// Using UNSAFE_BYTEBUFFER and BYTEBUFFER_NO_BOUNDS_CHECK together can yield a
// performance gain of ~15% for some operations, however doing so is potentially
// dangerous. Do so at your own risk!
//
using
System
;
...
...
@@ -22,9 +35,6 @@ namespace FlatBuffers
{
/// <summary>
/// Class to mimic Java's ByteBuffer which is used heavily in Flatbuffers.
/// If your execution environment allows unsafe code, you should enable
/// unsafe code in your project and #define UNSAFE_BYTEBUFFER to use a
/// MUCH faster version of ByteBuffer.
/// </summary>
public
class
ByteBuffer
{
...
...
@@ -126,11 +136,14 @@ namespace FlatBuffers
}
#endif // !UNSAFE_BYTEBUFFER
private
void
AssertOffsetAndLength
(
int
offset
,
int
length
)
{
#
if
!
BYTEBUFFER_NO_BOUNDS_CHECK
if
(
offset
<
0
||
offset
>
_buffer
.
Length
-
length
)
throw
new
ArgumentOutOfRangeException
();
#
endif
}
public
void
PutSbyte
(
int
offset
,
sbyte
value
)
...
...
@@ -200,7 +213,6 @@ namespace FlatBuffers
public
unsafe
void
PutUlong
(
int
offset
,
ulong
value
)
{
AssertOffsetAndLength
(
offset
,
sizeof
(
ulong
));
fixed
(
byte
*
ptr
=
_buffer
)
{
*(
ulong
*)(
ptr
+
offset
)
=
BitConverter
.
IsLittleEndian
...
...
samples/sample_text.cpp
View file @
c1b0abe0
...
...
@@ -46,7 +46,10 @@ int main(int /*argc*/, const char * /*argv*/[]) {
// to ensure it is correct, we now generate text back from the binary,
// and compare the two:
std
::
string
jsongen
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
if
(
!
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
))
{
printf
(
"Couldn't serialize parsed data to JSON!
\n
"
);
return
1
;
}
if
(
jsongen
!=
jsonfile
)
{
printf
(
"%s----------------
\n
%s"
,
jsongen
.
c_str
(),
jsonfile
.
c_str
());
...
...
src/idl_gen_go.cpp
View file @
c1b0abe0
...
...
@@ -288,9 +288,6 @@ static void GetMemberOfVectorOfStruct(const StructDef &struct_def,
if
(
!
(
vectortype
.
struct_def
->
fixed
))
{
code
+=
"
\t\t
x = rcv._tab.Indirect(x)
\n
"
;
}
code
+=
"
\t\t
if obj == nil {
\n
"
;
code
+=
"
\t\t\t
obj = new("
+
TypeName
(
field
)
+
")
\n
"
;
code
+=
"
\t\t
}
\n
"
;
code
+=
"
\t\t
obj.Init(rcv._tab.Bytes, x)
\n
"
;
code
+=
"
\t\t
return true
\n\t
}
\n
"
;
code
+=
"
\t
return false
\n
"
;
...
...
src/idl_gen_grpc.cpp
View file @
c1b0abe0
...
...
@@ -24,7 +24,7 @@
namespace
flatbuffers
{
class
FlatBufMethod
:
public
grpc_
cpp_
generator
::
Method
{
class
FlatBufMethod
:
public
grpc_generator
::
Method
{
public
:
enum
Streaming
{
kNone
,
kClient
,
kServer
,
kBiDi
};
...
...
@@ -62,7 +62,7 @@ class FlatBufMethod : public grpc_cpp_generator::Method {
Streaming
streaming_
;
};
class
FlatBufService
:
public
grpc_
cpp_
generator
::
Service
{
class
FlatBufService
:
public
grpc_generator
::
Service
{
public
:
FlatBufService
(
const
ServiceDef
*
service
)
:
service_
(
service
)
{}
...
...
@@ -72,8 +72,8 @@ class FlatBufService : public grpc_cpp_generator::Service {
return
static_cast
<
int
>
(
service_
->
calls
.
vec
.
size
());
};
std
::
unique_ptr
<
const
grpc_
cpp_
generator
::
Method
>
method
(
int
i
)
const
{
return
std
::
unique_ptr
<
const
grpc_
cpp_
generator
::
Method
>
(
std
::
unique_ptr
<
const
grpc_generator
::
Method
>
method
(
int
i
)
const
{
return
std
::
unique_ptr
<
const
grpc_generator
::
Method
>
(
new
FlatBufMethod
(
service_
->
calls
.
vec
[
i
]));
};
...
...
@@ -81,7 +81,7 @@ class FlatBufService : public grpc_cpp_generator::Service {
const
ServiceDef
*
service_
;
};
class
FlatBufPrinter
:
public
grpc_
cpp_
generator
::
Printer
{
class
FlatBufPrinter
:
public
grpc_generator
::
Printer
{
public
:
FlatBufPrinter
(
std
::
string
*
str
)
:
str_
(
str
),
escape_char_
(
'$'
),
indent_
(
0
)
{}
...
...
@@ -133,7 +133,7 @@ class FlatBufPrinter : public grpc_cpp_generator::Printer {
int
indent_
;
};
class
FlatBufFile
:
public
grpc_
cpp_
generator
::
File
{
class
FlatBufFile
:
public
grpc_generator
::
File
{
public
:
FlatBufFile
(
const
Parser
&
parser
,
const
std
::
string
&
file_name
)
:
parser_
(
parser
),
file_name_
(
file_name
)
{}
...
...
@@ -163,13 +163,13 @@ class FlatBufFile : public grpc_cpp_generator::File {
return
static_cast
<
int
>
(
parser_
.
services_
.
vec
.
size
());
};
std
::
unique_ptr
<
const
grpc_
cpp_
generator
::
Service
>
service
(
int
i
)
const
{
return
std
::
unique_ptr
<
const
grpc_
cpp_
generator
::
Service
>
(
std
::
unique_ptr
<
const
grpc_generator
::
Service
>
service
(
int
i
)
const
{
return
std
::
unique_ptr
<
const
grpc_generator
::
Service
>
(
new
FlatBufService
(
parser_
.
services_
.
vec
[
i
]));
}
std
::
unique_ptr
<
grpc_
cpp_
generator
::
Printer
>
CreatePrinter
(
std
::
string
*
str
)
const
{
return
std
::
unique_ptr
<
grpc_
cpp_
generator
::
Printer
>
(
std
::
unique_ptr
<
grpc_generator
::
Printer
>
CreatePrinter
(
std
::
string
*
str
)
const
{
return
std
::
unique_ptr
<
grpc_generator
::
Printer
>
(
new
FlatBufPrinter
(
str
));
}
...
...
src/idl_gen_text.cpp
View file @
c1b0abe0
This diff is collapsed.
Click to expand it.
tests/FlatBuffers.Test/ByteBufferTests.cs
View file @
c1b0abe0
...
...
@@ -40,6 +40,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
((
byte
)
99
,
buffer
[
0
]);
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutByteCannotPutAtOffsetPastLength
()
{
...
...
@@ -47,6 +48,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
PutByte
(
1
,
99
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutShortPopulatesBufferCorrectly
()
...
...
@@ -60,6 +62,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
((
byte
)
0
,
buffer
[
1
]);
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutShortCannotPutAtOffsetPastLength
()
{
...
...
@@ -67,7 +70,9 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
PutShort
(
2
,
99
));
}
#endif
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutShortChecksLength
()
{
...
...
@@ -83,6 +88,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
PutShort
(
1
,
99
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutIntPopulatesBufferCorrectly
()
...
...
@@ -98,6 +104,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
0x0A
,
buffer
[
3
]);
}
#
if
!
BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutIntCannotPutAtOffsetPastLength
()
{
...
...
@@ -121,6 +128,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
PutInt
(
2
,
0x0A0B0C0D
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutLongPopulatesBufferCorrectly
()
...
...
@@ -140,6 +148,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
0x01
,
buffer
[
7
]);
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_PutLongCannotPutAtOffsetPastLength
()
{
...
...
@@ -163,6 +172,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
PutLong
(
2
,
0x010203040A0B0C0D
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetByteReturnsCorrectData
()
...
...
@@ -173,6 +183,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
((
byte
)
99
,
uut
.
Get
(
0
));
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetByteChecksOffset
()
{
...
...
@@ -180,6 +191,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()=>
uut
.
Get
(
1
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetShortReturnsCorrectData
()
...
...
@@ -191,6 +203,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
1
,
uut
.
GetShort
(
0
));
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetShortChecksOffset
()
{
...
...
@@ -206,6 +219,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
GetShort
(
1
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetIntReturnsCorrectData
()
...
...
@@ -219,6 +233,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
0x0A0B0C0D
,
uut
.
GetInt
(
0
));
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetIntChecksOffset
()
{
...
...
@@ -234,6 +249,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
GetInt
(
0
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetLongReturnsCorrectData
()
...
...
@@ -251,6 +267,7 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
0x010203040A0B0C0D
,
uut
.
GetLong
(
0
));
}
#if !BYTEBUFFER_NO_BOUNDS_CHECK
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_GetLongChecksOffset
()
{
...
...
@@ -266,6 +283,7 @@ namespace FlatBuffers.Test
var
uut
=
new
ByteBuffer
(
buffer
);
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
uut
.
GetLong
(
0
));
}
#endif
[
FlatBuffersTestMethod
]
public
void
ByteBuffer_ReverseBytesUshort
()
...
...
tests/JavaTest.java
View file @
c1b0abe0
...
...
@@ -161,6 +161,10 @@ class JavaTest {
TestNestedFlatBuffer
();
TestCreateByteVector
();
TestCreateUninitializedVector
();
System
.
out
.
println
(
"FlatBuffers test: completed successfully"
);
}
...
...
@@ -281,6 +285,44 @@ class JavaTest {
TestEq
(
nestedMonsterName
,
nestedMonster
.
name
());
}
static
void
TestCreateByteVector
()
{
FlatBufferBuilder
fbb
=
new
FlatBufferBuilder
(
16
);
int
str
=
fbb
.
createString
(
"MyMonster"
);
byte
[]
inventory
=
new
byte
[]
{
0
,
1
,
2
,
3
,
4
};
int
vec
=
fbb
.
createByteVector
(
inventory
);
Monster
.
startMonster
(
fbb
);
Monster
.
addInventory
(
fbb
,
vec
);
Monster
.
addName
(
fbb
,
str
);
int
monster1
=
Monster
.
endMonster
(
fbb
);
Monster
.
finishMonsterBuffer
(
fbb
,
monster1
);
Monster
monsterObject
=
Monster
.
getRootAsMonster
(
fbb
.
dataBuffer
());
TestEq
(
monsterObject
.
inventory
(
1
),
(
int
)
inventory
[
1
]);
TestEq
(
monsterObject
.
inventoryLength
(),
inventory
.
length
);
TestEq
(
ByteBuffer
.
wrap
(
inventory
),
monsterObject
.
inventoryAsByteBuffer
());
}
static
void
TestCreateUninitializedVector
()
{
FlatBufferBuilder
fbb
=
new
FlatBufferBuilder
(
16
);
int
str
=
fbb
.
createString
(
"MyMonster"
);
byte
[]
inventory
=
new
byte
[]
{
0
,
1
,
2
,
3
,
4
};
ByteBuffer
bb
=
fbb
.
createUnintializedVector
(
1
,
inventory
.
length
,
1
);
for
(
byte
i:
inventory
)
{
bb
.
put
(
i
);
}
int
vec
=
fbb
.
endVector
();
Monster
.
startMonster
(
fbb
);
Monster
.
addInventory
(
fbb
,
vec
);
Monster
.
addName
(
fbb
,
str
);
int
monster1
=
Monster
.
endMonster
(
fbb
);
Monster
.
finishMonsterBuffer
(
fbb
,
monster1
);
Monster
monsterObject
=
Monster
.
getRootAsMonster
(
fbb
.
dataBuffer
());
TestEq
(
monsterObject
.
inventory
(
1
),
(
int
)
inventory
[
1
]);
TestEq
(
monsterObject
.
inventoryLength
(),
inventory
.
length
);
TestEq
(
ByteBuffer
.
wrap
(
inventory
),
monsterObject
.
inventoryAsByteBuffer
());
}
static
<
T
>
void
TestEq
(
T
a
,
T
b
)
{
if
(!
a
.
equals
(
b
))
{
System
.
out
.
println
(
""
+
a
.
getClass
().
getName
()
+
" "
+
b
.
getClass
().
getName
());
...
...
tests/MyGame/Example/Monster.go
View file @
c1b0abe0
...
...
@@ -131,9 +131,6 @@ func (rcv *Monster) Test4(obj *Test, j int) bool {
if
o
!=
0
{
x
:=
rcv
.
_tab
.
Vector
(
o
)
x
+=
flatbuffers
.
UOffsetT
(
j
)
*
4
if
obj
==
nil
{
obj
=
new
(
Test
)
}
obj
.
Init
(
rcv
.
_tab
.
Bytes
,
x
)
return
true
}
...
...
@@ -173,9 +170,6 @@ func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool {
x
:=
rcv
.
_tab
.
Vector
(
o
)
x
+=
flatbuffers
.
UOffsetT
(
j
)
*
4
x
=
rcv
.
_tab
.
Indirect
(
x
)
if
obj
==
nil
{
obj
=
new
(
Monster
)
}
obj
.
Init
(
rcv
.
_tab
.
Bytes
,
x
)
return
true
}
...
...
tests/test.cpp
View file @
c1b0abe0
...
...
@@ -410,7 +410,8 @@ void ParseAndGenerateTextTest() {
// to ensure it is correct, we now generate text back from the binary,
// and compare the two:
std
::
string
jsongen
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
true
);
if
(
jsongen
!=
jsonfile
)
{
printf
(
"%s----------------
\n
%s"
,
jsongen
.
c_str
(),
jsonfile
.
c_str
());
...
...
@@ -827,7 +828,8 @@ void FuzzTest2() {
std
::
string
jsongen
;
parser
.
opts
.
indent_step
=
0
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
true
);
if
(
jsongen
!=
json
)
{
// These strings are larger than a megabyte, so we show the bytes around
...
...
@@ -987,7 +989,8 @@ void UnicodeTest() {
true
);
std
::
string
jsongen
;
parser
.
opts
.
indent_step
=
-
1
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
true
);
TEST_EQ
(
jsongen
,
std
::
string
(
"{F:
\"\\
u20AC
\\
u00A2
\\
u30E6
\\
u30FC
\\
u30B6
\\
u30FC"
...
...
@@ -1003,13 +1006,31 @@ void UnicodeTestAllowNonUTF8() {
"
\\
u5225
\\
u30B5
\\
u30A4
\\
u30C8
\\
x01
\\
x80
\\
u0080
\\
uD83D
\\
uDE0E
\"
}"
),
true
);
std
::
string
jsongen
;
parser
.
opts
.
indent_step
=
-
1
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
true
);
TEST_EQ
(
jsongen
,
std
::
string
(
"{F:
\"\\
u20AC
\\
u00A2
\\
u30E6
\\
u30FC
\\
u30B6
\\
u30FC"
"
\\
u5225
\\
u30B5
\\
u30A4
\\
u30C8
\\
u0001
\\
x80
\\
u0080
\\
uD83D
\\
uDE0E
\"
}"
));
}
void
UnicodeTestGenerateTextFailsOnNonUTF8
()
{
flatbuffers
::
Parser
parser
;
// Allow non-UTF-8 initially to model what happens when we load a binary flatbuffer from disk
// which contains non-UTF-8 strings.
parser
.
opts
.
allow_non_utf8
=
true
;
TEST_EQ
(
parser
.
Parse
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
u20AC
\\
u00A2
\\
u30E6
\\
u30FC
\\
u30B6
\\
u30FC"
"
\\
u5225
\\
u30B5
\\
u30A4
\\
u30C8
\\
x01
\\
x80
\\
u0080
\\
uD83D
\\
uDE0E
\"
}"
),
true
);
std
::
string
jsongen
;
parser
.
opts
.
indent_step
=
-
1
;
// Now, disallow non-UTF-8 (the default behavior) so GenerateText indicates failure.
parser
.
opts
.
allow_non_utf8
=
false
;
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
false
);
}
void
UnicodeSurrogatesTest
()
{
flatbuffers
::
Parser
parser
;
...
...
@@ -1157,7 +1178,8 @@ void UnknownFieldsTest() {
std
::
string
jsongen
;
parser
.
opts
.
indent_step
=
-
1
;
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
auto
result
=
GenerateText
(
parser
,
parser
.
builder_
.
GetBufferPointer
(),
&
jsongen
);
TEST_EQ
(
result
,
true
);
TEST_EQ
(
jsongen
==
"{str:
\"
test
\"
,i: 10}"
,
true
);
}
...
...
@@ -1222,6 +1244,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
IntegerOutOfRangeTest
();
UnicodeTest
();
UnicodeTestAllowNonUTF8
();
UnicodeTestGenerateTextFailsOnNonUTF8
();
UnicodeSurrogatesTest
();
UnicodeInvalidSurrogatesTest
();
InvalidUTF8Test
();
...
...
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