~williewillus/racket-rfc8949

a932cdbec924fb7abcf6e7aed214088117cbd6c7 — Vincent Lee 3 years ago cca8633
Allow port to be omitted in calls to cbor-read and cbor-write
3 files changed, 4 insertions(+), 4 deletions(-)

M decode.rkt
M encode.rkt
M scribblings/manual.scrbl
M decode.rkt => decode.rkt +1 -1
@@ 218,7 218,7 @@
   cbor-read-list cbor-read-map cbor-read-tag cbor-read-special))

; Deserialize one cbor value from the given input port. Can and will be called reentrantly.
(define (cbor-read config in)
(define (cbor-read config [in (current-input-port)])
  (define header (expect-byte in))
  (let ([major (bitwise-bit-field header 5 8)]
        [additional (bitwise-and header #b11111)])

M encode.rkt => encode.rkt +1 -1
@@ 115,7 115,7 @@
        (write-byte (combine 7 24) out)
        (write-byte inner out))))

(define (cbor-write config v out)
(define (cbor-write config v [out (current-output-port)])
  (cond
    [(and (exact-integer? v) (<= 0 v u64-max))
     (cbor-write-uint v out)]

M scribblings/manual.scrbl => scribblings/manual.scrbl +2 -2
@@ 15,7 15,7 @@ versa.
@section{Usage}
@defproc[(cbor-write [config cbor-config?]
                     [v any/c]
                     [out output-port?])
                     [out output-port? (current-output-port)])
         void?]{
Writes the value @racket[v] to @racket[out].
The following @racket[v] are accepted:


@@ 36,7 36,7 @@ The following @racket[v] are accepted:
}

@defproc[(cbor-read [config cbor-config?]
                    [in input-port?])
                    [in input-port? (current-input-port)])
         any/c]{
Reads a binary-serialized CBOR value from @racket[in].
Major types are decoded as follows: