-
public interface MqttPersistableRepresents an object used to pass data to be persisted across the MqttClientPersistence interface.
When data is passed across the interface the header and payload are separated, so that unnecessary message copies may be avoided. For example, if a 10 MB payload was published it would be inefficient to create a byte array a few bytes larger than 10 MB and copy the MQTT message header and payload into a contiguous byte array.
When the request to persist data is made a separate byte array and offset is passed for the header and payload. Only the data between offset and length need be persisted. So for example, a message to be persisted consists of a header byte array starting at offset 1 and length 4, plus a payload byte array starting at offset 30 and length 40000. There are three ways in which the persistence implementation may return data to the client on recovery:
- It could return the data as it was passed in originally, with the same byte arrays and offsets.
- It could safely just persist and return the bytes from the offset for the specified length. For example, return a header byte array with offset 0 and length 4, plus a payload byte array with offset 0 and length 40000
- It could return the header and payload as a contiguous byte array with the header bytes preceeding the payload. The contiguous byte array should be set as the header byte array, with the payload byte array being null. For example, return a single byte array with offset 0 and length 40004. This is useful when recovering from a file where the header and payload could be written as a contiguous stream of bytes.
-
-
Method Summary
Modifier and Type Method Description abstract Array<byte>getHeaderBytes()Returns the header bytes in an array. abstract intgetHeaderLength()Returns the length of the header. abstract intgetHeaderOffset()Returns the offset of the header within the byte array returned by getHeaderBytes. abstract Array<byte>getPayloadBytes()Returns the payload bytes in an array. abstract intgetPayloadLength()Returns the length of the payload. abstract intgetPayloadOffset()Returns the offset of the payload within the byte array returned by getPayloadBytes. -
-
Method Detail
-
getHeaderBytes
abstract Array<byte> getHeaderBytes()
Returns the header bytes in an array. The bytes start at getHeaderOffset and continue for getHeaderLength.
-
getHeaderLength
abstract int getHeaderLength()
Returns the length of the header.
-
getHeaderOffset
abstract int getHeaderOffset()
Returns the offset of the header within the byte array returned by getHeaderBytes.
-
getPayloadBytes
abstract Array<byte> getPayloadBytes()
Returns the payload bytes in an array. The bytes start at getPayloadOffset and continue for getPayloadLength.
-
getPayloadLength
abstract int getPayloadLength()
Returns the length of the payload.
-
getPayloadOffset
abstract int getPayloadOffset()
Returns the offset of the payload within the byte array returned by getPayloadBytes.
-
-
-
-