Skip to content

Commit

Permalink
json, msgpack (feature): Scala Native support (#3505)
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial authored Apr 23, 2024
1 parent 9eca356 commit 689ef45
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package wvlet.airframe.msgpack.spi
import java.io.{InputStream, OutputStream}

import wvlet.airframe.msgpack.impl.{PureScalaBufferPacker, PureScalaBufferUnpacker}
import wvlet.airframe.msgpack.io.ByteArrayBuffer

/**
* Compatibility layer for Scala.js
*/
object Compat:
def isScalaJS = false

def floatToIntBits(v: Float): Int = java.lang.Float.floatToIntBits(v)
def doubleToLongBits(v: Double): Long = java.lang.Double.doubleToLongBits(v)

def newBufferPacker: BufferPacker =
new PureScalaBufferPacker
def newPacker(out: OutputStream): Packer = ???
def newUnpacker(in: InputStream): Unpacker = ???
def newUnpacker(msgpack: Array[Byte]): Unpacker =
newUnpacker(msgpack, 0, msgpack.length)
def newUnpacker(msgpack: Array[Byte], offset: Int, len: Int): Unpacker =
new PureScalaBufferUnpacker(ByteArrayBuffer.fromArray(msgpack, offset, len))
12 changes: 10 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ lazy val nativeProjects: Seq[ProjectReference] = Seq(
surface.native,
di.native,
metrics.native,
json.native,
msgpack.native,
ulid.native
)

Expand Down Expand Up @@ -634,7 +636,7 @@ lazy val metrics =
.dependsOn(log, surface)

lazy val msgpack =
crossProject(JVMPlatform, JSPlatform)
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("airframe-msgpack"))
.settings(buildSettings)
Expand All @@ -650,6 +652,11 @@ lazy val msgpack =
libraryDependencies +=
("org.scala-js" %%% "scalajs-java-time" % JS_JAVA_TIME_VERSION).cross(CrossVersion.for3Use2_13)
)
.nativeSettings(
nativeBuildSettings,
// For using java.time libraries
libraryDependencies += "org.ekrich" %%% "sjavatime" % "1.3.0"
)
.dependsOn(log, json)

lazy val codec =
Expand Down Expand Up @@ -850,7 +857,7 @@ lazy val httpRecorder =
.dependsOn(codec.jvm, metrics.jvm, control.jvm, netty, jdbc)

lazy val json =
crossProject(JSPlatform, JVMPlatform)
crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("airframe-json"))
.settings(buildSettings)
Expand All @@ -859,6 +866,7 @@ lazy val json =
description := "JSON parser"
)
.jsSettings(jsBuildSettings)
.nativeSettings(nativeBuildSettings)
.dependsOn(log)

lazy val benchmark =
Expand Down

0 comments on commit 689ef45

Please sign in to comment.