24 lines
602 B
Plaintext
24 lines
602 B
Plaintext
!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))
|