Skip to content

Commit 028b9e7

Browse files
committed
ETCM-167: Use +: instead of :: on RLPList.
1 parent e28c69d commit 028b9e7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/main/scala/io/iohk/ethereum/network/discovery/codecs/RLPCodecs.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object RLPCodecs {
4545
implicit val nodeRLPCodec: RLPCodec[Node] =
4646
RLPCodec.instance[Node](
4747
{ case Node(id, address) =>
48-
RLPEncoder.encode(address).asInstanceOf[RLPList] ++ RLPList(id)
48+
RLPEncoder.encode(address).asInstanceOf[RLPList] :+ id
4949
},
5050
{
5151
case list @ RLPList(items @ _*) if items.length >= 4 =>
@@ -62,10 +62,10 @@ object RLPCodecs {
6262
{ case EthereumNodeRecord.Content(seq, attrs) =>
6363
val kvs = attrs
6464
.foldRight(RLPList()) { case ((k, v), kvs) =>
65-
k.toArray :: v.toArray :: kvs
65+
k.toArray +: v.toArray +: kvs
6666
}
6767

68-
seq :: kvs
68+
seq +: kvs
6969
},
7070
{ case RLPList(seq, kvs @ _*) =>
7171
val attrs = kvs
@@ -89,7 +89,8 @@ object RLPCodecs {
8989
implicit val enrRLPCodec: RLPCodec[EthereumNodeRecord] =
9090
RLPCodec.instance(
9191
{ case EthereumNodeRecord(signature, content) =>
92-
signature.toByteArray :: RLPEncoder.encode(content).asInstanceOf[RLPList]
92+
val contentList = RLPEncoder.encode(content).asInstanceOf[RLPList]
93+
signature.toByteArray +: contentList
9394
},
9495
{ case RLPList(signature, content @ _*) =>
9596
EthereumNodeRecord(

src/main/scala/io/iohk/ethereum/rlp/RLPImplicitDerivations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object RLPImplicitDerivations {
5858
}
5959

6060
private def decodeError[T](subject: String, error: String, maybeEncodeable: Option[RLPEncodeable] = None): T =
61-
throw RLPException(s"error decoding $subject: $error", maybeEncodeable)
61+
throw RLPException(s"Cannot decode $subject: $error", maybeEncodeable)
6262

6363
private def tryDecode[T](subject: => String, encodeable: RLPEncodeable)(f: RLPEncodeable => T): T = {
6464
try {

src/main/scala/io/iohk/ethereum/rlp/package.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ package object rlp {
1515
sealed trait RLPEncodeable
1616

1717
case class RLPList(items: RLPEncodeable*) extends RLPEncodeable {
18-
def ::(item: RLPEncodeable): RLPList =
18+
def +:(item: RLPEncodeable): RLPList =
1919
RLPList((item +: items): _*)
2020

21+
def :+(item: RLPEncodeable): RLPList =
22+
RLPList((items :+ item): _*)
23+
2124
def ++(other: RLPList): RLPList =
2225
RLPList((items ++ other.items): _*)
2326
}
@@ -96,7 +99,7 @@ package object rlp {
9699

97100
override def decode(rlp: RLPEncodeable): T =
98101
if (dec.isDefinedAt(rlp)) dec(rlp)
99-
else throw RLPException(s"Cannot decode type ${ct.runtimeClass.getSimpleName} from RLP.", rlp)
102+
else throw RLPException(s"Cannot decode type ${ct.runtimeClass.getSimpleName} from unexpected RLP.", rlp)
100103
}
101104

102105
def apply[T](enc: RLPEncoder[T], dec: RLPDecoder[T]): RLPCodec[T] =

0 commit comments

Comments
 (0)