Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
00ad3639
Commit
00ad3639
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add MessageSendReport codable model
parent
0f945331
No related branches found
No related tags found
1 merge request
!3
Bindings models wrapper
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/ElixxirDAppsSDK/MessageSendReport.swift
+51
-0
51 additions, 0 deletions
Sources/ElixxirDAppsSDK/MessageSendReport.swift
Tests/ElixxirDAppsSDKTests/MessageSendReportTests.swift
+35
-0
35 additions, 0 deletions
Tests/ElixxirDAppsSDKTests/MessageSendReportTests.swift
with
86 additions
and
0 deletions
Sources/ElixxirDAppsSDK/MessageSendReport.swift
0 → 100644
+
51
−
0
View file @
00ad3639
import
Foundation
public
struct
MessageSendReport
:
Equatable
{
public
init
(
roundList
:
[
Int
],
messageId
:
Data
,
timestamp
:
Int
)
{
self
.
roundList
=
roundList
self
.
messageId
=
messageId
self
.
timestamp
=
timestamp
}
public
var
roundList
:
[
Int
]
public
var
messageId
:
Data
public
var
timestamp
:
Int
}
extension
MessageSendReport
:
Codable
{
enum
CodingKeys
:
String
,
CodingKey
{
case
roundList
=
"RoundList"
case
messageId
=
"MessageID"
case
timestamp
=
"Timestamp"
}
enum
RoundListCodingKeys
:
String
,
CodingKey
{
case
rounds
=
"Rounds"
}
public
init
(
from
decoder
:
Decoder
)
throws
{
let
container
=
try
decoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
messageId
=
try
container
.
decode
(
Data
.
self
,
forKey
:
.
messageId
)
timestamp
=
try
container
.
decode
(
Int
.
self
,
forKey
:
.
timestamp
)
let
roundListContainer
=
try
container
.
nestedContainer
(
keyedBy
:
RoundListCodingKeys
.
self
,
forKey
:
.
roundList
)
roundList
=
try
roundListContainer
.
decode
([
Int
]
.
self
,
forKey
:
.
rounds
)
}
public
func
encode
(
to
encoder
:
Encoder
)
throws
{
var
container
=
encoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
try
container
.
encode
(
messageId
,
forKey
:
.
messageId
)
try
container
.
encode
(
timestamp
,
forKey
:
.
timestamp
)
var
roundListContainer
=
container
.
nestedContainer
(
keyedBy
:
RoundListCodingKeys
.
self
,
forKey
:
.
roundList
)
try
roundListContainer
.
encode
(
roundList
,
forKey
:
.
rounds
)
}
}
This diff is collapsed.
Click to expand it.
Tests/ElixxirDAppsSDKTests/MessageSendReportTests.swift
0 → 100644
+
35
−
0
View file @
00ad3639
import
CustomDump
import
XCTest
@testable
import
ElixxirDAppsSDK
final
class
MessageSendReportTests
:
XCTestCase
{
func
testCoding
()
throws
{
let
messageId
=
secureRandomData
(
count
:
32
)
let
jsonString
=
"""
{
"
RoundList
": {
"
Rounds
": [1,5,9]
},
"
MessageID
":
\(
messageId
.
jsonEncodedBase64
()
)
,
"
Timestamp
": 1653582683183384000
}
"""
let
jsonData
=
jsonString
.
data
(
using
:
.
utf8
)
!
let
decoder
=
JSONDecoder
()
decoder
.
dataDecodingStrategy
=
.
base64
let
report
=
try
decoder
.
decode
(
MessageSendReport
.
self
,
from
:
jsonData
)
XCTAssertNoDifference
(
report
,
MessageSendReport
(
roundList
:
[
1
,
5
,
9
],
messageId
:
messageId
,
timestamp
:
1_653_582_683_183_384_000
))
let
encoder
=
JSONEncoder
()
encoder
.
dataEncodingStrategy
=
.
base64
let
encodedReport
=
try
encoder
.
encode
(
report
)
let
decodedReport
=
try
decoder
.
decode
(
MessageSendReport
.
self
,
from
:
encodedReport
)
XCTAssertNoDifference
(
decodedReport
,
report
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment