Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaskougios committed Dec 12, 2023
1 parent 7574b23 commit 05d6a42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ class InOutMessageProtocol(invokerMap: InvokerMap):
buf.write(data)
buf

def transport(myId: Int, corId: Long, data: Array[Byte], argsData: Array[Byte], coordsData: Array[Byte]): BufferData =
val buf = BufferData.growing(data.length + argsData.length + coordsData.length + 32)
buf.writeInt32(myId)
buf.write(longToBytes(corId))
buf.writeUnsignedInt32(coordsData.length)
buf.write(coordsData)
buf.writeInt32(data.length)
buf.write(data)
buf.writeInt32(argsData.length)
buf.write(argsData)
buf

private def longToBytes(x: Long): Array[Byte] =
val buffer = new Array[Byte](8)
for (i <- 0 until 8)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package functions.helidon.transport

import functions.fibers.FiberExecutor
import functions.helidon.ws.InOutMessageProtocol
import functions.model.TransportInput
import io.helidon.common.buffers.BufferData
import io.helidon.websocket.WsListener
Expand All @@ -13,22 +14,14 @@ class HelidonWsTransport(fiberExecutor: FiberExecutor, sendResponseTimeoutInMill
private val myId = Random.nextInt()
private val wsListener = new ClientWsListener(myId, fiberExecutor, sendResponseTimeoutInMillis)
private val correlationId = new AtomicLong(0)
private val protocol = new InOutMessageProtocol(Map.empty)

def clientWsListener: WsListener = wsListener

def transportFunction(in: TransportInput): Array[Byte] =
val coordsData = in.coordinates4.toRawCoordinatesBytes
val corId = correlationId.incrementAndGet()

val buf = BufferData.growing(in.data.length + in.argsData.length + coordsData.length + 32)
buf.writeInt32(myId)
buf.write(longToBytes(corId))
buf.writeUnsignedInt32(coordsData.length)
buf.write(coordsData)
buf.writeInt32(in.data.length)
buf.write(in.data)
buf.writeInt32(in.argsData.length)
buf.write(in.argsData)
val buf = protocol.transport(myId, corId, in.data, in.argsData, coordsData)
wsListener.send(corId, in.coordinates4, buf)

def close(): Unit = wsListener.close()
Expand Down

0 comments on commit 05d6a42

Please sign in to comment.