Commit 6dff7c68 authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen Committed by GitHub

Merge pull request #3916 from YuryBandarchuk16/master

Added new constants
parents 2fdafa9a ec59dc02
...@@ -23,10 +23,18 @@ package com.google.flatbuffers; ...@@ -23,10 +23,18 @@ package com.google.flatbuffers;
*/ */
public class Constants { public class Constants {
// Java doesn't seem to have these. // Java doesn't seem to have these.
/** The number of bytes in an `byte`. */
static final int SIZEOF_BYTE = 1;
/** The number of bytes in a `short`. */ /** The number of bytes in a `short`. */
static final int SIZEOF_SHORT = 2; static final int SIZEOF_SHORT = 2;
/** The number of bytes in an `int`. */ /** The number of bytes in an `int`. */
static final int SIZEOF_INT = 4; static final int SIZEOF_INT = 4;
/** The number of bytes in an `float`. */
static final int SIZEOF_FLOAT = 4;
/** The number of bytes in an `long`. */
static final int SIZEOF_LONG = 8;
/** The number of bytes in an `double`. */
static final int SIZEOF_DOUBLE = 8;
/** The number of bytes in a file identifier. */ /** The number of bytes in a file identifier. */
static final int FILE_IDENTIFIER_LENGTH = 4; static final int FILE_IDENTIFIER_LENGTH = 4;
} }
......
...@@ -188,7 +188,7 @@ public class FlatBufferBuilder { ...@@ -188,7 +188,7 @@ public class FlatBufferBuilder {
* *
* @param x A `boolean` to put into the buffer. * @param x A `boolean` to put into the buffer.
*/ */
public void putBoolean(boolean x) { bb.put (space -= 1, (byte)(x ? 1 : 0)); } public void putBoolean(boolean x) { bb.put (space -= Constants.SIZEOF_BYTE, (byte)(x ? 1 : 0)); }
/** /**
* Add a `byte` to the buffer, backwards from the current location. Doesn't align nor * Add a `byte` to the buffer, backwards from the current location. Doesn't align nor
...@@ -196,7 +196,7 @@ public class FlatBufferBuilder { ...@@ -196,7 +196,7 @@ public class FlatBufferBuilder {
* *
* @param x A `byte` to put into the buffer. * @param x A `byte` to put into the buffer.
*/ */
public void putByte (byte x) { bb.put (space -= 1, x); } public void putByte (byte x) { bb.put (space -= Constants.SIZEOF_BYTE, x); }
/** /**
* Add a `short` to the buffer, backwards from the current location. Doesn't align nor * Add a `short` to the buffer, backwards from the current location. Doesn't align nor
...@@ -204,7 +204,7 @@ public class FlatBufferBuilder { ...@@ -204,7 +204,7 @@ public class FlatBufferBuilder {
* *
* @param x A `short` to put into the buffer. * @param x A `short` to put into the buffer.
*/ */
public void putShort (short x) { bb.putShort (space -= 2, x); } public void putShort (short x) { bb.putShort (space -= Constants.SIZEOF_SHORT, x); }
/** /**
* Add an `int` to the buffer, backwards from the current location. Doesn't align nor * Add an `int` to the buffer, backwards from the current location. Doesn't align nor
...@@ -212,7 +212,7 @@ public class FlatBufferBuilder { ...@@ -212,7 +212,7 @@ public class FlatBufferBuilder {
* *
* @param x An `int` to put into the buffer. * @param x An `int` to put into the buffer.
*/ */
public void putInt (int x) { bb.putInt (space -= 4, x); } public void putInt (int x) { bb.putInt (space -= Constants.SIZEOF_INT, x); }
/** /**
* Add a `long` to the buffer, backwards from the current location. Doesn't align nor * Add a `long` to the buffer, backwards from the current location. Doesn't align nor
...@@ -220,7 +220,7 @@ public class FlatBufferBuilder { ...@@ -220,7 +220,7 @@ public class FlatBufferBuilder {
* *
* @param x A `long` to put into the buffer. * @param x A `long` to put into the buffer.
*/ */
public void putLong (long x) { bb.putLong (space -= 8, x); } public void putLong (long x) { bb.putLong (space -= Constants.SIZEOF_LONG, x); }
/** /**
* Add a `float` to the buffer, backwards from the current location. Doesn't align nor * Add a `float` to the buffer, backwards from the current location. Doesn't align nor
...@@ -228,7 +228,7 @@ public class FlatBufferBuilder { ...@@ -228,7 +228,7 @@ public class FlatBufferBuilder {
* *
* @param x A `float` to put into the buffer. * @param x A `float` to put into the buffer.
*/ */
public void putFloat (float x) { bb.putFloat (space -= 4, x); } public void putFloat (float x) { bb.putFloat (space -= Constants.SIZEOF_FLOAT, x); }
/** /**
* Add a `double` to the buffer, backwards from the current location. Doesn't align nor * Add a `double` to the buffer, backwards from the current location. Doesn't align nor
...@@ -236,7 +236,7 @@ public class FlatBufferBuilder { ...@@ -236,7 +236,7 @@ public class FlatBufferBuilder {
* *
* @param x A `double` to put into the buffer. * @param x A `double` to put into the buffer.
*/ */
public void putDouble (double x) { bb.putDouble(space -= 8, x); } public void putDouble (double x) { bb.putDouble(space -= Constants.SIZEOF_DOUBLE, x); }
/// @endcond /// @endcond
/** /**
...@@ -244,49 +244,49 @@ public class FlatBufferBuilder { ...@@ -244,49 +244,49 @@ public class FlatBufferBuilder {
* *
* @param x A `boolean` to put into the buffer. * @param x A `boolean` to put into the buffer.
*/ */
public void addBoolean(boolean x) { prep(1, 0); putBoolean(x); } public void addBoolean(boolean x) { prep(Constants.SIZEOF_BYTE, 0); putBoolean(x); }
/** /**
* Add a `byte` to the buffer, properly aligned, and grows the buffer (if necessary). * Add a `byte` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x A `byte` to put into the buffer. * @param x A `byte` to put into the buffer.
*/ */
public void addByte (byte x) { prep(1, 0); putByte (x); } public void addByte (byte x) { prep(Constants.SIZEOF_BYTE, 0); putByte (x); }
/** /**
* Add a `short` to the buffer, properly aligned, and grows the buffer (if necessary). * Add a `short` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x A `short` to put into the buffer. * @param x A `short` to put into the buffer.
*/ */
public void addShort (short x) { prep(2, 0); putShort (x); } public void addShort (short x) { prep(Constants.SIZEOF_SHORT, 0); putShort (x); }
/** /**
* Add an `int` to the buffer, properly aligned, and grows the buffer (if necessary). * Add an `int` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x An `int` to put into the buffer. * @param x An `int` to put into the buffer.
*/ */
public void addInt (int x) { prep(4, 0); putInt (x); } public void addInt (int x) { prep(Constants.SIZEOF_INT, 0); putInt (x); }
/** /**
* Add a `long` to the buffer, properly aligned, and grows the buffer (if necessary). * Add a `long` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x A `long` to put into the buffer. * @param x A `long` to put into the buffer.
*/ */
public void addLong (long x) { prep(8, 0); putLong (x); } public void addLong (long x) { prep(Constants.SIZEOF_LONG, 0); putLong (x); }
/** /**
* Add a `float` to the buffer, properly aligned, and grows the buffer (if necessary). * Add a `float` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x A `float` to put into the buffer. * @param x A `float` to put into the buffer.
*/ */
public void addFloat (float x) { prep(4, 0); putFloat (x); } public void addFloat (float x) { prep(Constants.SIZEOF_FLOAT, 0); putFloat (x); }
/** /**
* Add a `double` to the buffer, properly aligned, and grows the buffer (if necessary). * Add a `double` to the buffer, properly aligned, and grows the buffer (if necessary).
* *
* @param x A `double` to put into the buffer. * @param x A `double` to put into the buffer.
*/ */
public void addDouble (double x) { prep(8, 0); putDouble (x); } public void addDouble (double x) { prep(Constants.SIZEOF_DOUBLE, 0); putDouble (x); }
/** /**
* Adds on offset, relative to where it will be written. * Adds on offset, relative to where it will be written.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment