Package org.eclipse.ditto.json
Interface CborFactory
public interface CborFactory
This interface abstracts serialization/deserialization via CBOR.
Registration of an implementation is done via a
ServiceLoader
(putting a file named
org.eclipse.ditto.json.CborFactory
inside the META-INF/services
directory of the providing module.
Use isCborAvailable()
in order to check for CBOR availability.
This is a Ditto internal class which is not intended for re-use. It therefore is not treated as API which is held binary compatible to previous versions.
- Since:
- 1.2.1
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
createCborRepresentation
(List<JsonValue> list, int guessedSerializedSize) Creates the CBOR representation of the passed JSON value list and the estimated required serialized size of it.byte[]
createCborRepresentation
(Map<String, JsonField> jsonFieldMap, int guessedSerializedSize) Creates the CBOR representation of the passed JSON fieldMap and the estimated required serialized size of it.boolean
Determines whether the libraries providing CBOR serializations are available (classes can be loaded).readFrom
(byte[] bytes) Deserializes aJsonValue
by parsing the passedbytes
with CBOR.readFrom
(byte[] bytes, int offset, int length) Deserializes aJsonValue
by parsing the passedbytes
with CBOR applying aoffset
andlength
.readFrom
(ByteBuffer byteBuffer) Deserializes aJsonValue
by parsing the passedbyteBuffer
with CBOR.byte[]
toByteArray
(JsonValue jsonValue) Serializes a CBOR byte array from the passedjsonValue
.toByteBuffer
(JsonValue jsonValue) Serializes a CBOR ByteBuffer from the passedjsonValue
.void
writeToByteBuffer
(JsonValue jsonValue, ByteBuffer byteBuffer) Serializes the passedjsonValue
into the passedbyteBuffer
applying CBOR.
-
Method Details
-
isCborAvailable
boolean isCborAvailable()Determines whether the libraries providing CBOR serializations are available (classes can be loaded).- Returns:
true
when CBOR is available and can be used for serialization.
-
readFrom
Deserializes aJsonValue
by parsing the passedbytes
with CBOR.- Parameters:
bytes
- the bytes to parse with CBOR.- Returns:
- the parsed JsonValue.
- Throws:
JsonParseException
- if the content ofbytes
cannot be deserialized to aJsonValue
.
-
readFrom
Deserializes aJsonValue
by parsing the passedbytes
with CBOR applying aoffset
andlength
.- Parameters:
bytes
- the bytes to parse with CBOR.offset
- the offset where to start reading from.length
- the length of how much bytes to read.- Returns:
- the parsed JsonValue.
- Throws:
JsonParseException
- if the content ofbytes
cannot be deserialized to aJsonValue
.
-
readFrom
Deserializes aJsonValue
by parsing the passedbyteBuffer
with CBOR.- Parameters:
byteBuffer
- the ByteBuffer to parse with CBOR.- Returns:
- the parsed JsonValue.
- Throws:
JsonParseException
- if the content ofbyteBuffer
cannot be deserialized to aJsonValue
.
-
toByteArray
Serializes a CBOR byte array from the passedjsonValue
.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.- Returns:
- the CBOR bytes.
- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
toByteBuffer
Serializes a CBOR ByteBuffer from the passedjsonValue
.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.- Returns:
- the CBOR ByteBuffer.
- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
writeToByteBuffer
Serializes the passedjsonValue
into the passedbyteBuffer
applying CBOR.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.byteBuffer
- the ByteBuffer to serialize into.- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
createCborRepresentation
byte[] createCborRepresentation(Map<String, JsonField> jsonFieldMap, int guessedSerializedSize) throws IOExceptionCreates the CBOR representation of the passed JSON fieldMap and the estimated required serialized size of it.- Parameters:
jsonFieldMap
- the map of JsonFields to create the CBOR representation for.guessedSerializedSize
- the estimated serialized size of the CBOR structure.- Returns:
- the CBOR representation as bytes.
- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
createCborRepresentation
Creates the CBOR representation of the passed JSON value list and the estimated required serialized size of it.- Parameters:
list
- the list of JsonValues to create the CBOR representation for.guessedSerializedSize
- the estimated serialized size of the CBOR structure.- Returns:
- the CBOR representation as bytes.
- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.
-