import akka.util.ByteString
object SimpleTest extends App {
import org.kafecho.bitwrangler.macros.BitWrangler
val data = ByteString(0x40, 0xFF) // Essentially 0010 0000 1111 1111
println(BitWrangler.boolean(data, 2)) // Read the 3rd bit value
println(BitWrangler.int(data, 7, 3)) // Read the value 011
}
The BitWrangler is implemented as a set of Scala macros which generate an AST for the bitwise and bit-shift operations based on information known at compile time.
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
val data = ByteString(0xFF,0xFF,0xFF)
BitWrangler.int(data,5,19) // Read 19 bits from the 5th bit in the byte string.
The macro, according to the Scala compiler, is expanded as: SimpleExample.this.data.apply(0).$amp(7).$less$less(3).$bar(SimpleExample.this.data.apply(1).$amp(255)).$less$less(8).$bar(SimpleExample.this.data.apply(2).$amp(255))
There is currently a value class penalty in that it inhibits constant folding. If this were remedied, I think you wouldn't need to use macros at all.
So are you saying that assuming Value classes that support constant foldings, the Scala compiler and the JVM could make the non-macro code as efficient as the macro-generated version?