Ah, of course a 0-byte integer has value 0
This commit is contained in:
parent
85fe7b3b07
commit
77fd8e86bf
|
@ -99,10 +99,10 @@
|
|||
(define (next-varint) (eof-guard (read-varint in-port)))
|
||||
|
||||
(define (next-integer n)
|
||||
(when (zero? n) (return (on-fail "Zero-length integer not permitted")))
|
||||
(define acc0 (next-byte))
|
||||
(define acc (if (< acc0 128) acc0 (- acc0 256)))
|
||||
(for/fold [(acc acc)] [(n (in-range (- n 1)))] (+ (* acc 256) (next-byte))))
|
||||
(cond [(zero? n) 0]
|
||||
[else (define acc0 (next-byte))
|
||||
(define acc (if (< acc0 128) acc0 (- acc0 256)))
|
||||
(for/fold [(acc acc)] [(n (in-range (- n 1)))] (+ (* acc 256) (next-byte)))]))
|
||||
|
||||
(define (next-items)
|
||||
(define pos0 (pos))
|
||||
|
|
Loading…
Reference in New Issue