Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Kotlin
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
android
Elixxir dApps SDK Kotlin
Commits
87f3440f
Commit
87f3440f
authored
2 years ago
by
Kamal Bramwell
Browse files
Options
Downloads
Patches
Plain Diff
Check for empty data before deserializing
parent
85fd9dbf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
xxclient/src/main/java/io/elixxir/xxclient/models/BindingsModel.kt
+13
-4
13 additions, 4 deletions
...src/main/java/io/elixxir/xxclient/models/BindingsModel.kt
with
13 additions
and
4 deletions
xxclient/src/main/java/io/elixxir/xxclient/models/BindingsModel.kt
+
13
−
4
View file @
87f3440f
package
io.elixxir.xxclient.models
import
android.util.Log
import
com.google.gson.Gson
import
com.google.gson.reflect.TypeToken
import
io.elixxir.xxclient.utils.toBase64String
interface
BindingsModel
{
...
...
@@ -16,13 +18,20 @@ interface BindingsModel {
}
inline
fun
<
reified
T
>
decode
(
data
:
ByteArray
):
T
{
return
if
(
data
.
isNotEmpty
())
{
val
typeToken
=
object
:
TypeToken
<
T
>()
{}.
type
return
Gson
().
fromJson
(
data
.
decodeToString
(),
typeToken
)
Gson
().
fromJson
(
data
.
decodeToString
(),
typeToken
)
}
else
{
Log
.
d
(
"Decode"
,
"Failed to decode data: ${data.decodeToString()}"
)
throw
InvalidDataException
()
}
}
inline
fun
<
reified
T
>
decodeArray
(
data
:
ByteArray
):
List
<
T
>
{
return
if
(
data
.
isNotEmpty
())
{
val
typeToken
=
object
:
TypeToken
<
Array
<
T
>>()
{}.
type
return
Gson
().
fromJson
<
Array
<
T
>>(
data
.
decodeToString
(),
typeToken
).
toList
()
Gson
().
fromJson
<
Array
<
T
>>(
data
.
decodeToString
(),
typeToken
).
toList
()
}
else
listOf
()
}
}
}
\ No newline at end of file
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