@@ -4,24 +4,30 @@ import scala.quoted._
4
4
import scala .quoted .matching ._
5
5
import scala .util .FromDigits
6
6
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 =>
8
11
9
12
class FromDigits extends FromDigits .WithRadix [ByteVector ] {
10
13
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)
13
15
}
14
16
15
17
given FromDigits {
16
18
override inline def fromDigits (digits : String ): ByteVector =
17
- $ {digitsToByteVector (' digits , Expr (10 ))}
19
+ $ {digitsToByteVectorMacro (' digits , Expr (10 ))}
18
20
override inline def fromDigits (digits : String , radix : Int ): ByteVector =
19
- $ {digitsToByteVector (' digits , ' radix )}
21
+ $ {digitsToByteVectorMacro (' digits , ' radix )}
20
22
}
21
23
}
22
24
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" )
23
28
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 ] =
25
31
(digits, radix) match {
26
32
case (Const (ds), Const (r)) =>
27
33
if (r == 16 ) {
@@ -31,8 +37,5 @@ def digitsToByteVector(digits: Expr[String], radix: Expr[Int])(given qctx: Quote
31
37
' {ByteVector .empty}
32
38
}
33
39
case other =>
34
- ' {
35
- if ($radix == 16 ) ByteVector .fromValidHex($digits.tail)
36
- else throw FromDigits .MalformedNumber (" unsupported radix" )
37
- }
40
+ ' {digitsToByteVector($digits, $radix)}
38
41
}
0 commit comments