Skip to content

Commit 239a2fa

Browse files
Encode and decode data of WireObject
Based on [1] at 2e975cb. This was implemented by updating the code to reflect the internal API that I wanted to exist, and then asking Cursor to implement the rules of the spec and to write tests. I then edited the generated code to simplify it a bit and add things like @SPEC annotations and other explanatory comments. I wanted some round-trip tests that go through the Realtime backend but decided to leave them until later once I have a bit more knowledge of the LiveObjects protocol; have created #17. [1] ably/specification#335
1 parent 7f2f311 commit 239a2fa

7 files changed

Lines changed: 876 additions & 57 deletions

File tree

Sources/AblyLiveObjects/Internal/DefaultInternalPlugin.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ internal final class DefaultInternalPlugin: NSObject, AblyPlugin.LiveObjectsInte
6060
internal func decodeObjectMessage(
6161
_ serialized: [String: Any],
6262
context: DecodingContextProtocol,
63-
// TODO: use
6463
format: EncodingFormat,
6564
error errorPtr: AutoreleasingUnsafeMutablePointer<ARTErrorInfo?>?,
6665
) -> (any ObjectMessageProtocol)? {
@@ -71,7 +70,10 @@ internal final class DefaultInternalPlugin: NSObject, AblyPlugin.LiveObjectsInte
7170
wireObject: wireObject,
7271
decodingContext: context,
7372
)
74-
let objectMessage = InboundObjectMessage(wireObjectMessage: wireObjectMessage)
73+
let objectMessage = try InboundObjectMessage(
74+
wireObjectMessage: wireObjectMessage,
75+
format: format,
76+
)
7577
return ObjectMessageBox(objectMessage: objectMessage)
7678
} catch {
7779
errorPtr?.pointee = error.toARTErrorInfo()
@@ -81,14 +83,13 @@ internal final class DefaultInternalPlugin: NSObject, AblyPlugin.LiveObjectsInte
8183

8284
internal func encodeObjectMessage(
8385
_ publicObjectMessage: any AblyPlugin.ObjectMessageProtocol,
84-
// TODO: use
8586
format: EncodingFormat,
8687
) -> [String: Any] {
8788
guard let outboundObjectMessageBox = publicObjectMessage as? ObjectMessageBox<OutboundObjectMessage> else {
8889
preconditionFailure("Expected to receive the same OutboundObjectMessage type as we emit")
8990
}
9091

91-
let wireObjectMessage = outboundObjectMessageBox.objectMessage.toWire()
92+
let wireObjectMessage = outboundObjectMessageBox.objectMessage.toWire(format: format)
9293
return wireObjectMessage.toWireObject.toAblyPluginDataDictionary
9394
}
9495

0 commit comments

Comments
 (0)