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
72b9501e
Commit
72b9501e
authored
Jan 29, 2015
by
Florian Enner
Committed by
Wouter van Oortmerssen
Feb 02, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added force-defaults to Java bindings
Change-Id: I62d10b639112788be3b0f670280bd50ef9fcf094
parent
9c169083
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
FlatBufferBuilder.java
java/com/google/flatbuffers/FlatBufferBuilder.java
+22
-8
No files found.
java/com/google/flatbuffers/FlatBufferBuilder.java
View file @
72b9501e
...
@@ -39,6 +39,7 @@ public class FlatBufferBuilder {
...
@@ -39,6 +39,7 @@ public class FlatBufferBuilder {
int
[]
vtables
=
new
int
[
16
];
// List of offsets of all vtables.
int
[]
vtables
=
new
int
[
16
];
// List of offsets of all vtables.
int
num_vtables
=
0
;
// Number of entries in `vtables` in use.
int
num_vtables
=
0
;
// Number of entries in `vtables` in use.
int
vector_num_elems
=
0
;
// For the current vector being built.
int
vector_num_elems
=
0
;
// For the current vector being built.
boolean
force_defaults
=
false
;
// False omits default values from the serialized data
/**
/**
* Start with a buffer of size {@code initial_size}, then grow as required.
* Start with a buffer of size {@code initial_size}, then grow as required.
...
@@ -333,14 +334,14 @@ public class FlatBufferBuilder {
...
@@ -333,14 +334,14 @@ public class FlatBufferBuilder {
}
}
// Add a scalar to a table at `o` into its vtable, with value `x` and default `d`
// Add a scalar to a table at `o` into its vtable, with value `x` and default `d`
public
void
addBoolean
(
int
o
,
boolean
x
,
boolean
d
)
{
if
(
x
!=
d
)
{
addBoolean
(
x
);
slot
(
o
);
}
}
public
void
addBoolean
(
int
o
,
boolean
x
,
boolean
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addBoolean
(
x
);
slot
(
o
);
}
}
public
void
addByte
(
int
o
,
byte
x
,
int
d
)
{
if
(
x
!=
d
)
{
addByte
(
x
);
slot
(
o
);
}
}
public
void
addByte
(
int
o
,
byte
x
,
int
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addByte
(
x
);
slot
(
o
);
}
}
public
void
addShort
(
int
o
,
short
x
,
int
d
)
{
if
(
x
!=
d
)
{
addShort
(
x
);
slot
(
o
);
}
}
public
void
addShort
(
int
o
,
short
x
,
int
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addShort
(
x
);
slot
(
o
);
}
}
public
void
addInt
(
int
o
,
int
x
,
int
d
)
{
if
(
x
!=
d
)
{
addInt
(
x
);
slot
(
o
);
}
}
public
void
addInt
(
int
o
,
int
x
,
int
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addInt
(
x
);
slot
(
o
);
}
}
public
void
addLong
(
int
o
,
long
x
,
long
d
)
{
if
(
x
!=
d
)
{
addLong
(
x
);
slot
(
o
);
}
}
public
void
addLong
(
int
o
,
long
x
,
long
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addLong
(
x
);
slot
(
o
);
}
}
public
void
addFloat
(
int
o
,
float
x
,
double
d
)
{
if
(
x
!=
d
)
{
addFloat
(
x
);
slot
(
o
);
}
}
public
void
addFloat
(
int
o
,
float
x
,
double
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addFloat
(
x
);
slot
(
o
);
}
}
public
void
addDouble
(
int
o
,
double
x
,
double
d
)
{
if
(
x
!=
d
)
{
addDouble
(
x
);
slot
(
o
);
}
}
public
void
addDouble
(
int
o
,
double
x
,
double
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addDouble
(
x
);
slot
(
o
);
}
}
public
void
addOffset
(
int
o
,
int
x
,
int
d
)
{
if
(
x
!=
d
)
{
addOffset
(
x
);
slot
(
o
);
}
}
public
void
addOffset
(
int
o
,
int
x
,
int
d
)
{
if
(
force_defaults
||
x
!=
d
)
{
addOffset
(
x
);
slot
(
o
);
}
}
// Structs are stored inline, so nothing additional is being added. `d` is always 0.
// Structs are stored inline, so nothing additional is being added. `d` is always 0.
public
void
addStruct
(
int
voffset
,
int
x
,
int
d
)
{
public
void
addStruct
(
int
voffset
,
int
x
,
int
d
)
{
...
@@ -442,6 +443,19 @@ public class FlatBufferBuilder {
...
@@ -442,6 +443,19 @@ public class FlatBufferBuilder {
finish
(
root_table
);
finish
(
root_table
);
}
}
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
* way to manually disable this optimization.
*
* @param forceDefaults true always serializes default values
* @return this
*/
public
FlatBufferBuilder
forceDefaults
(
boolean
forceDefaults
){
this
.
force_defaults
=
forceDefaults
;
return
this
;
}
// Get the ByteBuffer representing the FlatBuffer. Only call this after you've
// Get the ByteBuffer representing the FlatBuffer. Only call this after you've
// called finish(). The actual data starts at the ByteBuffer's current position,
// called finish(). The actual data starts at the ByteBuffer's current position,
// not necessarily at 0.
// not necessarily at 0.
...
...
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