blob: bccba594093159dba516f384d67c404f058110d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package scalevalapokalypsi.Client
import scala.collection.mutable.Buffer
import scalevalapokalypsi.constants.*
import scalevalapokalypsi.utils.*
/** A class for checking asynchronously for received lines */
class ReceivedLineParser:
private var serverLineState = ServerLineState.ActionsAndSong
private var bufferedData: Buffer[Byte] = Buffer.empty // TODO: suboptimal DS
/** Add received data */
def in(data: Array[Byte]): Unit =
this.bufferedData ++= data
/** Read a line from the received data */
def nextLine(): Option[String] =
val indexOfCRLF = this.bufferedData.indexOfSlice(CRLF)
if indexOfCRLF == -1 then
None
else
val splitData = this.bufferedData.splitAt(indexOfCRLF)
this.bufferedData = Buffer.from(splitData(1).drop(CRLF.length))
byteArrayToString(splitData(0).toArray)
end ReceivedLineParser
|