Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions live-objects/src/main/kotlin/io/ably/lib/objects/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ internal fun LiveObjectsAdapter.ensureMessageSizeWithinLimit(objectMessages: Arr
}
}

internal enum class ProtocolMessageFormat(private val value: String) {
Msgpack("msgpack"),
Json("json");

override fun toString(): String = value
}

internal class Binary(val data: ByteArray) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
16 changes: 4 additions & 12 deletions live-objects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.google.gson.JsonObject

import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import io.ably.lib.objects.serialization.InitialValueJsonSerializer
import io.ably.lib.objects.serialization.ObjectDataJsonSerializer
import io.ably.lib.objects.serialization.gson

Expand Down Expand Up @@ -212,20 +211,13 @@ internal data class ObjectOperation(
val nonce: String? = null,

/**
* The initial value bytes for the object. These bytes should be used along with the nonce
* The initial value json string for the object. This value should be used along with the nonce
* and timestamp to create the object ID. Frontdoor will use this to verify the object ID.
* After verification the bytes will be decoded into the Map or Counter objects and
* the initialValue, nonce, and initialValueEncoding will be removed.
* After verification the json string will be decoded into the Map or Counter objects and
* the initialValue and nonce will be removed.
* Spec: OOP3h
*/
@JsonAdapter(InitialValueJsonSerializer::class)
val initialValue: Binary? = null,

/** The initial value encoding defines how the initialValue should be interpreted.
* Spec: OOP3i
*/
@Deprecated("Will be removed in the future, initialValue will be json string")
val initialValueEncoding: ProtocolMessageFormat? = null
val initialValue: String? = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,3 @@ internal class ObjectDataJsonSerializer : JsonSerializer<ObjectData>, JsonDeseri
return ObjectData(objectId, value)
}
}

internal class InitialValueJsonSerializer : JsonSerializer<Binary>, JsonDeserializer<Binary> {
override fun serialize(src: Binary, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
return JsonPrimitive(Base64.getEncoder().encodeToString(src.data))
}

override fun deserialize(json: JsonElement, typeOfT: Type?, context: JsonDeserializationContext?): Binary {
return Binary(Base64.getDecoder().decode(json.asString))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import io.ably.lib.objects.ObjectOperation
import io.ably.lib.objects.ObjectOperationAction
import io.ably.lib.objects.ObjectState
import io.ably.lib.objects.ObjectValue
import io.ably.lib.objects.ProtocolMessageFormat
import io.ably.lib.util.Serialisation
import org.msgpack.core.MessageFormat
import org.msgpack.core.MessagePacker
Expand Down Expand Up @@ -158,7 +157,6 @@ private fun ObjectOperation.writeMsgpack(packer: MessagePacker) {
if (counter != null) fieldCount++
if (nonce != null) fieldCount++
if (initialValue != null) fieldCount++
if (initialValueEncoding != null) fieldCount++

packer.packMapHeader(fieldCount)

Expand Down Expand Up @@ -196,13 +194,7 @@ private fun ObjectOperation.writeMsgpack(packer: MessagePacker) {

if (initialValue != null) {
packer.packString("initialValue")
packer.packBinaryHeader(initialValue.data.size)
packer.writePayload(initialValue.data)
}

if (initialValueEncoding != null) {
packer.packString("initialValueEncoding")
packer.packString(initialValueEncoding.name)
packer.packString(initialValue)
}
}

Expand All @@ -219,8 +211,7 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
var map: ObjectMap? = null
var counter: ObjectCounter? = null
var nonce: String? = null
var initialValue: Binary? = null
var initialValueEncoding: ProtocolMessageFormat? = null
var initialValue: String? = null

for (i in 0 until fieldCount) {
val fieldName = unpacker.unpackString().intern()
Expand All @@ -243,13 +234,7 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
"map" -> map = readObjectMap(unpacker)
"counter" -> counter = readObjectCounter(unpacker)
"nonce" -> nonce = unpacker.unpackString()
"initialValue" -> {
val size = unpacker.unpackBinaryHeader()
val bytes = ByteArray(size)
unpacker.readPayload(bytes)
initialValue = Binary(bytes)
}
"initialValueEncoding" -> initialValueEncoding = ProtocolMessageFormat.valueOf(unpacker.unpackString())
"initialValue" -> initialValue = unpacker.unpackString()
else -> unpacker.skipValue()
}
}
Expand All @@ -267,7 +252,6 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
counter = counter,
nonce = nonce,
initialValue = initialValue,
initialValueEncoding = initialValueEncoding
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class ObjectMessageSizeTest {
), // Total ObjectCounter size: 8 bytes

nonce = "nonce123", // Not counted in operation size
initialValue = Binary("some-value".toByteArray()), // Not counted in operation size
initialValueEncoding = ProtocolMessageFormat.Json // Not counted in operation size
initialValue = "some-value", // Not counted in operation size
), // Total ObjectOperation size: 12 + 8 + 26 + 8 = 54 bytes

objectState = ObjectState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal val dummyObjectOperation = ObjectOperation(
map = dummyObjectMap,
counter = dummyObjectCounter,
nonce = "dummy-nonce",
initialValue = Binary("{\"foo\":\"bar\"}".toByteArray())
initialValue = "{\"foo\":\"bar\"}"
)

internal val dummyObjectState = ObjectState(
Expand Down
Loading