Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,169 @@
|
||||
encode(text: Text) (data: Bytes) {
|
||||
data = dever.bytes.fromText(text)
|
||||
}
|
||||
|
||||
decode(data: Bytes) (text: Text) {
|
||||
text = dever.bytes.toText(data)
|
||||
}
|
||||
|
||||
buffer(values: List<Int>) (data: Bytes) {
|
||||
data = dever.bytes.fromInts(values)
|
||||
}
|
||||
|
||||
cut(data: Bytes, start: Int, end: Int) (part: Bytes) {
|
||||
part = dever.bytes.slice(data, start, end)
|
||||
}
|
||||
|
||||
joinBytes(left: Bytes, right: Bytes) (data: Bytes) {
|
||||
data = dever.bytes.concat(left, right)
|
||||
}
|
||||
|
||||
byteAt(data: Bytes, index: Int) (value: Int?) {
|
||||
value = dever.bytes.at(data, index)
|
||||
}
|
||||
|
||||
byteSize(data: Bytes) (size: Int) {
|
||||
size = dever.bytes.length(data)
|
||||
}
|
||||
|
||||
loop byteStats(data: Bytes) (total: Int, values: List<Int>, count: Int)
|
||||
| each value in data | result |
|
||||
| total | sum value |
|
||||
| values | list value |
|
||||
| count | count |
|
||||
|
||||
loop byteSum(data: Bytes) (total: Int)
|
||||
| each value in data | result |
|
||||
| total | sum value |
|
||||
|
||||
loop byteFirst(data: Bytes) (out: Int?)
|
||||
| each value in data | result |
|
||||
| out | first value |
|
||||
|
||||
loop byteFiltered(data: Bytes) (values: List<Int>)
|
||||
| each value in data | value | result |
|
||||
| values | >= 128 | list value |
|
||||
|
||||
boundedByte(value: Int >= 0 and <= 255) (out: Int) {
|
||||
out = value
|
||||
}
|
||||
|
||||
loop validBytes(data: Bytes) (out: List<Int>)
|
||||
| each value in data | result |
|
||||
| out | list boundedByte(value) |
|
||||
|
||||
captureDecode(data: Bytes) (out: dever.bytes.DecodeResult) {
|
||||
out = result(dever.bytes.toText(data))
|
||||
}
|
||||
|
||||
captureBuffer(values: List<Int>) (out: dever.bytes.BufferResult) {
|
||||
out = result(dever.bytes.fromInts(values))
|
||||
}
|
||||
|
||||
captureCut(data: Bytes, start: Int, end: Int) (out: dever.bytes.BufferResult) {
|
||||
out = result(dever.bytes.slice(data, start, end))
|
||||
}
|
||||
|
||||
applyEncode(text: Text, encode: handler(text: Text) (bytes: Bytes)) (out: Bytes) {
|
||||
out = encode(text)
|
||||
}
|
||||
|
||||
throughHandler(text: Text) (out: Bytes) {
|
||||
out = applyEncode(text, dever.bytes.fromText)
|
||||
}
|
||||
|
||||
type Packet {
|
||||
data: Bytes
|
||||
name: Text
|
||||
}
|
||||
|
||||
keepPacket(packet: Packet) (part: Bytes, original: Packet) {
|
||||
part = dever.bytes.slice(packet.data, 1, 3)
|
||||
original = packet
|
||||
}
|
||||
|
||||
loop repeatedSlice(data: Bytes) (out: List<Bytes>)
|
||||
| each index in range(0, 3) | result |
|
||||
| out | list dever.bytes.slice(data, index, index + 1) |
|
||||
|
||||
appendChunk(chunk: Bytes, state: Bytes) (out: Bytes) {
|
||||
out = dever.bytes.concat(state, chunk)
|
||||
}
|
||||
|
||||
loop concatAll(chunks: List<Bytes>, seed: Bytes) (out: Bytes)
|
||||
| each chunk in chunks | result |
|
||||
| out | fold(acc = seed, appendChunk(chunk, acc)) |
|
||||
|
||||
loop encodeParts(chunks: List<Text>) (out: List<Bytes>)
|
||||
| each chunk in chunks | result |
|
||||
| out | list dever.bytes.fromText(chunk) |
|
||||
|
||||
loop joinParts(chunks: List<Bytes>) (out: Bytes)
|
||||
| each chunk in chunks | result |
|
||||
| out | fold(acc = dever.bytes.fromText(""), appendChunk(chunk, acc)) |
|
||||
|
||||
loop prefixParts(chunks: List<Bytes>) (out: Bytes)
|
||||
| each chunk in chunks | result |
|
||||
| out | fold(acc = dever.bytes.fromText("prefix:"), appendChunk(chunk, acc)) |
|
||||
|
||||
flow fusedBytes(text: Text) (out: Bytes)
|
||||
| step | kind | do |
|
||||
| parts | loop | encodeParts(text.split(text, "")) |
|
||||
| out | loop | joinParts(parts) |
|
||||
|
||||
flow prefixedBytes(text: Text) (out: Bytes)
|
||||
| step | kind | do |
|
||||
| parts | loop | encodeParts(text.split(text, "")) |
|
||||
| out | loop | prefixParts(parts) |
|
||||
|
||||
keepParts(text: Text) (out: Bytes, count: Int) {
|
||||
parts = encodeParts(text.split(text, ""))
|
||||
out = joinParts(parts)
|
||||
count = length(parts)
|
||||
}
|
||||
|
||||
joinSeparated(text: Text) (out: Bytes) {
|
||||
parts = encodeParts(text.split(text, "-"))
|
||||
out = joinParts(parts)
|
||||
}
|
||||
|
||||
markedPart(text: Text) (out: Bytes) { out = dever.bytes.fromText("x" + text) }
|
||||
|
||||
loop markedParts(chunks: List<Text>) (out: List<Bytes>)
|
||||
| each chunk in chunks | result |
|
||||
| out | list markedPart(chunk) |
|
||||
|
||||
joinMarked(text: Text) (out: Bytes) {
|
||||
parts = markedParts(text.split(text, ""))
|
||||
out = joinParts(parts)
|
||||
}
|
||||
|
||||
checkedPart(text: Text) (out: Bytes) {
|
||||
check text != "!" else Invalid
|
||||
out = dever.bytes.fromText(text)
|
||||
}
|
||||
|
||||
loop checkedParts(chunks: List<Text>) (out: List<Bytes>)
|
||||
| each chunk in chunks | result |
|
||||
| out | list checkedPart(chunk) |
|
||||
|
||||
joinChecked(text: Text) (out: Bytes) {
|
||||
parts = checkedParts(text.split(text, ""))
|
||||
out = joinParts(parts)
|
||||
}
|
||||
|
||||
type PartError { error WrongCount(count: Int) }
|
||||
|
||||
guardedJoin(text: Text, allowed: Bool) (out: Bytes) {
|
||||
parts = encodeParts(text.split(text, ""))
|
||||
check allowed else PartError.WrongCount(length(parts))
|
||||
out = joinParts(parts)
|
||||
}
|
||||
|
||||
moveJoinedSource(text: Text) (out: Bytes, original: Text) {
|
||||
alias = text
|
||||
parts = encodeParts(text.split(alias, ""))
|
||||
original = text
|
||||
out = joinParts(parts)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user