Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Feb 9, 2024
1 parent 0b81593 commit 93c41c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.11.6
0.11.7

17 changes: 12 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion
import com.github.lolgab.mill.mima._

val scala212 = "2.12.18"
val scala213 = "2.13.11"
val scala213 = "2.13.12"

val scala3 = "3.3.0"
val scalaNative = "0.4.14"
val acyclic = "0.3.8"
val acyclic = "0.3.9"

val sourcecode = "0.3.0"

val dottyCustomVersion = Option(sys.props("dottyVersion"))

val scala2JVMVersions = Seq(scala212, scala213)
val scalaVersions = scala2JVMVersions// ++ Seq(scala3) ++ dottyCustomVersion
val scalaVersions = scala2JVMVersions ++ Seq(scala3) ++ dottyCustomVersion

trait CommonPlatformModule extends ScalaModule with PlatformScalaModule{

Expand Down Expand Up @@ -58,6 +58,10 @@ trait CommonPublishModule
)
)

def scalacPluginIvyDeps =
super.scalacPluginIvyDeps() ++ Agg(ivy"com.lihaoyi::unroll-plugin:0.1.3")


def publishProperties: Target[Map[String, String]] = super.publishProperties() ++ Map(
"info.releaseNotesURL" -> "https://com-lihaoyi.github.io/upickle/#VersionHistory"
)
Expand All @@ -84,7 +88,7 @@ trait CommonPublishModule
}

def scalacOptions = T {
Seq("-unchecked", "-deprecation", "-encoding", "utf8", "-feature", "-Xfatal-warnings") ++
Seq("-unchecked", "-deprecation", "-encoding", "utf8", "-feature", "-Xfatal-warnings", "-Xplugin-require:unroll") ++
Agg.when(!isScala3(scalaVersion()))("-opt:l:method").toSeq
}

Expand Down Expand Up @@ -219,7 +223,10 @@ object ujson extends Module{
object upickle extends Module{
object core extends Module {
trait CommonCoreModule extends CommonPublishModule {
def ivyDeps = Agg(ivy"com.lihaoyi::geny::1.0.0")
def ivyDeps = Agg(
ivy"com.lihaoyi::geny::1.0.0",
ivy"com.lihaoyi::unroll-annotation:0.1.3"
)
}

object js extends Cross[CoreJsModule](scalaVersions)
Expand Down
80 changes: 10 additions & 70 deletions ujson/src/ujson/package.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import upickle.core.NoOpVisitor
import upickle.core.BufferedValue

import unroll.Unroll
package object ujson{
def transform[T](t: Readable,
v: upickle.core.Visitor[_, T],
sortKeys: Boolean = false): T = {
@Unroll sortKeys: Boolean = false): T = {
BufferedValue.maybeSortKeysTransform(Readable, t, sortKeys, v)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def transform[T](t: Readable,
v: upickle.core.Visitor[_, T]): T = transform(t, v, sortKeys = false)
/**
* Read the given JSON input as a JSON struct
*/
Expand All @@ -25,70 +22,40 @@ package object ujson{
def write(t: Value.Value,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): String = {
@Unroll sortKeys: Boolean = false): String = {
val writer = new java.io.StringWriter
writeTo(t, writer, indent, escapeUnicode, sortKeys)
writer.toString
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def write(t: Value.Value,
indent: Int,
escapeUnicode: Boolean): String = {
write(t, indent, escapeUnicode, sortKeys = false)
}

/**
* Write the given JSON struct as a JSON String to the given Writer
*/
def writeTo(t: Value.Value,
out: java.io.Writer,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
transform(t, Renderer(out, indent, escapeUnicode), sortKeys)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeTo(t: Value.Value,
out: java.io.Writer,
indent: Int,
escapeUnicode: Boolean): Unit = {
writeTo(t, out, indent, escapeUnicode, sortKeys = false)
}

def writeToOutputStream(t: Value.Value,
out: java.io.OutputStream,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
transform(t, new BaseByteRenderer(out, indent, escapeUnicode), sortKeys)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeToOutputStream(t: Value.Value,
out: java.io.OutputStream,
indent: Int,
escapeUnicode: Boolean): Unit = {
writeToOutputStream(t, out, indent, escapeUnicode, sortKeys = false)
}

def writeToByteArray(t: Value.Value,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Array[Byte] = {
@Unroll sortKeys: Boolean = false): Array[Byte] = {
val baos = new java.io.ByteArrayOutputStream
writeToOutputStream(t, baos, indent, escapeUnicode, sortKeys)
baos.toByteArray
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeToByteArray(t: Value.Value,
indent: Int,
escapeUnicode: Boolean): Array[Byte] = {
writeToByteArray(t, indent, escapeUnicode, sortKeys = false)
}

/**
* Parse the given JSON input, failing if it is invalid
*/
Expand All @@ -100,18 +67,12 @@ package object ujson{
def reformat(s: Readable,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): String = {
@Unroll sortKeys: Boolean = false): String = {
val writer = new java.io.StringWriter()
reformatTo(s, writer, indent, escapeUnicode, sortKeys)
writer.toString
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def reformat(s: Readable,
indent: Int,
escapeUnicode: Boolean): String = {
reformat(s, indent, escapeUnicode, sortKeys = false)
}
/**
* Parse the given JSON input and write it to a string with
* the configured formatting to the given Writer
Expand All @@ -120,17 +81,10 @@ package object ujson{
out: java.io.Writer,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
transform(s, Renderer(out, indent, escapeUnicode), sortKeys)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def reformatTo(s: Readable,
out: java.io.Writer,
indent: Int,
escapeUnicode: Boolean): Unit = {
reformatTo(s, out, indent, escapeUnicode, sortKeys = false)
}
/**
* Parse the given JSON input and write it to a string with
* the configured formatting to the given Writer
Expand All @@ -139,33 +93,19 @@ package object ujson{
out: java.io.OutputStream,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
transform(s, new BaseByteRenderer(out, indent, escapeUnicode), sortKeys)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def reformatToOutputStream(s: Readable,
out: java.io.OutputStream,
indent: Int,
escapeUnicode: Boolean): Unit = {
reformatToOutputStream(s, out, indent, escapeUnicode, sortKeys = false)
}

def reformatToByteArray(s: Readable,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Array[Byte] = {
@Unroll sortKeys: Boolean = false): Array[Byte] = {
val baos = new java.io.ByteArrayOutputStream
reformatToOutputStream(s, baos, indent, escapeUnicode, sortKeys)
baos.toByteArray
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def reformatToByteArray(s: Readable,
indent: Int,
escapeUnicode: Boolean): Array[Byte] = {
reformatToByteArray(s, indent, escapeUnicode, sortKeys = false)
}
// End ujson
@deprecated("use ujson.Value")
type Js = Value
Expand Down
70 changes: 10 additions & 60 deletions upickle/src/upickle/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import language.experimental.macros
import language.higherKinds
import upickle.core._
import scala.reflect.ClassTag
import unroll.Unroll

/**
* An instance of the upickle API. There's a default instance at
Expand Down Expand Up @@ -50,28 +51,18 @@ trait Api
def write[T: Writer](t: T,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): String = {
@Unroll sortKeys: Boolean = false): String = {
maybeSortKeysTransform(t, sortKeys, ujson.StringRenderer(indent, escapeUnicode)).toString
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def write[T: Writer](t: T,
indent: Int,
escapeUnicode: Boolean): String = {
write(t, indent, escapeUnicode, sortKeys = false)
}

/**
* Write the given Scala value as a MessagePack binary
*/
def writeBinary[T: Writer](t: T,
sortKeys: Boolean = false): Array[Byte] = {
@Unroll sortKeys: Boolean = false): Array[Byte] = {
maybeSortKeysTransform(t, sortKeys, new upack.MsgPackWriter(new ByteArrayOutputStream())).toByteArray
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeBinary[T: Writer](t: T): Array[Byte] = writeBinary(t, sortKeys = false)

/**
* Write the given Scala value as a JSON struct
*/
Expand All @@ -89,105 +80,64 @@ trait Api
out: java.io.Writer,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
maybeSortKeysTransform(t, sortKeys, new ujson.Renderer(out, indent = indent, escapeUnicode))
}


// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeTo[T: Writer](t: T,
out: java.io.Writer,
indent: Int,
escapeUnicode: Boolean): Unit = writeTo(t, out, indent, escapeUnicode, sortKeys = false)

def writeToOutputStream[T: Writer](t: T,
out: java.io.OutputStream,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
maybeSortKeysTransform(t, sortKeys, new ujson.BaseByteRenderer(out, indent = indent, escapeUnicode))
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeToOutputStream[T: Writer](t: T,
out: java.io.OutputStream,
indent: Int,
escapeUnicode: Boolean): Unit = {
writeToOutputStream(t, out, indent, escapeUnicode, sortKeys = false)
}

def writeToByteArray[T: Writer](t: T,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): Array[Byte] = {
@Unroll sortKeys: Boolean = false): Array[Byte] = {
val out = new java.io.ByteArrayOutputStream()
writeToOutputStream(t, out, indent, escapeUnicode, sortKeys)
out.toByteArray
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeToByteArray[T: Writer](t: T,
indent: Int,
escapeUnicode: Boolean): Array[Byte] = {
writeToByteArray[T](t, indent, escapeUnicode, sortKeys = false)
}
/**
* Write the given Scala value as a JSON string via a `geny.Writable`
*/
def stream[T: Writer](t: T,
indent: Int = -1,
escapeUnicode: Boolean = false,
sortKeys: Boolean = false): geny.Writable = new geny.Writable{
@Unroll sortKeys: Boolean = false): geny.Writable = new geny.Writable{
override def httpContentType = Some("application/json")
def writeBytesTo(out: java.io.OutputStream) = {
maybeSortKeysTransform(t, sortKeys, new ujson.BaseByteRenderer(out, indent = indent, escapeUnicode))
}
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def stream[T: Writer](t: T,
indent: Int,
escapeUnicode: Boolean): geny.Writable = {
stream(t, indent, escapeUnicode, sortKeys = false)
}
/**
* Write the given Scala value as a MessagePack binary to the given OutputStream
*/
def writeBinaryTo[T: Writer](t: T,
out: java.io.OutputStream,
sortKeys: Boolean = false): Unit = {
@Unroll sortKeys: Boolean = false): Unit = {
streamBinary[T](t, sortKeys = sortKeys).writeBytesTo(out)
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeBinaryTo[T: Writer](t: T,
out: java.io.OutputStream): Unit = {
writeBinaryTo(t, out, sortKeys = false)
}

def writeBinaryToByteArray[T: Writer](t: T,
sortKeys: Boolean = false): Array[Byte] = {
@Unroll sortKeys: Boolean = false): Array[Byte] = {
val out = new java.io.ByteArrayOutputStream()
streamBinary[T](t, sortKeys = sortKeys).writeBytesTo(out)
out.toByteArray
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def writeBinaryToByteArray[T: Writer](t: T): Array[Byte] = {
writeBinaryToByteArray(t, sortKeys = false)
}
/**
* Write the given Scala value as a MessagePack binary via a `geny.Writable`
*/
def streamBinary[T: Writer](t: T, sortKeys: Boolean = false): geny.Writable = new geny.Writable{
def streamBinary[T: Writer](t: T, @Unroll sortKeys: Boolean = false): geny.Writable = new geny.Writable{
override def httpContentType = Some("application/octet-stream")
def writeBytesTo(out: java.io.OutputStream) = maybeSortKeysTransform(t, sortKeys, new upack.MsgPackWriter(out))
}

// @deprecated("Binary Compatibility Stub", "upickle after 3.1.4")
def streamBinary[T: Writer](t: T): geny.Writable = {
streamBinary(t, sortKeys = false)
}

def writer[T: Writer] = implicitly[Writer[T]]

Expand Down

0 comments on commit 93c41c8

Please sign in to comment.