@@ -40,25 +40,27 @@ object RLPImplicitDerivations {
40
40
41
41
/** Specialized decoder for case classes that only accepts RLPList for input. */
42
42
trait RLPListDecoder [T ] extends RLPDecoder [T ] {
43
+ protected def ct : ClassTag [T ]
43
44
def decodeList (items : List [RLPEncodeable ]): (T , List [FieldInfo ])
44
45
45
46
override def decode (rlp : RLPEncodeable ): T =
46
47
rlp match {
47
48
case list : RLPList =>
48
49
decodeList(list.items.toList)._1
49
50
case _ =>
50
- throw RLPException (s " Expected to decode an RLPList" , rlp)
51
+ throw RLPException (s " Cannot decode ${ct.runtimeClass.getSimpleName} : expected an RLPList. " , rlp)
51
52
}
52
53
}
53
54
object RLPListDecoder {
54
- def apply [T ](f : List [RLPEncodeable ] => (T , List [FieldInfo ])): RLPListDecoder [T ] =
55
+ def apply [T : ClassTag ](f : List [RLPEncodeable ] => (T , List [FieldInfo ])): RLPListDecoder [T ] =
55
56
new RLPListDecoder [T ] {
57
+ override val ct = implicitly[ClassTag [T ]]
56
58
override def decodeList (items : List [RLPEncodeable ]) = f(items)
57
59
}
58
60
}
59
61
60
62
private def decodeError [T ](subject : String , error : String , maybeEncodeable : Option [RLPEncodeable ] = None ): T =
61
- throw RLPException (s " error decoding $subject: $error" , maybeEncodeable)
63
+ throw RLPException (s " Cannot decode $subject: $error" , maybeEncodeable)
62
64
63
65
private def tryDecode [T ](subject : => String , encodeable : RLPEncodeable )(f : RLPEncodeable => T ): T = {
64
66
try {
@@ -99,15 +101,15 @@ object RLPImplicitDerivations {
99
101
// This is still a trailing optional field, so we can insert it as a value or omit it.
100
102
hEncoder.value.encode(head) match {
101
103
case RLPList (hRLP) =>
102
- hRLP : : tRLP
104
+ hRLP + : tRLP
103
105
case RLPList () if tRLP.items.isEmpty =>
104
106
tRLP
105
107
case hRLP =>
106
- hRLP : : tRLP
108
+ hRLP + : tRLP
107
109
}
108
110
} else {
109
111
// We're no longer in a trailing position, so insert it as a list of 0 or 1 items.
110
- hEncoder.value.encode(head) : : tRLP
112
+ hEncoder.value.encode(head) + : tRLP
111
113
}
112
114
113
115
htRLP -> (hInfo :: tInfos)
@@ -125,7 +127,7 @@ object RLPImplicitDerivations {
125
127
RLPListEncoder { case head :: tail =>
126
128
val hRLP = hEncoder.value.encode(head)
127
129
val (tRLP, tInfos) = tEncoder.value.encodeList(tail)
128
- (hRLP : : tRLP, hInfo :: tInfos)
130
+ (hRLP + : tRLP, hInfo :: tInfos)
129
131
}
130
132
}
131
133
0 commit comments