mirror of https://github.com/sbt/sbt.git
Split using newline. Also more error handling.
This commit is contained in:
parent
9557107c97
commit
ec0fe7bb21
|
|
@ -10,7 +10,7 @@ abstract class ClientConnection(connection: Socket) {
|
|||
|
||||
// TODO handle client disconnect
|
||||
private val running = new AtomicBoolean(true)
|
||||
private val delimiter = '\0'.toByte
|
||||
private val delimiter: Byte = '\n'.toByte
|
||||
|
||||
private val out = connection.getOutputStream
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.json4s.JsonAST.{ JArray, JString }
|
|||
import org.json4s._
|
||||
import org.json4s.JsonDSL._
|
||||
import org.json4s.native.JsonMethods._
|
||||
import org.json4s.ParserUtil.ParseException
|
||||
|
||||
object Serialization {
|
||||
|
||||
|
|
@ -40,15 +41,18 @@ object Serialization {
|
|||
/**
|
||||
* @return A command or an invalid input description
|
||||
*/
|
||||
def deserialize(bytes: Seq[Byte]): Either[String, Command] = {
|
||||
val json = parse(new String(bytes.toArray, "UTF-8"))
|
||||
def deserialize(bytes: Seq[Byte]): Either[String, Command] =
|
||||
try {
|
||||
val json = parse(new String(bytes.toArray, "UTF-8"))
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
(json \ "type").extract[String] match {
|
||||
case "command" => Right(Execution((json \ "command_line").extract[String]))
|
||||
case cmd => Left(s"Unknown command type $cmd")
|
||||
// TODO: is using extract safe?
|
||||
(json \ "type").extract[String] match {
|
||||
case "execution" => Right(Execution((json \ "command_line").extract[String]))
|
||||
case cmd => Left(s"Unknown command type $cmd")
|
||||
}
|
||||
} catch {
|
||||
case e: ParseException => Left(s"Parse error: ${e.getMessage}")
|
||||
case e: MappingException => Left(s"Missing type field")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ object Server {
|
|||
|
||||
val connection = new ClientConnection(socket) {
|
||||
override def onCommand(command: Command): Unit = {
|
||||
println(s"onCommand $command")
|
||||
commandQueue.add(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue