-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of
immutable.ArraySeq
+ more inlinings (#1279)
- Loading branch information
1 parent
5c1b9ae
commit fec8e2c
Showing
19 changed files
with
282 additions
and
81 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
zio-json/shared/src/main/scala-2.13/zio/json/JsonCodecVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package zio.json | ||
|
||
import scala.collection.immutable | ||
|
||
trait JsonCodecVersionSpecific { | ||
implicit def arraySeq[A: JsonEncoder: JsonDecoder: reflect.ClassTag]: JsonCodec[immutable.ArraySeq[A]] = | ||
JsonCodec(JsonEncoder.arraySeq[A], JsonDecoder.arraySeq[A]) | ||
} |
20 changes: 20 additions & 0 deletions
20
zio-json/shared/src/main/scala-2.13/zio/json/JsonDecoderVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package zio.json | ||
|
||
import zio.json.JsonDecoder.JsonError | ||
import zio.json.internal.RetractReader | ||
|
||
import scala.collection.immutable | ||
|
||
private[json] trait JsonDecoderVersionSpecific { | ||
implicit def arraySeq[A: JsonDecoder: reflect.ClassTag]: JsonDecoder[immutable.ArraySeq[A]] = | ||
new CollectionJsonDecoder[immutable.ArraySeq[A]] { | ||
private[this] val arrayDecoder = JsonDecoder.array[A] | ||
|
||
override def unsafeDecodeMissing(trace: List[JsonError]): immutable.ArraySeq[A] = immutable.ArraySeq.empty | ||
|
||
def unsafeDecode(trace: List[JsonError], in: RetractReader): immutable.ArraySeq[A] = | ||
immutable.ArraySeq.unsafeWrapArray(arrayDecoder.unsafeDecode(trace, in)) | ||
} | ||
} | ||
|
||
private[json] trait DecoderLowPriorityVersionSpecific |
23 changes: 23 additions & 0 deletions
23
zio-json/shared/src/main/scala-2.13/zio/json/JsonEncoderVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package zio.json | ||
|
||
import zio.json.ast.Json | ||
import zio.json.internal.Write | ||
|
||
import scala.collection.immutable | ||
|
||
private[json] trait JsonEncoderVersionSpecific { | ||
implicit def arraySeq[A: JsonEncoder: scala.reflect.ClassTag]: JsonEncoder[immutable.ArraySeq[A]] = | ||
new JsonEncoder[immutable.ArraySeq[A]] { | ||
private[this] val arrayEnc = JsonEncoder.array[A] | ||
|
||
override def isEmpty(as: immutable.ArraySeq[A]): Boolean = as.isEmpty | ||
|
||
def unsafeEncode(as: immutable.ArraySeq[A], indent: Option[Int], out: Write): Unit = | ||
arrayEnc.unsafeEncode(as.unsafeArray.asInstanceOf[Array[A]], indent, out) | ||
|
||
override final def toJsonAST(as: immutable.ArraySeq[A]): Either[String, Json] = | ||
arrayEnc.toJsonAST(as.unsafeArray.asInstanceOf[Array[A]]) | ||
} | ||
} | ||
|
||
private[json] trait EncoderLowPriorityVersionSpecific |
4 changes: 4 additions & 0 deletions
4
zio-json/shared/src/main/scala-3/zio/json/JsonCodecVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package zio.json | ||
|
||
import scala.collection.immutable | ||
|
||
private[json] trait JsonCodecVersionSpecific { | ||
inline def derived[A: deriving.Mirror.Of](using config: JsonCodecConfiguration): JsonCodec[A] = DeriveJsonCodec.gen[A] | ||
|
||
implicit def arraySeq[A: JsonEncoder: JsonDecoder: reflect.ClassTag]: JsonCodec[immutable.ArraySeq[A]] = | ||
JsonCodec(JsonEncoder.arraySeq[A], JsonDecoder.arraySeq[A]) | ||
} |
15 changes: 14 additions & 1 deletion
15
zio-json/shared/src/main/scala-3/zio/json/JsonDecoderVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
zio-json/shared/src/main/scala-3/zio/json/JsonEncoderVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
package zio.json | ||
|
||
import zio.json.ast.Json | ||
import zio.json.internal.Write | ||
|
||
import scala.collection.immutable | ||
import scala.compiletime.ops.any.IsConst | ||
|
||
private[json] trait JsonEncoderVersionSpecific { | ||
inline def derived[A: deriving.Mirror.Of](using config: JsonCodecConfiguration): JsonEncoder[A] = | ||
DeriveJsonEncoder.gen[A] | ||
|
||
implicit def arraySeq[A: JsonEncoder: scala.reflect.ClassTag]: JsonEncoder[immutable.ArraySeq[A]] = | ||
new JsonEncoder[immutable.ArraySeq[A]] { | ||
private[this] val arrayEnc = JsonEncoder.array[A] | ||
|
||
override def isEmpty(as: immutable.ArraySeq[A]): Boolean = as.isEmpty | ||
|
||
def unsafeEncode(as: immutable.ArraySeq[A], indent: Option[Int], out: Write): Unit = | ||
arrayEnc.unsafeEncode(as.unsafeArray.asInstanceOf[Array[A]], indent, out) | ||
|
||
override final def toJsonAST(as: immutable.ArraySeq[A]): Either[String, Json] = | ||
arrayEnc.toJsonAST(as.unsafeArray.asInstanceOf[Array[A]]) | ||
} | ||
} | ||
|
||
private[json] trait EncoderLowPriorityVersionSpecific { | ||
|
||
inline given unionOfStringEnumeration[T](using IsUnionOf[String, T]): JsonEncoder[T] = | ||
JsonEncoder.string.asInstanceOf[JsonEncoder[T]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.