Skip to content
Snippets Groups Projects
Commit dce9d7d4 authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Added nullable return values

parent 81d7d95b
No related branches found
No related tags found
No related merge requests found
Showing
with 47 additions and 46 deletions
...@@ -26,7 +26,7 @@ interface Bindings { ...@@ -26,7 +26,7 @@ interface Bindings {
fun downloadAndVerifySignedNdf( fun downloadAndVerifySignedNdf(
environmentUrl: String, environmentUrl: String,
certificate: Certificate, certificate: Certificate,
): Ndf ): Ndf?
fun generateSecret(byteLength: Long): Password fun generateSecret(byteLength: Long): Password
...@@ -34,7 +34,7 @@ interface Bindings { ...@@ -34,7 +34,7 @@ interface Bindings {
sessionFileDirectory: String, sessionFileDirectory: String,
sessionPassword: Password, sessionPassword: Password,
cmixParams: CmixParams cmixParams: CmixParams
): CMix ): CMix?
fun newCmix( fun newCmix(
ndfJson: String, ndfJson: String,
...@@ -114,7 +114,7 @@ interface Bindings { ...@@ -114,7 +114,7 @@ interface Bindings {
fun getReceptionIdentity( fun getReceptionIdentity(
key: String, key: String,
e2eId: E2eId e2eId: E2eId
): ReceptionIdentity ): ReceptionIdentity?
fun newFileTransferManager( fun newFileTransferManager(
e2eId: E2eId, e2eId: E2eId,
...@@ -125,7 +125,7 @@ interface Bindings { ...@@ -125,7 +125,7 @@ interface Bindings {
fun getIdFromContact(contactData: ContactData): ByteArray fun getIdFromContact(contactData: ContactData): ByteArray
fun getPublicKeyFromContact(contactData: ContactData): ByteArray fun getPublicKeyFromContact(contactData: ContactData): ByteArray
fun getFactsFromContact(contactData: ContactData): Fact fun getFactsFromContact(contactData: ContactData): List<Fact>
fun setFactsOnContact(contactData: ContactData, fact: Fact): ContactData fun setFactsOnContact(contactData: ContactData, fact: Fact): ContactData
fun searchUd( fun searchUd(
...@@ -134,7 +134,7 @@ interface Bindings { ...@@ -134,7 +134,7 @@ interface Bindings {
listener: UdSearchResultListener, listener: UdSearchResultListener,
factsListJson: ByteArray, factsListJson: ByteArray,
singleRequestParamsJson: ByteArray singleRequestParamsJson: ByteArray
): SingleUseReport ): SingleUseReport?
fun lookupUd( fun lookupUd(
e2eId: E2eId, e2eId: E2eId,
...@@ -142,7 +142,7 @@ interface Bindings { ...@@ -142,7 +142,7 @@ interface Bindings {
listener: UdLookupResultListener, listener: UdLookupResultListener,
lookupId: UserId, lookupId: UserId,
singleRequestParamsJson: ByteArray singleRequestParamsJson: ByteArray
): SingleUseReport ): SingleUseReport?
fun multiLookupUd( fun multiLookupUd(
e2eId: E2eId, e2eId: E2eId,
...@@ -167,7 +167,7 @@ interface Bindings { ...@@ -167,7 +167,7 @@ interface Bindings {
payload: Payload, payload: Payload,
paramsJson: ByteArray, paramsJson: ByteArray,
listener: SingleUseResponseListener listener: SingleUseResponseListener
): SingleUseReport ): SingleUseReport?
fun updateCommonErrors(errorsJson: String) fun updateCommonErrors(errorsJson: String)
......
package io.elixxir.xxclient.bindings package io.elixxir.xxclient.bindings
import bindings.GroupChatProcessor
import io.elixxir.xxclient.backup.Backup import io.elixxir.xxclient.backup.Backup
import io.elixxir.xxclient.backup.BackupAdapter import io.elixxir.xxclient.backup.BackupAdapter
import io.elixxir.xxclient.callbacks.* import io.elixxir.xxclient.callbacks.*
...@@ -22,6 +21,7 @@ import io.elixxir.xxclient.groupchat.GroupChat ...@@ -22,6 +21,7 @@ import io.elixxir.xxclient.groupchat.GroupChat
import io.elixxir.xxclient.groupchat.GroupChatAdapter import io.elixxir.xxclient.groupchat.GroupChatAdapter
import io.elixxir.xxclient.models.* import io.elixxir.xxclient.models.*
import io.elixxir.xxclient.models.BindingsModel.Companion.decode import io.elixxir.xxclient.models.BindingsModel.Companion.decode
import io.elixxir.xxclient.models.BindingsModel.Companion.decodeArray
import io.elixxir.xxclient.models.BindingsModel.Companion.encode import io.elixxir.xxclient.models.BindingsModel.Companion.encode
import io.elixxir.xxclient.models.ReceiveFileCallbackAdapter import io.elixxir.xxclient.models.ReceiveFileCallbackAdapter
import io.elixxir.xxclient.userdiscovery.UserDiscovery import io.elixxir.xxclient.userdiscovery.UserDiscovery
...@@ -48,7 +48,7 @@ open class BindingsAdapter : Bindings { ...@@ -48,7 +48,7 @@ open class BindingsAdapter : Bindings {
override fun downloadAndVerifySignedNdf( override fun downloadAndVerifySignedNdf(
environmentUrl: String, environmentUrl: String,
certificate: Certificate certificate: Certificate
): Ndf { ): Ndf? {
return CoreBindings.downloadAndVerifySignedNdfWithUrl(environmentUrl, certificate) return CoreBindings.downloadAndVerifySignedNdfWithUrl(environmentUrl, certificate)
} }
...@@ -233,7 +233,7 @@ open class BindingsAdapter : Bindings { ...@@ -233,7 +233,7 @@ open class BindingsAdapter : Bindings {
) )
} }
override fun getReceptionIdentity(key: String, e2eId: E2eId): ReceptionIdentity { override fun getReceptionIdentity(key: String, e2eId: E2eId): ReceptionIdentity? {
return decode( return decode(
CoreBindings.loadReceptionIdentity(key, e2eId) CoreBindings.loadReceptionIdentity(key, e2eId)
) )
...@@ -263,8 +263,8 @@ open class BindingsAdapter : Bindings { ...@@ -263,8 +263,8 @@ open class BindingsAdapter : Bindings {
return CoreBindings.getPubkeyFromContact(contactData) return CoreBindings.getPubkeyFromContact(contactData)
} }
override fun getFactsFromContact(contactData: ContactData): Fact { override fun getFactsFromContact(contactData: ContactData): List<Fact> {
return decode( return decodeArray(
CoreBindings.getFactsFromContact(contactData) CoreBindings.getFactsFromContact(contactData)
) )
} }
...@@ -279,7 +279,7 @@ open class BindingsAdapter : Bindings { ...@@ -279,7 +279,7 @@ open class BindingsAdapter : Bindings {
listener: UdSearchResultListener, listener: UdSearchResultListener,
factsListJson: ByteArray, factsListJson: ByteArray,
singleRequestParamsJson: ByteArray singleRequestParamsJson: ByteArray
): SingleUseReport { ): SingleUseReport? {
val result = CoreBindings.searchUD( val result = CoreBindings.searchUD(
e2eId, e2eId,
udContact.encoded(), udContact.encoded(),
...@@ -296,7 +296,7 @@ open class BindingsAdapter : Bindings { ...@@ -296,7 +296,7 @@ open class BindingsAdapter : Bindings {
listener: UdLookupResultListener, listener: UdLookupResultListener,
lookupId: UserId, lookupId: UserId,
singleRequestParamsJson: ByteArray singleRequestParamsJson: ByteArray
): SingleUseReport { ): SingleUseReport? {
val result = CoreBindings.lookupUD( val result = CoreBindings.lookupUD(
e2eId, e2eId,
udContact.encoded(), udContact.encoded(),
...@@ -348,7 +348,7 @@ open class BindingsAdapter : Bindings { ...@@ -348,7 +348,7 @@ open class BindingsAdapter : Bindings {
payload: Payload, payload: Payload,
paramsJson: ByteArray, paramsJson: ByteArray,
listener: SingleUseResponseListener listener: SingleUseResponseListener
): SingleUseReport { ): SingleUseReport? {
val result = CoreBindings.transmitSingleUse( val result = CoreBindings.transmitSingleUse(
e2eId, e2eId,
recipient.encoded(), recipient.encoded(),
......
...@@ -14,8 +14,8 @@ open class BroadcastListenerAdapter( ...@@ -14,8 +14,8 @@ open class BroadcastListenerAdapter(
) : BroadcastListener by listener, BroadcastListenerBindings { ) : BroadcastListener by listener, BroadcastListenerBindings {
override fun callback(data: ByteArray?, error: Exception?) { override fun callback(data: ByteArray?, error: Exception?) {
listener.onBroadcast( parseModel<BroadcastMessage>(data, error).let {
parseModel(data, error) listener.onBroadcast(it)
) }
} }
} }
\ No newline at end of file
...@@ -13,10 +13,10 @@ open class MessageListenerAdapter( ...@@ -13,10 +13,10 @@ open class MessageListenerAdapter(
protected val listener: MessageListener protected val listener: MessageListener
) : Listener { ) : Listener {
override fun hear(message: ByteArray?) { override fun hear(message: ByteArray?) {
message?.let { message?.let { data ->
listener.onMessageReceived( decode<Message>(data)?.let {
decode(it) listener.onMessageReceived(it)
) }
} }
} }
......
...@@ -12,9 +12,9 @@ interface Channel { ...@@ -12,9 +12,9 @@ interface Channel {
val maxAsymmetricPayloadSize: Long val maxAsymmetricPayloadSize: Long
val maxPayloadSize: Long val maxPayloadSize: Long
fun broadcast(payload: Payload): BroadcastReport fun broadcast(payload: Payload): BroadcastReport?
fun broadcastAsymmetric(payload: Payload, privateKey: ByteArray): BroadcastReport fun broadcastAsymmetric(payload: Payload, privateKey: ByteArray): BroadcastReport?
fun get(): ChannelDef fun get(): ChannelDef?
fun listen(channel: Long, listener: BroadcastListener) fun listen(channel: Long, listener: BroadcastListener)
fun stop() fun stop()
} }
...@@ -25,19 +25,19 @@ open class ChannelAdapter(protected val channel: BindingsChannel) : Channel { ...@@ -25,19 +25,19 @@ open class ChannelAdapter(protected val channel: BindingsChannel) : Channel {
override val maxPayloadSize: Long override val maxPayloadSize: Long
get() = channel.maxPayloadSize() get() = channel.maxPayloadSize()
override fun broadcast(payload: Payload): BroadcastReport { override fun broadcast(payload: Payload): BroadcastReport? {
return decode( return decode(
channel.broadcast(payload) channel.broadcast(payload)
) )
} }
override fun broadcastAsymmetric(payload: Payload, privateKey: ByteArray): BroadcastReport { override fun broadcastAsymmetric(payload: Payload, privateKey: ByteArray): BroadcastReport? {
return decode( return decode(
channel.broadcastAsymmetric(payload, privateKey) channel.broadcastAsymmetric(payload, privateKey)
) )
} }
override fun get(): ChannelDef { override fun get(): ChannelDef? {
return decode( return decode(
channel.get() channel.get()
) )
......
...@@ -15,9 +15,9 @@ interface CMix { ...@@ -15,9 +15,9 @@ interface CMix {
val receptionRegistrationValidationSignature: ByteArray val receptionRegistrationValidationSignature: ByteArray
fun makeReceptionIdentity(): ByteArray fun makeReceptionIdentity(): ByteArray
fun makeLegacyReceptionIdentity(): ReceptionIdentity fun makeLegacyReceptionIdentity(): ReceptionIdentity?
fun isNetworkHealthy(): Boolean fun isNetworkHealthy(): Boolean
fun getNodeRegistrationStatus(): NodeRegistrationReport fun getNodeRegistrationStatus(): NodeRegistrationReport?
fun hasRunningProcesses(): Boolean fun hasRunningProcesses(): Boolean
fun getNetworkFollowerStatus(): NetworkFollowerStatus fun getNetworkFollowerStatus(): NetworkFollowerStatus
fun startNetworkFollower(timeoutMs: Long) fun startNetworkFollower(timeoutMs: Long)
...@@ -49,7 +49,7 @@ open class CMixAdapter(protected val cMix: CMixBindings) : CMix { ...@@ -49,7 +49,7 @@ open class CMixAdapter(protected val cMix: CMixBindings) : CMix {
return cMix.makeReceptionIdentity() return cMix.makeReceptionIdentity()
} }
override fun makeLegacyReceptionIdentity(): ReceptionIdentity { override fun makeLegacyReceptionIdentity(): ReceptionIdentity? {
return decode( return decode(
cMix.makeLegacyReceptionIdentity() cMix.makeLegacyReceptionIdentity()
) )
...@@ -59,7 +59,7 @@ open class CMixAdapter(protected val cMix: CMixBindings) : CMix { ...@@ -59,7 +59,7 @@ open class CMixAdapter(protected val cMix: CMixBindings) : CMix {
return cMix.isHealthy return cMix.isHealthy
} }
override fun getNodeRegistrationStatus(): NodeRegistrationReport { override fun getNodeRegistrationStatus(): NodeRegistrationReport? {
return decode( return decode(
cMix.nodeRegistrationStatus cMix.nodeRegistrationStatus
) )
......
...@@ -33,7 +33,7 @@ interface E2e { ...@@ -33,7 +33,7 @@ interface E2e {
fun resetAuthenticatedChannel(contact: Contact): RoundId fun resetAuthenticatedChannel(contact: Contact): RoundId
fun callAllReceivedRequests() fun callAllReceivedRequests()
fun getReceivedRequest(partnerId: UserId): Request fun getReceivedRequest(partnerId: UserId): Request?
fun deleteRequest(partnerId: UserId) fun deleteRequest(partnerId: UserId)
fun deleteAllRequests() fun deleteAllRequests()
fun deleteReceivedRequests() fun deleteReceivedRequests()
...@@ -54,7 +54,7 @@ interface E2e { ...@@ -54,7 +54,7 @@ interface E2e {
receiverId: UserId, receiverId: UserId,
payload: Payload, payload: Payload,
params: E2eParams params: E2eParams
): SendReport ): SendReport?
fun registerListener( fun registerListener(
senderId: UserId, senderId: UserId,
......
...@@ -75,7 +75,7 @@ open class E2eAdapter(protected val e2e: E2eBindings) : E2e{ ...@@ -75,7 +75,7 @@ open class E2eAdapter(protected val e2e: E2eBindings) : E2e{
e2e.callAllReceivedRequests() e2e.callAllReceivedRequests()
} }
override fun getReceivedRequest(partnerId: UserId): Request { override fun getReceivedRequest(partnerId: UserId): Request? {
return decode( return decode(
e2e.getReceivedRequest(partnerId) e2e.getReceivedRequest(partnerId)
) )
...@@ -122,7 +122,7 @@ open class E2eAdapter(protected val e2e: E2eBindings) : E2e{ ...@@ -122,7 +122,7 @@ open class E2eAdapter(protected val e2e: E2eBindings) : E2e{
receiverId: UserId, receiverId: UserId,
payload: Payload, payload: Payload,
params: E2eParams params: E2eParams
): SendReport { ): SendReport? {
val reportData = e2e.sendE2E( val reportData = e2e.sendE2E(
messageType.code, messageType.code,
receiverId, receiverId,
......
...@@ -13,11 +13,11 @@ interface GroupChat { ...@@ -13,11 +13,11 @@ interface GroupChat {
fun getGroup(groupId: ByteArray): Group fun getGroup(groupId: ByteArray): Group
fun getGroups(): List<Group> fun getGroups(): List<Group>
fun makeGroup(membership: ByteArray, message: ByteArray, name: ByteArray): GroupReport fun makeGroup(membership: ByteArray, message: ByteArray, name: ByteArray): GroupReport?
fun joinGroup(trackedGroupId: ByteArray) fun joinGroup(trackedGroupId: ByteArray)
fun leaveGroup(groupId: ByteArray) fun leaveGroup(groupId: ByteArray)
fun resendRequest(groupId: ByteArray): GroupReport fun resendRequest(groupId: ByteArray): GroupReport?
fun send(groupId: ByteArray, message: ByteArray, tag: String?): GroupSendReport fun send(groupId: ByteArray, message: ByteArray, tag: String?): GroupSendReport?
} }
open class GroupChatAdapter( open class GroupChatAdapter(
...@@ -40,7 +40,7 @@ open class GroupChatAdapter( ...@@ -40,7 +40,7 @@ open class GroupChatAdapter(
membership: ByteArray, membership: ByteArray,
message: ByteArray, message: ByteArray,
name: ByteArray name: ByteArray
): GroupReport { ): GroupReport? {
return decode( return decode(
group.makeGroup(membership, message, name) group.makeGroup(membership, message, name)
) )
...@@ -54,13 +54,13 @@ open class GroupChatAdapter( ...@@ -54,13 +54,13 @@ open class GroupChatAdapter(
group.leaveGroup(groupId) group.leaveGroup(groupId)
} }
override fun resendRequest(groupId: ByteArray): GroupReport { override fun resendRequest(groupId: ByteArray): GroupReport? {
return decode( return decode(
group.resendRequest(groupId) group.resendRequest(groupId)
) )
} }
override fun send(groupId: ByteArray, message: ByteArray, tag: String?): GroupSendReport { override fun send(groupId: ByteArray, message: ByteArray, tag: String?): GroupSendReport? {
return decode( return decode(
group.send(groupId, message, tag) group.send(groupId, message, tag)
) )
......
...@@ -17,13 +17,13 @@ interface BindingsModel { ...@@ -17,13 +17,13 @@ interface BindingsModel {
return Gson().toJson(list.toTypedArray(), typeToken).encodeToByteArray() return Gson().toJson(list.toTypedArray(), typeToken).encodeToByteArray()
} }
inline fun <reified T> decode(data: ByteArray): T { inline fun <reified T> decode(data: ByteArray): T? {
return if (data.isNotEmpty()) { return if (data.isNotEmpty()) {
val typeToken = object : TypeToken<T>() {}.type val typeToken = object : TypeToken<T>() {}.type
Gson().fromJson(data.decodeToString(), typeToken) Gson().fromJson(data.decodeToString(), typeToken)
} else { } else {
Log.d("Decode", "Failed to decode data: ${data.decodeToString()}") Log.d("Decode", "Failed to decode data: ${data.decodeToString()}")
throw InvalidDataException() null
} }
} }
......
...@@ -10,8 +10,9 @@ inline fun <reified T: BindingsModel> parseModel(data: ByteArray?, error: Except ...@@ -10,8 +10,9 @@ inline fun <reified T: BindingsModel> parseModel(data: ByteArray?, error: Except
return error?.let { return error?.let {
Result.failure(it) Result.failure(it)
} ?: data?.let { } ?: data?.let {
if (it.isNotEmpty()) Result.success(BindingsModel.decode(it)) BindingsModel.decode<T>(it)?.let { model ->
else Result.failure(NoResultsException()) Result.success(model)
} ?: Result.failure(NoResultsException())
} ?: Result.failure(InvalidDataException()) } ?: Result.failure(InvalidDataException())
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment