Skip to content

Commit 59cb308

Browse files
authored
Merge pull request #1112 from ably/fix/remove-initialValueEncoding-field
[ECO-5421] Remove initialValueEncoding field
2 parents e6af916 + 563392d commit 59cb308

6 files changed

Lines changed: 9 additions & 51 deletions

File tree

live-objects/src/main/kotlin/io/ably/lib/objects/Helpers.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ internal fun LiveObjectsAdapter.ensureMessageSizeWithinLimit(objectMessages: Arr
3232
}
3333
}
3434

35-
internal enum class ProtocolMessageFormat(private val value: String) {
36-
Msgpack("msgpack"),
37-
Json("json");
38-
39-
override fun toString(): String = value
40-
}
41-
4235
internal class Binary(val data: ByteArray) {
4336
override fun equals(other: Any?): Boolean {
4437
if (this === other) return true

live-objects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject
55

66
import com.google.gson.annotations.JsonAdapter
77
import com.google.gson.annotations.SerializedName
8-
import io.ably.lib.objects.serialization.InitialValueJsonSerializer
98
import io.ably.lib.objects.serialization.ObjectDataJsonSerializer
109
import io.ably.lib.objects.serialization.gson
1110

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

214213
/**
215-
* The initial value bytes for the object. These bytes should be used along with the nonce
214+
* The initial value json string for the object. This value should be used along with the nonce
216215
* and timestamp to create the object ID. Frontdoor will use this to verify the object ID.
217-
* After verification the bytes will be decoded into the Map or Counter objects and
218-
* the initialValue, nonce, and initialValueEncoding will be removed.
216+
* After verification the json string will be decoded into the Map or Counter objects and
217+
* the initialValue and nonce will be removed.
219218
* Spec: OOP3h
220219
*/
221-
@JsonAdapter(InitialValueJsonSerializer::class)
222-
val initialValue: Binary? = null,
223-
224-
/** The initial value encoding defines how the initialValue should be interpreted.
225-
* Spec: OOP3i
226-
*/
227-
@Deprecated("Will be removed in the future, initialValue will be json string")
228-
val initialValueEncoding: ProtocolMessageFormat? = null
220+
val initialValue: String? = null,
229221
)
230222

231223
/**

live-objects/src/main/kotlin/io/ably/lib/objects/serialization/JsonSerialization.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,3 @@ internal class ObjectDataJsonSerializer : JsonSerializer<ObjectData>, JsonDeseri
8787
return ObjectData(objectId, value)
8888
}
8989
}
90-
91-
internal class InitialValueJsonSerializer : JsonSerializer<Binary>, JsonDeserializer<Binary> {
92-
override fun serialize(src: Binary, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
93-
return JsonPrimitive(Base64.getEncoder().encodeToString(src.data))
94-
}
95-
96-
override fun deserialize(json: JsonElement, typeOfT: Type?, context: JsonDeserializationContext?): Binary {
97-
return Binary(Base64.getDecoder().decode(json.asString))
98-
}
99-
}

live-objects/src/main/kotlin/io/ably/lib/objects/serialization/MsgpackSerialization.kt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import io.ably.lib.objects.ObjectOperation
1717
import io.ably.lib.objects.ObjectOperationAction
1818
import io.ably.lib.objects.ObjectState
1919
import io.ably.lib.objects.ObjectValue
20-
import io.ably.lib.objects.ProtocolMessageFormat
2120
import io.ably.lib.util.Serialisation
2221
import org.msgpack.core.MessageFormat
2322
import org.msgpack.core.MessagePacker
@@ -158,7 +157,6 @@ private fun ObjectOperation.writeMsgpack(packer: MessagePacker) {
158157
if (counter != null) fieldCount++
159158
if (nonce != null) fieldCount++
160159
if (initialValue != null) fieldCount++
161-
if (initialValueEncoding != null) fieldCount++
162160

163161
packer.packMapHeader(fieldCount)
164162

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

197195
if (initialValue != null) {
198196
packer.packString("initialValue")
199-
packer.packBinaryHeader(initialValue.data.size)
200-
packer.writePayload(initialValue.data)
201-
}
202-
203-
if (initialValueEncoding != null) {
204-
packer.packString("initialValueEncoding")
205-
packer.packString(initialValueEncoding.name)
197+
packer.packString(initialValue)
206198
}
207199
}
208200

@@ -219,8 +211,7 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
219211
var map: ObjectMap? = null
220212
var counter: ObjectCounter? = null
221213
var nonce: String? = null
222-
var initialValue: Binary? = null
223-
var initialValueEncoding: ProtocolMessageFormat? = null
214+
var initialValue: String? = null
224215

225216
for (i in 0 until fieldCount) {
226217
val fieldName = unpacker.unpackString().intern()
@@ -243,13 +234,7 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
243234
"map" -> map = readObjectMap(unpacker)
244235
"counter" -> counter = readObjectCounter(unpacker)
245236
"nonce" -> nonce = unpacker.unpackString()
246-
"initialValue" -> {
247-
val size = unpacker.unpackBinaryHeader()
248-
val bytes = ByteArray(size)
249-
unpacker.readPayload(bytes)
250-
initialValue = Binary(bytes)
251-
}
252-
"initialValueEncoding" -> initialValueEncoding = ProtocolMessageFormat.valueOf(unpacker.unpackString())
237+
"initialValue" -> initialValue = unpacker.unpackString()
253238
else -> unpacker.skipValue()
254239
}
255240
}
@@ -267,7 +252,6 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
267252
counter = counter,
268253
nonce = nonce,
269254
initialValue = initialValue,
270-
initialValueEncoding = initialValueEncoding
271255
)
272256
}
273257

live-objects/src/test/kotlin/io/ably/lib/objects/unit/ObjectMessageSizeTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ class ObjectMessageSizeTest {
8181
), // Total ObjectCounter size: 8 bytes
8282

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

8887
objectState = ObjectState(

live-objects/src/test/kotlin/io/ably/lib/objects/unit/fixtures/ObjectMessageFixtures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal val dummyObjectOperation = ObjectOperation(
5555
map = dummyObjectMap,
5656
counter = dummyObjectCounter,
5757
nonce = "dummy-nonce",
58-
initialValue = Binary("{\"foo\":\"bar\"}".toByteArray())
58+
initialValue = "{\"foo\":\"bar\"}"
5959
)
6060

6161
internal val dummyObjectState = ObjectState(

0 commit comments

Comments
 (0)