mirror of https://github.com/sbt/sbt.git
Extract serializeResponse
This commit is contained in:
parent
d3ef452a5f
commit
5f56fa9f14
|
|
@ -8,7 +8,7 @@
|
||||||
package sbt
|
package sbt
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import sjsonnew.JsonFormat
|
import sjsonnew.{ JsonFormat, JsonWriter }
|
||||||
import sjsonnew.support.scalajson.unsafe.{ Parser, Converter, CompactPrinter }
|
import sjsonnew.support.scalajson.unsafe.{ Parser, Converter, CompactPrinter }
|
||||||
import sjsonnew.shaded.scalajson.ast.unsafe.{ JValue, JObject, JString }
|
import sjsonnew.shaded.scalajson.ast.unsafe.{ JValue, JObject, JString }
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
@ -44,28 +44,28 @@ object Serialization {
|
||||||
/** This formats the message according to JSON-RPC. http://www.jsonrpc.org/specification */
|
/** This formats the message according to JSON-RPC. http://www.jsonrpc.org/specification */
|
||||||
private[sbt] def serializeResponseMessage(message: JsonRpcResponseMessage): Array[Byte] = {
|
private[sbt] def serializeResponseMessage(message: JsonRpcResponseMessage): Array[Byte] = {
|
||||||
import sbt.internal.protocol.codec.JsonRPCProtocol._
|
import sbt.internal.protocol.codec.JsonRPCProtocol._
|
||||||
val json: JValue = Converter.toJson[JsonRpcResponseMessage](message).get
|
serializeResponse(message)
|
||||||
val body = CompactPrinter(json)
|
|
||||||
val bodyBytes = body.getBytes("UTF-8")
|
|
||||||
|
|
||||||
(s"Content-Length: ${bodyBytes.size}\r\n" +
|
|
||||||
s"Content-Type: $VsCode\r\n" +
|
|
||||||
"\r\n" +
|
|
||||||
body).getBytes("UTF-8")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This formats the message according to JSON-RPC. http://www.jsonrpc.org/specification */
|
/** This formats the message according to JSON-RPC. http://www.jsonrpc.org/specification */
|
||||||
private[sbt] def serializeNotificationMessage(
|
private[sbt] def serializeNotificationMessage(
|
||||||
message: JsonRpcNotificationMessage): Array[Byte] = {
|
message: JsonRpcNotificationMessage,
|
||||||
|
): Array[Byte] = {
|
||||||
import sbt.internal.protocol.codec.JsonRPCProtocol._
|
import sbt.internal.protocol.codec.JsonRPCProtocol._
|
||||||
val json: JValue = Converter.toJson[JsonRpcNotificationMessage](message).get
|
serializeResponse(message)
|
||||||
val body = CompactPrinter(json)
|
}
|
||||||
val bodyBytes = body.getBytes("UTF-8")
|
|
||||||
|
|
||||||
(s"Content-Length: ${bodyBytes.size}\r\n" +
|
private[sbt] def serializeResponse[A: JsonWriter](message: A): Array[Byte] = {
|
||||||
s"Content-Type: $VsCode\r\n" +
|
val json: JValue = Converter.toJson[A](message).get
|
||||||
"\r\n" +
|
val body = CompactPrinter(json)
|
||||||
body).getBytes("UTF-8")
|
val bodyLength = body.getBytes("UTF-8").length
|
||||||
|
|
||||||
|
Iterator(
|
||||||
|
s"Content-Length: $bodyLength",
|
||||||
|
s"Content-Type: $VsCode",
|
||||||
|
"",
|
||||||
|
body
|
||||||
|
).mkString("\r\n").getBytes("UTF-8")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue