Skip to content

Commit

Permalink
swift
Browse files Browse the repository at this point in the history
  • Loading branch information
humanagent committed Dec 23, 2023
1 parent 1cc82a3 commit 1a22123
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
71 changes: 49 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"identity" : "generic-json-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/zoul/generic-json-swift",
"location" : "https://github.com/iwill/generic-json-swift",
"state" : {
"revision" : "0a06575f4038b504e78ac330913d920f1630f510",
"version" : "2.0.2"
Expand Down Expand Up @@ -50,26 +50,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version" : "1.0.2"
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729",
"version" : "1.0.3"
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin.git",
"state" : {
"revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda",
"version" : "1.2.0"
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
Expand All @@ -81,67 +81,94 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "1827dc94bdab2eb5f2fc804e9b0cb43574282566",
"version" : "1.0.2"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c",
"version" : "1.4.4"
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "edfceecba13d68c1c993382806e72f7e96feaa86",
"version" : "2.44.0"
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
"version" : "2.62.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "798c962495593a23fdea0c0c63fd55571d8dff51",
"version" : "1.20.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "3bd9004b9d685ed6b629760fc84903e48efec806",
"version" : "1.29.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3",
"version" : "2.23.0"
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c",
"version" : "1.15.0"
"revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e",
"version" : "1.20.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8",
"version" : "1.20.3"
"revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8",
"version" : "1.25.2"
}
},
{
"identity" : "web3.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/argentlabs/web3.swift",
"state" : {
"revision" : "9da09d639d4e5d06eb59518e636b3ae957e8e9cd",
"version" : "1.3.0"
"revision" : "1e75f98a5738c470b23bbfffa9314e9f788df76b",
"version" : "1.6.1"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "2d9d2188a08eef4a869d368daab21b3c08510991",
"version" : "2.6.1"
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
}
},
{
Expand All @@ -150,7 +177,7 @@
"location" : "https://github.com/xmtp/xmtp-rust-swift",
"state" : {
"branch" : "main",
"revision" : "eb931c2f467c2a71a621f54d7ae22887b234c13a"
"revision" : "e08af6942841054ae02a6fe01d90d18e76d5f248"
}
}
],
Expand Down
38 changes: 5 additions & 33 deletions Tests/XMTPTests/MultiplyNumberCustomContentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ import XCTest
@testable import XMTP


public struct SingleNumberCodec: ContentCodec {


public typealias T = Double

public var contentType: ContentTypeID {
ContentTypeID(authorityID: "example.com", typeID: "number", versionMajor: 1, versionMinor: 1)
}

public func encode(content: Double, client _: Client) throws -> EncodedContent {
var encodedContent = EncodedContent()

encodedContent.type = ContentTypeID(authorityID: "example.com", typeID: "number", versionMajor: 1, versionMinor: 1)
encodedContent.content = try JSONEncoder().encode(content)

return encodedContent
}

public func decode(content: EncodedContent, client _: Client) throws -> Double {
let decoded = try JSONDecoder().decode(Double.self, from: content.content)
return decoded * 2
}
public func fallback(content: Double) throws -> String? {
return "SingleNumberCodec is not supported"
}
}


public struct MultiplyNumbers {
public var num1: Double
public var num2: Double
Expand All @@ -49,7 +21,7 @@ public struct MultiplyNumbers {
}
}

public struct MultiplyNumbersCodec: ContentCodec {
public struct ContentTypeMultiplyNumberCodec: ContentCodec {
public typealias T = MultiplyNumbers

public var contentType: ContentTypeID {
Expand All @@ -73,22 +45,22 @@ public struct MultiplyNumbersCodec: ContentCodec {
}

public func fallback(content: MultiplyNumbers) throws -> String? {
return "MultiplyNumbersCodec is not supported"
return "ContentTypeMultiplyNumberCodec is not supported"
}
}

@available(iOS 15, *)
class MultiplyNumberCustomContentType: XCTestCase {
func testCanRoundTripWithMultiplyNumbersCodec() async throws {
func testCanRoundTripWithContentTypeMultiplyNumberCodec() async throws {
let fixtures = await fixtures()

let aliceClient = fixtures.aliceClient!
let aliceConversation = try await aliceClient.conversations.newConversation(with: fixtures.bob.address)

aliceClient.register(codec: MultiplyNumbersCodec())
aliceClient.register(codec: ContentTypeMultiplyNumberCodec())

let multiplyNumbers = MultiplyNumbers(num1: 3, num2: 2)
try await aliceConversation.send(content: multiplyNumbers, options: .init(contentType: MultiplyNumbersCodec().contentType))
try await aliceConversation.send(content: multiplyNumbers, options: .init(contentType: ContentTypeMultiplyNumberCodec().contentType))

let messages = try await aliceConversation.messages()
XCTAssertEqual(messages.count, 1)
Expand Down

0 comments on commit 1a22123

Please sign in to comment.