54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
type DecodeResult {
|
|
Decoded(text: Text)
|
|
error Failed(message: Text)
|
|
}
|
|
|
|
type BufferResult {
|
|
Ready(bytes: Bytes)
|
|
error Failed(message: Text)
|
|
}
|
|
|
|
fromText(text: Text) (bytes: Bytes) {
|
|
bytes = dever.system.bytesFromText(text)
|
|
}
|
|
|
|
toText(bytes: Bytes) (text: Text) {
|
|
text = decoded(dever.system.bytesToText(bytes))
|
|
}
|
|
|
|
rule decoded(value: DecodeResult) (text: Text)
|
|
value {
|
|
Decoded(text) => text
|
|
Failed(message) => fail(DecodeResult.Failed(message))
|
|
}
|
|
|
|
fromInts(values: List<Int>) (bytes: Bytes) {
|
|
bytes = ready(dever.system.bytesFromInts(values))
|
|
}
|
|
|
|
length(bytes: Bytes) (size: Int >= 0) {
|
|
size = dever.system.bytesLength(bytes)
|
|
}
|
|
|
|
at(bytes: Bytes, index: Int) (value: Int?) {
|
|
value = dever.system.bytesAt(bytes, index)
|
|
}
|
|
|
|
slice(bytes: Bytes, start: Int, end: Int) (value: Bytes) {
|
|
value = ready(dever.system.bytesSlice(bytes, start, end))
|
|
}
|
|
|
|
rule ready(value: BufferResult) (bytes: Bytes)
|
|
value {
|
|
Ready(bytes) => bytes
|
|
Failed(message) => fail(BufferResult.Failed(message))
|
|
}
|
|
|
|
concat(left: Bytes, right: Bytes) (bytes: Bytes) {
|
|
bytes = dever.system.bytesConcat(left, right)
|
|
}
|
|
|
|
fromBase64(text: Text) (bytes: Bytes) {
|
|
bytes = ready(dever.system.bytesFromBase64(text))
|
|
}
|