Package org.eclipse.ditto.json
Interface CborFactory
-
public interface CborFactory
This interface abstracts serialization/deserialization via CBOR. Registration of an implementation is done via aServiceLoader
(putting a file namedorg.eclipse.ditto.json.CborFactory
inside theMETA-INF/services
directory of the providing module. UseisCborAvailable()
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]
createCborRepresentation(java.util.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(java.util.Map<java.lang.String,JsonField> jsonFieldMap, int guessedSerializedSize)
Creates the CBOR representation of the passed JSON fieldMap and the estimated required serialized size of it.boolean
isCborAvailable()
Determines whether the libraries providing CBOR serializations are available (classes can be loaded).JsonValue
readFrom(byte[] bytes)
Deserializes aJsonValue
by parsing the passedbytes
with CBOR.JsonValue
readFrom(byte[] bytes, int offset, int length)
Deserializes aJsonValue
by parsing the passedbytes
with CBOR applying aoffset
andlength
.JsonValue
readFrom(java.nio.ByteBuffer byteBuffer)
Deserializes aJsonValue
by parsing the passedbyteBuffer
with CBOR.byte[]
toByteArray(JsonValue jsonValue)
Serializes a CBOR byte array from the passedjsonValue
.java.nio.ByteBuffer
toByteBuffer(JsonValue jsonValue)
Serializes a CBOR ByteBuffer from the passedjsonValue
.void
writeToByteBuffer(JsonValue jsonValue, java.nio.ByteBuffer byteBuffer)
Serializes the passedjsonValue
into the passedbyteBuffer
applying CBOR.
-
-
-
Method Detail
-
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
JsonValue readFrom(byte[] bytes)
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
JsonValue readFrom(byte[] bytes, int offset, int length)
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
JsonValue readFrom(java.nio.ByteBuffer byteBuffer)
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
byte[] toByteArray(JsonValue jsonValue) throws java.io.IOException
Serializes a CBOR byte array from the passedjsonValue
.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.- Returns:
- the CBOR bytes.
- Throws:
java.io.IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
toByteBuffer
java.nio.ByteBuffer toByteBuffer(JsonValue jsonValue) throws java.io.IOException
Serializes a CBOR ByteBuffer from the passedjsonValue
.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.- Returns:
- the CBOR ByteBuffer.
- Throws:
java.io.IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
writeToByteBuffer
void writeToByteBuffer(JsonValue jsonValue, java.nio.ByteBuffer byteBuffer) throws java.io.IOException
Serializes the passedjsonValue
into the passedbyteBuffer
applying CBOR.- Parameters:
jsonValue
- the JsonValue to serialize into CBOR.byteBuffer
- the ByteBuffer to serialize into.- Throws:
java.io.IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
createCborRepresentation
byte[] createCborRepresentation(java.util.Map<java.lang.String,JsonField> jsonFieldMap, int guessedSerializedSize) throws java.io.IOException
Creates 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:
java.io.IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
createCborRepresentation
byte[] createCborRepresentation(java.util.List<JsonValue> list, int guessedSerializedSize) throws java.io.IOException
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:
java.io.IOException
- in case writing the value to the backing OutputStream causes an IOException.
-
-