# Class: com.pnfsoftware.jeb.util.encoding.cbor.CborEncoder

Provides an encoder capable of encoding data into CBOR format to a given [OutputStream](OutputStream).

## Constructor: CborEncoder
- parameter: `os`, type: `java.io.OutputStream`

Description: Creates a new [CborEncoder](CborEncoder) instance.
parameter: os: the actual output stream to write the CBOR\-encoded data to, cannot be `null`.

## Method: writeArrayStart

Description: 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()](#writeBreak()).
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeArrayStart
- parameter: `length`, type: `int`

Description: 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.
parameter: length: the number of array elements to write, should \>= 0.
throws: in case the given length was negative;
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeBoolean
- parameter: `value`, type: `boolean`

Description: Writes a boolean value in canonical CBOR format.
parameter: value: the boolean to write.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeBreak

Description: Writes a "break" stop\-value in canonical CBOR format.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeByteString
- parameter: `bytes`, type: `byte[]`

Description: Writes a byte string in canonical CBOR\-format.
parameter: value: the byte string to write, can be `null` in which case a byte\-string of length `0` is written.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeByteStringStart

Description: 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()](#writeBreak()).
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeDouble
- parameter: `value`, type: `double`

Description: Writes a double\-precision float value in canonical CBOR format.
parameter: value: the value to write, values from [Double#MIN_VALUE](Double#MIN_VALUE) to [Double#MAX_VALUE](Double#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeFloat
- parameter: `value`, type: `float`

Description: Writes a single\-precision float value in canonical CBOR format.
parameter: value: the value to write, values from [Float#MIN_VALUE](Float#MIN_VALUE) to [Float#MAX_VALUE](Float#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeHalfPrecisionFloat
- parameter: `value`, type: `float`

Description: Writes a half\-precision float value in canonical CBOR format.
parameter: value: the value to write, values from [Float#MIN_VALUE](Float#MIN_VALUE) to [Float#MAX_VALUE](Float#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeInt
- parameter: `value`, type: `long`

Description: Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeInt16
- parameter: `value`, type: `int`

Description: Writes a signed or unsigned 16\-bit integer value in CBOR format.
parameter: value: the value to write, values from `[-65536..65535]` are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeInt32
- parameter: `value`, type: `long`

Description: Writes a signed or unsigned 32\-bit integer value in CBOR format.
parameter: value: the value to write, values in the range `[-4294967296..4294967295]` are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeInt64
- parameter: `value`, type: `long`

Description: Writes a signed or unsigned 64\-bit integer value in CBOR format.
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeInt8
- parameter: `value`, type: `int`

Description: Writes a signed or unsigned 8\-bit integer value in CBOR format.
parameter: value: the value to write, values in the range `[-256..255]` are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeMapStart

Description: 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()](#writeBreak()).
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeMapStart
- parameter: `length`, type: `int`

Description: 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.
parameter: length: the number of map entries to write, should \>= 0.
throws: in case the given length was negative;
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeNull

Description: Writes a `null` value in canonical CBOR format.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeSimpleType
- parameter: `majorType`, type: `int`
- parameter: `value`, type: `int`

Description: Encodes and writes the major type and value as a simple type.
parameter: majorType: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from \[0..31\] are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeSimpleValue
- parameter: `simpleValue`, type: `byte`

Description: Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.
parameter: value: the \(unsigned byte\) value to write, values from `32` to `255` are supported \(though not enforced\).
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeSmallInt
- parameter: `value`, type: `int`

Description: Writes a signed or unsigned small \(<= 23\) integer value in CBOR format.
parameter: value: the value to write, values in the range `[-24..23]` are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeString
- parameter: `majorType`, type: `int`
- parameter: `bytes`, type: `byte[]`

Description: Writes a byte string in canonical CBOR\-format.
parameter: majorType: the major type of the string, should be either 0x40 or 0x60;
parameter: value: the byte string to write, can be `null` in which case a byte\-string of length `0` is written.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeTag
- parameter: `tag`, type: `long`

Description: Writes a semantic tag in canonical CBOR format.
parameter: tag: the tag to write, should \>= 0.
throws: in case the given tag was negative;
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeTextString
- parameter: `value`, type: `java.lang.String`

Description: 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.
parameter: value: the UTF\-8 string to write, can be `null` in which case an UTF\-8 string of length `0` is written.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeTextStringStart

Description: 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()](#writeBreak()).
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeType
- parameter: `majorType`, type: `int`
- parameter: `value`, type: `long`

Description: Encodes and writes the major type indicator with a given payload \(length\).
parameter: majorType: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeUInt
- parameter: `mt`, type: `int`
- parameter: `value`, type: `long`

Description: Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.
parameter: mt: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeUInt16
- parameter: `mt`, type: `int`
- parameter: `value`, type: `int`

Description: Encodes and writes an unsigned 16\-bit integer value
parameter: mt: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeUInt32
- parameter: `mt`, type: `int`
- parameter: `value`, type: `int`

Description: Encodes and writes an unsigned 32\-bit integer value
parameter: mt: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeUInt64
- parameter: `mt`, type: `int`
- parameter: `value`, type: `long`

Description: Encodes and writes an unsigned 64\-bit integer value
parameter: mt: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Protected Method: writeUInt8
- parameter: `mt`, type: `int`
- parameter: `value`, type: `int`

Description: Encodes and writes an unsigned 8\-bit integer value
parameter: mt: the major type of the value to write, denotes what semantics the written value has;
parameter: value: the value to write, values from [Long#MIN_VALUE](Long#MIN_VALUE) to [Long#MAX_VALUE](Long#MAX_VALUE) are supported.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

## Method: writeUndefined

Description: Writes an "undefined" value in canonical CBOR format.
throws: in case of I/O problems writing the CBOR\-encoded value to the underlying output stream.

