Skip to content

Commit

Permalink
[WIP] Restore binary compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed May 14, 2024
1 parent b472fc9 commit e33e4c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
31 changes: 30 additions & 1 deletion upickle/core/src/upickle/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ trait Types{ types =>
new TaggedReadWriter.Node(tagKey, rws.asInstanceOf[Seq[TaggedReadWriter[T]]]:_*)
}

@deprecated("Not used, left for binary compatibility")
def merge[T](rws: ReadWriter[_ <: T]*): TaggedReadWriter[T] = merge(Annotator.defaultTagKey, rws:_*)

implicit def join[T](implicit r0: Reader[T], w0: Writer[T]): ReadWriter[T] = (r0, w0) match{
// Make sure we preserve the tagged-ness of the Readers/Writers being
// pulled in; we need to do this because the macros that generate tagged
Expand Down Expand Up @@ -105,9 +108,12 @@ trait Types{ types =>

override def visitArray(length: Int, index: Int) = super.visitArray(length, index).asInstanceOf[ArrVisitor[Any, Z]]
}
def merge[T](tagKey: String, readers0: Reader[_ <: T]*) = {
def merge[T](tagKey: String, readers0: Reader[_ <: T]*): TaggedReader.Node[T] = {
new TaggedReader.Node(tagKey, readers0.asInstanceOf[Seq[TaggedReader[T]]]:_*)
}

@deprecated("Not used, left for binary compatibility")
def merge[T](readers0: Reader[_ <: T]*): TaggedReader.Node[T] = merge(Annotator.defaultTagKey, readers0:_*)
}

/**
Expand Down Expand Up @@ -164,9 +170,15 @@ trait Types{ types =>
}
object TaggedReader{
class Leaf[T](private[upickle] val tagKey: String, tagValue: String, r: Reader[T]) extends TaggedReader[T]{
@deprecated("Not used, left for binary compatibility")
def this(tag: String, r: Reader[T]) = this(Annotator.defaultTagKey, tag, r)

def findReader(s: String) = if (s == tagValue) r else null
}
class Node[T](private[upickle] val tagKey: String, rs: TaggedReader[_ <: T]*) extends TaggedReader[T]{
@deprecated("Not used, left for binary compatibility")
def this(rs: TaggedReader[_ <: T]*) = this(Annotator.defaultTagKey, rs:_*)

def findReader(s: String) = scanChildren(rs)(_.findReader(s)).asInstanceOf[Reader[T]]
}
}
Expand All @@ -181,6 +193,10 @@ trait Types{ types =>
}
object TaggedWriter{
class Leaf[T](checker: Annotator.Checker, tagKey: String, tagValue: String, r: ObjectWriter[T]) extends TaggedWriter[T]{
@deprecated("Not used, left for binary compatibility")
def this(checker: Annotator.Checker, tag: String, r: ObjectWriter[T]) =
this(checker, Annotator.defaultTagKey, tag, r)

def findWriter(v: Any) = {
checker match{
case Annotator.Checker.Cls(c) if c.isInstance(v) => (tagKey, tagValue, r)
Expand Down Expand Up @@ -221,6 +237,9 @@ trait Types{ types =>

def taggedWrite[T, R](w: ObjectWriter[T], tagKey: String, tagValue: String, out: Visitor[_, R], v: T): R

@deprecated("Not used, left for binary compatibility")
def taggedWrite[T, R](w: ObjectWriter[T], tag: String, out: Visitor[_, R], v: T): R

private[this] def scanChildren[T, V](xs: Seq[T])(f: T => V) = {
var x: V = null.asInstanceOf[V]
val i = xs.iterator
Expand Down Expand Up @@ -256,6 +275,16 @@ trait Annotator { this: Types =>
def annotate[V](rw: ObjectWriter[V], key: String, value: String, checker: Annotator.Checker): TaggedWriter[V]
def annotate[V](rw: ObjectWriter[V], key: String, value: String)(implicit ct: ClassTag[V]): TaggedWriter[V] =
annotate(rw, key, value, Annotator.Checker.Cls(ct.runtimeClass))

@deprecated("Not used, left for binary compatibility")
def annotate[V](rw: Reader[V], n: String): TaggedReader[V]

@deprecated("Not used, left for binary compatibility")
def annotate[V](rw: ObjectWriter[V], n: String, checker: Annotator.Checker): TaggedWriter[V]

@deprecated("Not used, left for binary compatibility")
final def annotate[V](rw: ObjectWriter[V], n: String)(implicit ct: ClassTag[V]): TaggedWriter[V] =
annotate(rw, Annotator.defaultTagKey, n)
}
object Annotator{
def defaultTagKey = "$type"
Expand Down
27 changes: 25 additions & 2 deletions upickle/src/upickle/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,20 @@ object default extends AttributeTagged{
*/
object legacy extends LegacyApi
trait LegacyApi extends Api with Annotator{
def annotate[V](rw: Reader[V], key: String, value: String) = new TaggedReader.Leaf[V](key, value, rw)
def annotate[V](rw: Reader[V], key: String, value: String): TaggedReader[V] = new TaggedReader.Leaf[V](key, value, rw)

@deprecated("Not used, left for binary compatibility")
final def annotate[V](rw: Reader[V], n: String): TaggedReader[V] =
annotate(rw, Annotator.defaultTagKey, n)

def annotate[V](rw: ObjectWriter[V], key: String, value: String, checker: Annotator.Checker): TaggedWriter[V] = {
new TaggedWriter.Leaf[V](checker, key, value, rw)
}

@deprecated("Not used, left for binary compatibility")
final def annotate[V](rw: ObjectWriter[V], n: String, checker: Annotator.Checker): TaggedWriter[V] =
annotate(rw, Annotator.defaultTagKey, n, checker)

def taggedExpectedMsg = "expected sequence"
sealed trait TaggedReaderState
object TaggedReaderState{
Expand Down Expand Up @@ -295,6 +303,9 @@ trait LegacyApi extends Api with Annotator{

ctx.visitEnd(-1)
}
@deprecated("Not used, left for binary compatibility")
final def taggedWrite[T, R](w: ObjectWriter[T], tag: String, out: Visitor[_, R], v: T): R =
taggedWrite(w, Annotator.defaultTagKey, tag, out, v)
}

/**
Expand All @@ -303,13 +314,22 @@ trait LegacyApi extends Api with Annotator{
* of the attribute is.
*/
trait AttributeTagged extends Api with Annotator{
def annotate[V](rw: Reader[V], key: String, value: String) = {
@deprecated("Not used, left for binary compatibility")
def tagName = Annotator.defaultTagKey

def annotate[V](rw: Reader[V], key: String, value: String): TaggedReader[V] = {
new TaggedReader.Leaf[V](key, value, rw)
}
@deprecated("Not used, left for binary compatibility")
final def annotate[V](rw: Reader[V], n: String): TaggedReader[V] =
annotate(rw, Annotator.defaultTagKey, n)

def annotate[V](rw: ObjectWriter[V], key: String, value: String, checker: Annotator.Checker): TaggedWriter[V] = {
new TaggedWriter.Leaf[V](checker, key, value, rw)
}
@deprecated("Not used, left for binary compatibility")
final def annotate[V](rw: ObjectWriter[V], n: String, checker: Annotator.Checker): TaggedWriter[V] =
annotate(rw, Annotator.defaultTagKey, n, checker)

def taggedExpectedMsg = "expected dictionary"
private def isTagName(tagKey: String, i: Any) = i match{
Expand Down Expand Up @@ -402,4 +422,7 @@ trait AttributeTagged extends Api with Annotator{
res
}
}
@deprecated("Not used, left for binary compatibility")
final def taggedWrite[T, R](w: ObjectWriter[T], tag: String, out: Visitor[_, R], v: T): R =
taggedWrite(w, Annotator.defaultTagKey, tag, out, v)
}

0 comments on commit e33e4c8

Please sign in to comment.