Skip to content

Commit 52b65d4

Browse files
committed
Fixed build and reduced some duplication in FromDigits support
1 parent e43c944 commit 52b65d4

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

core/shared/src/main/scala-0.22/scodec/bits/ByteVectorPlatform.scala

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@ import scala.quoted._
44
import scala.quoted.matching._
55
import scala.util.FromDigits
66

7-
trait ByteVectorPlatform {
7+
// TODO: as of 0.22, making this private[bits] results in errors like the following at call sites:
8+
// scala> val b: ByteVector = 0x00112233_44556677_8899aabb_ccddeeff_fedba098
9+
// trait ByteVectorPlatform cannot be accessed as a member of scodec.bits from module class rs$line$2$.
10+
private[bits] trait ByteVectorPlatform { self: ByteVector.type =>
811

912
class FromDigits extends FromDigits.WithRadix[ByteVector] {
1013
def fromDigits(digits: String, radix: Int): ByteVector =
11-
if (radix == 16) ByteVector.fromValidHex(digits.tail)
12-
else throw FromDigits.MalformedNumber("unsupported radix")
14+
digitsToByteVector(digits, radix)
1315
}
1416

1517
given FromDigits {
1618
override inline def fromDigits(digits: String): ByteVector =
17-
${digitsToByteVector('digits, Expr(10))}
19+
${digitsToByteVectorMacro('digits, Expr(10))}
1820
override inline def fromDigits(digits: String, radix: Int): ByteVector =
19-
${digitsToByteVector('digits, 'radix)}
21+
${digitsToByteVectorMacro('digits, 'radix)}
2022
}
2123
}
2224

25+
private[bits] def digitsToByteVector(digits: String, radix: Int): ByteVector =
26+
if (radix == 16) ByteVector.fromValidHex(digits.tail)
27+
else throw FromDigits.MalformedNumber(s"unsupported radix $radix")
2328

24-
def digitsToByteVector(digits: Expr[String], radix: Expr[Int])(given qctx: QuoteContext): Expr[ByteVector] =
29+
30+
def digitsToByteVectorMacro(digits: Expr[String], radix: Expr[Int])(given qctx: QuoteContext): Expr[ByteVector] =
2531
(digits, radix) match {
2632
case (Const(ds), Const(r)) =>
2733
if (r == 16) {
@@ -31,8 +37,5 @@ def digitsToByteVector(digits: Expr[String], radix: Expr[Int])(given qctx: Quote
3137
'{ByteVector.empty}
3238
}
3339
case other =>
34-
'{
35-
if ($radix == 16) ByteVector.fromValidHex($digits.tail)
36-
else throw FromDigits.MalformedNumber("unsupported radix")
37-
}
40+
'{digitsToByteVector($digits, $radix)}
3841
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scodec.bits
2+
3+
private[bits] trait ByteVectorPlatform
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scodec.bits
2+
3+
private[bits] trait ByteVectorPlatform

0 commit comments

Comments
 (0)