mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
fix: dynamic output buffer size, reusing the byte array buffer and only copying the written part to persistence
This commit is contained in:
parent
bf4a94a20e
commit
32f9675fe4
@ -83,14 +83,14 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
|||||||
//serialize Message and Destination properties
|
//serialize Message and Destination properties
|
||||||
val kryo = Kryo()
|
val kryo = Kryo()
|
||||||
kryo.isRegistrationRequired = false
|
kryo.isRegistrationRequired = false
|
||||||
val serializedMessage = ByteArray(4096)
|
val output = Output(ByteArray(4096), -1) // maxBufferSize '-1' will dynamically grow internally if we run out of room serializing the message
|
||||||
val serializedDestination = ByteArray(4096)
|
|
||||||
var output = Output(serializedMessage)
|
|
||||||
kryo.writeClassAndObject(output, message)
|
kryo.writeClassAndObject(output, message)
|
||||||
output.close()
|
output.close()
|
||||||
output = Output(serializedDestination)
|
val serializedMessage = output.toBytes()
|
||||||
|
output.clear()
|
||||||
kryo.writeClassAndObject(output, destination)
|
kryo.writeClassAndObject(output, destination)
|
||||||
output.close()
|
output.close()
|
||||||
|
val serializedDestination = output.toBytes()
|
||||||
return Data.Builder().putByteArray(KEY_MESSAGE, serializedMessage)
|
return Data.Builder().putByteArray(KEY_MESSAGE, serializedMessage)
|
||||||
.putByteArray(KEY_DESTINATION, serializedDestination)
|
.putByteArray(KEY_DESTINATION, serializedDestination)
|
||||||
.build();
|
.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user