Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Fix #10 avoid confusion of Int => T with IndexedSeq[T] under -Yparita…
Browse files Browse the repository at this point in the history
…l-unification
  • Loading branch information
julien-lafont committed Sep 18, 2017
1 parent 29ded98 commit d8ff936
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions modules/core/src/main/scala/io/protoless/fields/FieldDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.protoless.fields
import scala.annotation.implicitNotFound
import scala.collection.mutable
import scala.collection.generic.CanBuildFrom
import scala.reflect.ClassTag
import scala.util.{Failure, Success, Try}

import com.google.protobuf.{ByteString, WireFormat, CodedInputStream => CIS}
Expand Down Expand Up @@ -406,11 +407,12 @@ trait MidPriorityFieldDecoder extends LowPriorityFieldDecoder {
trait LowPriorityFieldDecoder {

/**
* Decode a repeating field of type `A` into a collection of high-kind type `C`.
* Decode a repeating field of type `A` into a Traversable collection `C`.
*
* @group Collection
*/
implicit final def decodeCanBuildFrom[A, C[_]](implicit dec: RepeatableFieldDecoder[A], cbf: CanBuildFrom[Nothing, A, C[A]]): RepeatableFieldDecoder[C[A]] = new RepeatableFieldDecoder[C[A]] {
implicit final def decodeTraversable[A, C[A] <: Traversable[A]](implicit dec: RepeatableFieldDecoder[A], cbf: CanBuildFrom[Nothing, A, C[A]])
: RepeatableFieldDecoder[C[A]] = new RepeatableFieldDecoder[C[A]] {

@scala.annotation.tailrec
private def readUntilFieldNumberEquals(index: Int, input: CIS, cbf: mutable.Builder[A, C[A]]): Either[DecodingFailure, C[A]] = {
Expand Down Expand Up @@ -461,6 +463,20 @@ trait LowPriorityFieldDecoder {
override def fieldType: FieldType = dec.fieldType
}

/**
* Decode a repeating field of type `A` into an Array.
*
* TODO: Improve performance by not depending on `decodeTraversable`
*
* @group Collection
*/
implicit final def decodeArray[A](implicit
dec: RepeatableFieldDecoder[A],
cbf: CanBuildFrom[Nothing, A, Seq[A]],
tp: ClassTag[A]): RepeatableFieldDecoder[Array[A]] = {
decodeTraversable[A, Seq](dec, cbf).map(_.toArray)
}

/**
* Read the next field tag and extract the FieldNumber / WireType.
*
Expand Down

0 comments on commit d8ff936

Please sign in to comment.