java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.encoding.cbor.CborEncoder |
Provides an encoder capable of encoding data into CBOR format to a given OutputStream.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CborEncoder(OutputStream os)
Creates a new
CborEncoder instance. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
writeArrayStart()
Writes the start of an indefinite-length array.
| ||||||||||
void |
writeArrayStart(int length)
Writes the start of a definite-length array.
| ||||||||||
void |
writeBoolean(boolean value)
Writes a boolean value in canonical CBOR format.
| ||||||||||
void |
writeBreak()
Writes a "break" stop-value in canonical CBOR format.
| ||||||||||
void |
writeByteString(byte[] bytes)
Writes a byte string in canonical CBOR-format.
| ||||||||||
void |
writeByteStringStart()
Writes the start of an indefinite-length byte string.
| ||||||||||
void |
writeDouble(double value)
Writes a double-precision float value in canonical CBOR format.
| ||||||||||
void |
writeFloat(float value)
Writes a single-precision float value in canonical CBOR format.
| ||||||||||
void |
writeHalfPrecisionFloat(float value)
Writes a half-precision float value in canonical CBOR format.
| ||||||||||
void |
writeInt(long value)
Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..
| ||||||||||
void |
writeInt16(int value)
Writes a signed or unsigned 16-bit integer value in CBOR format.
| ||||||||||
void |
writeInt32(long value)
Writes a signed or unsigned 32-bit integer value in CBOR format.
| ||||||||||
void |
writeInt64(long value)
Writes a signed or unsigned 64-bit integer value in CBOR format.
| ||||||||||
void |
writeInt8(int value)
Writes a signed or unsigned 8-bit integer value in CBOR format.
| ||||||||||
void |
writeMapStart()
Writes the start of an indefinite-length map.
| ||||||||||
void |
writeMapStart(int length)
Writes the start of a finite-length map.
| ||||||||||
void |
writeNull()
Writes a
null value in canonical CBOR format. | ||||||||||
void |
writeSimpleValue(byte simpleValue)
Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.
| ||||||||||
void |
writeSmallInt(int value)
Writes a signed or unsigned small (<= 23) integer value in CBOR format.
| ||||||||||
void |
writeTag(long tag)
Writes a semantic tag in canonical CBOR format.
| ||||||||||
void |
writeTextString(String value)
Writes an UTF-8 string in canonical CBOR-format.
| ||||||||||
void |
writeTextStringStart()
Writes the start of an indefinite-length UTF-8 string.
| ||||||||||
void |
writeUndefined()
Writes an "undefined" value in canonical CBOR format.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
writeSimpleType(int majorType, int value)
Encodes and writes the major type and value as a simple type.
| ||||||||||
void |
writeString(int majorType, byte[] bytes)
Writes a byte string in canonical CBOR-format.
| ||||||||||
void |
writeType(int majorType, long value)
Encodes and writes the major type indicator with a given payload (length).
| ||||||||||
void |
writeUInt(int mt, long value)
Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.
| ||||||||||
void |
writeUInt16(int mt, int value)
Encodes and writes an unsigned 16-bit integer value
| ||||||||||
void |
writeUInt32(int mt, int value)
Encodes and writes an unsigned 32-bit integer value
| ||||||||||
void |
writeUInt64(int mt, long value)
Encodes and writes an unsigned 64-bit integer value
| ||||||||||
void |
writeUInt8(int mt, int value)
Encodes and writes an unsigned 8-bit integer value
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new CborEncoder
instance.
os | the actual output stream to write the CBOR-encoded data to, cannot be null .
|
---|
Writes the start of an indefinite-length array.
After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
After all array elements are written, one should write a single break value to end the array, see writeBreak()
.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes the start of a definite-length array.
After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
length | the number of array elements to write, should >= 0. |
---|
IllegalArgumentException | in case the given length was negative; |
---|---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
Writes a boolean value in canonical CBOR format.
value | the boolean to write. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a "break" stop-value in canonical CBOR format.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a byte string in canonical CBOR-format.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes the start of an indefinite-length byte string.
After calling this method, one is expected to write the given number of string parts. No length checks are performed.
After all string parts are written, one should write a single break value to end the string, see writeBreak()
.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a signed or unsigned 16-bit integer value in CBOR format.
value | the value to write, values from [-65536..65535] are supported. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a signed or unsigned 32-bit integer value in CBOR format.
value | the value to write, values in the range [-4294967296..4294967295] are supported. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a signed or unsigned 8-bit integer value in CBOR format.
value | the value to write, values in the range [-256..255] are supported. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes the start of an indefinite-length map.
After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
After all map entries are written, one should write a single break value to end the map, see writeBreak()
.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes the start of a finite-length map.
After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
length | the number of map entries to write, should >= 0. |
---|
IllegalArgumentException | in case the given length was negative; |
---|---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
Writes a null
value in canonical CBOR format.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a signed or unsigned small (<= 23) integer value in CBOR format.
value | the value to write, values in the range [-24..23] are supported. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a semantic tag in canonical CBOR format.
tag | the tag to write, should >= 0. |
---|
IllegalArgumentException | in case the given tag was negative; |
---|---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
Writes an UTF-8 string in canonical CBOR-format.
Note that this method is platform specific, as the given string value will be encoded in a byte array using the platform encoding! This means that the encoding must be standardized and known.
value | the UTF-8 string to write, can be null in which case an UTF-8 string of length 0 is written. |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes the start of an indefinite-length UTF-8 string.
After calling this method, one is expected to write the given number of string parts. No length checks are performed.
After all string parts are written, one should write a single break value to end the string, see writeBreak()
.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes an "undefined" value in canonical CBOR format.
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes the major type and value as a simple type.
majorType | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from [0..31] are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Writes a byte string in canonical CBOR-format.
majorType | the major type of the string, should be either 0x40 or 0x60; |
---|
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes the major type indicator with a given payload (length).
majorType | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.
mt | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes an unsigned 16-bit integer value
mt | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes an unsigned 32-bit integer value
mt | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes an unsigned 64-bit integer value
mt | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|
Encodes and writes an unsigned 8-bit integer value
mt | the major type of the value to write, denotes what semantics the written value has; |
---|---|
value | the value to write, values from MIN_VALUE to MAX_VALUE are supported. |
IOException | in case of I/O problems writing the CBOR-encoded value to the underlying output stream. |
---|