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 Type
    Method
    Description
    byte[]
    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 a JsonValue by parsing the passed bytes with CBOR.
    readFrom(byte[] bytes, int offset, int length)
    Deserializes a JsonValue by parsing the passed bytes with CBOR applying a offset and length.
    readFrom(ByteBuffer byteBuffer)
    Deserializes a JsonValue by parsing the passed byteBuffer with CBOR.
    byte[]
    Serializes a CBOR byte array from the passed jsonValue.
    Serializes a CBOR ByteBuffer from the passed jsonValue.
    void
    writeToByteBuffer(JsonValue jsonValue, ByteBuffer byteBuffer)
    Serializes the passed jsonValue into the passed byteBuffer 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

      JsonValue readFrom(byte[] bytes)
      Deserializes a JsonValue by parsing the passed bytes with CBOR.
      Parameters:
      bytes - the bytes to parse with CBOR.
      Returns:
      the parsed JsonValue.
      Throws:
      JsonParseException - if the content of bytes cannot be deserialized to a JsonValue.
    • readFrom

      JsonValue readFrom(byte[] bytes, int offset, int length)
      Deserializes a JsonValue by parsing the passed bytes with CBOR applying a offset and length.
      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 of bytes cannot be deserialized to a JsonValue.
    • readFrom

      JsonValue readFrom(ByteBuffer byteBuffer)
      Deserializes a JsonValue by parsing the passed byteBuffer with CBOR.
      Parameters:
      byteBuffer - the ByteBuffer to parse with CBOR.
      Returns:
      the parsed JsonValue.
      Throws:
      JsonParseException - if the content of byteBuffer cannot be deserialized to a JsonValue.
    • toByteArray

      byte[] toByteArray(JsonValue jsonValue) throws IOException
      Serializes a CBOR byte array from the passed jsonValue.
      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

      ByteBuffer toByteBuffer(JsonValue jsonValue) throws IOException
      Serializes a CBOR ByteBuffer from the passed jsonValue.
      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

      void writeToByteBuffer(JsonValue jsonValue, ByteBuffer byteBuffer) throws IOException
      Serializes the passed jsonValue into the passed byteBuffer 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 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:
      IOException - in case writing the value to the backing OutputStream causes an IOException.
    • createCborRepresentation

      byte[] createCborRepresentation(List<JsonValue> list, int guessedSerializedSize) throws 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:
      IOException - in case writing the value to the backing OutputStream causes an IOException.