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