mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Introduces Bytes class (#1019)
This introduces a new `Bytes` standard library class, for working with binary data. * Add Bytes class to the standard library * Change CLI to eval `output.bytes` * Change code generators to map Bytes to respective underlying type * Add subscript and concat operator support * Add binary encoding for Bytes * Add PCF and Plist rendering for Bytes Co-authored-by: Kushal Pisavadia <kushi.p@gmail.com>
This commit is contained in:
@@ -87,6 +87,7 @@ internal class BinaryEvaluator(
|
||||
private const val CODE_CLASS: Byte = 0xC
|
||||
private const val CODE_TYPEALIAS: Byte = 0xD
|
||||
private const val CODE_FUNCTION: Byte = 0xE
|
||||
private const val CODE_BYTES: Byte = 0xF
|
||||
private const val CODE_PROPERTY: Byte = 0x10
|
||||
private const val CODE_ENTRY: Byte = 0x11
|
||||
private const val CODE_ELEMENT: Byte = 0x12
|
||||
@@ -122,6 +123,13 @@ internal class BinaryEvaluator(
|
||||
packer.packString(value.unit.toString())
|
||||
}
|
||||
|
||||
override fun visitBytes(value: VmBytes) {
|
||||
packer.packArrayHeader(2)
|
||||
packer.packInt(CODE_BYTES.toInt())
|
||||
packer.packBinaryHeader(value.bytes.size)
|
||||
packer.addPayload(value.bytes)
|
||||
}
|
||||
|
||||
override fun visitIntSeq(value: VmIntSeq) {
|
||||
packer.packArrayHeader(4)
|
||||
packer.packInt(CODE_INTSEQ.toInt())
|
||||
|
||||
@@ -632,7 +632,7 @@ abstract class AbstractServerTest {
|
||||
content
|
||||
|
||||
$tripleQuote
|
||||
base64 = "Y29udGVudAo="
|
||||
bytes = Bytes(99, 111, 110, 116, 101, 110, 116, 10)
|
||||
}
|
||||
res2 {
|
||||
uri = "modulepath:/dir1/resource1.txt"
|
||||
@@ -640,7 +640,7 @@ abstract class AbstractServerTest {
|
||||
content
|
||||
|
||||
$tripleQuote
|
||||
base64 = "Y29udGVudAo="
|
||||
bytes = Bytes(99, 111, 110, 116, 101, 110, 116, 10)
|
||||
}
|
||||
res3 {
|
||||
ressy = "the module2 output"
|
||||
|
||||
Reference in New Issue
Block a user