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
a0437bc3
Commit
a0437bc3
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Convert big ints in UdSearchResult JSON to strings
parent
9a3e5d90
No related branches found
No related tags found
2 merge requests
!102
Release 1.0.0
,
!40
Fix user discovery search
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/XXClient/Models/UDSearchResult.swift
+19
-2
19 additions, 2 deletions
Sources/XXClient/Models/UDSearchResult.swift
Tests/XXClientTests/Models/UDSearchResultTests.swift
+26
-0
26 additions, 0 deletions
Tests/XXClientTests/Models/UDSearchResultTests.swift
with
45 additions
and
2 deletions
Sources/XXClient/Models/UDSearchResult.swift
+
19
−
2
View file @
a0437bc3
...
...
@@ -20,7 +20,8 @@ extension UDSearchResult: Codable {
}
public
static
func
decode
(
_
data
:
Data
)
throws
->
Self
{
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
let
data
=
convertBigIntsToStrings
(
jsonData
:
data
)
return
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
}
public
func
encode
()
throws
->
Data
{
...
...
@@ -30,10 +31,26 @@ extension UDSearchResult: Codable {
extension
Array
where
Element
==
UDSearchResult
{
public
static
func
decode
(
_
data
:
Data
)
throws
->
Self
{
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
let
data
=
convertBigIntsToStrings
(
jsonData
:
data
)
return
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
}
public
func
encode
()
throws
->
Data
{
try
JSONEncoder
()
.
encode
(
self
)
}
}
private
func
convertBigIntsToStrings
(
jsonData
input
:
Data
)
->
Data
{
guard
var
string
=
String
(
data
:
input
,
encoding
:
.
utf8
)
else
{
return
input
}
string
=
string
.
replacingOccurrences
(
of
:
#
":
\
s*([0-9]{19,})
\
s*,"
#
,
with
:
#
": "
$1
","
#
,
options
:
[
.
regularExpression
]
)
guard
let
output
=
string
.
data
(
using
:
.
utf8
)
else
{
return
input
}
return
output
}
This diff is collapsed.
Click to expand it.
Tests/XXClientTests/Models/UDSearchResultTests.swift
+
26
−
0
View file @
a0437bc3
...
...
@@ -42,4 +42,30 @@ final class UDSearchResultTests: XCTestCase {
XCTAssertNoDifference
(
decodedModels
,
models
)
}
func
testEncodeWithBigInt
()
throws
{
let
idB64
=
"pYIpRwPy+FnOkl5tndkG8RC93W/t5b1lszqPpMDynlUD"
let
facts
:
[
Fact
]
=
[
Fact
(
fact
:
"carlos_arimateias"
,
type
:
0
),
]
let
jsonString
=
"""
{
"
ID
": "
\(
idB64
)
",
"
DhPubKey
": {
"
Value
": 1759426033802606996617132861414734059978289057332806031357800676138355264622676606691435603603751978195460163638145821347601916259127578968570412642641025630452893097179266022832268525346700655861033031712000288680395716922501450233258587788020541937373196899001184700899008948530359980753630443486308876999029238453979779103124291315202352475056237021681172884599194016245219278368648568458514708567045834427853469072638665888791358582182353417065794210125797368093469194927663862565508608719835557592421245749381164023134450699040591219966988201315627676532245052123725278573237006510683695959381015415110970848376498637637944431576313526294020390694483472829278364602405292767170719547347485307956614210210673321959886410245334772057212077704024337636501108566655549055129066343309591274727538343075929837698653965640646190405582788894021694347212874155979958144038307500444865955516612526623220973497735316081265793063949,
"
Fingerprint
": 15989433043166758754
},
"
OwnershipProof
": null,
"
Facts
":
\(
String
(
data
:
try!
facts
.
encode
(),
encoding
:
.
utf8
)
!
)
}
"""
let
jsonData
=
jsonString
.
data
(
using
:
.
utf8
)
!
let
decodedModel
=
try
UDSearchResult
.
decode
(
jsonData
)
XCTAssertNoDifference
(
decodedModel
,
UDSearchResult
(
id
:
Data
(
base64Encoded
:
idB64
)
!
,
facts
:
facts
))
}
}
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