privatedef read_line(): String =
Byte_Message.read_line(in) match { case Some(bytes) => bytes.text case None => ""
}
privatedef read_header(): List[String] = { val header = new mutable.ListBuffer[String] var line = "" while ({ line = read_line(); line.nonEmpty }) header += line
header.toList
}
privatedef read_content(n: Int): String = { val bytes = Bytes.read_stream(in, limit = n) if (bytes.size == n) bytes.text else error("Bad message content (unexpected EOF after " + bytes.size + " of " + n + " bytes)")
}
def read(): Option[JSON.T] = {
read_header() match { case Nil => None case Content_Length(s) :: _ =>
s match { case Value.Int(n) if n >= 0 => val msg = read_content(n) val json = JSON.parse(msg)
LSP.Message.log("IN: " + n, json, log, verbose)
Some(json) case _ => error("Bad Content-Length: " + s)
} case header => error(cat_lines("Malformed header:" :: header))
}
}
/* write message */
def write(json: JSON.T): Unit = { val content = JSON.Format.bytes(json) val n = content.size val header = UTF8.bytes("Content-Length: " + n + "\r\n\r\n")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.