Tree-native binary processing
This commit is contained in:
23
lib/binary.tri
Normal file
23
lib/binary.tri
Normal file
@@ -0,0 +1,23 @@
|
||||
!import "base.tri" !Local
|
||||
!import "list.tri" !Local
|
||||
!import "bytes.tri" !Local
|
||||
|
||||
errUnexpectedEof = 1
|
||||
|
||||
ok = value rest : pair true (pair value rest)
|
||||
err = code rest : pair false (pair code rest)
|
||||
|
||||
readU8 = (bytes : matchList
|
||||
(err errUnexpectedEof t)
|
||||
(h r : ok h r)
|
||||
bytes)
|
||||
|
||||
readBytesTaken = n bytes : bytesTake n bytes
|
||||
readBytesRest = n bytes : bytesDrop n bytes
|
||||
readBytesEnough? = n bytes : equal? (bytesLength (readBytesTaken n bytes)) n
|
||||
|
||||
readBytes = (n bytes :
|
||||
matchBool
|
||||
(ok (readBytesTaken n bytes) (readBytesRest n bytes))
|
||||
(err errUnexpectedEof bytes)
|
||||
(readBytesEnough? n bytes))
|
||||
Reference in New Issue
Block a user