On this page:
open-fixup-port
fixup-port?
push-fixup
pop-fixup
fixup-port-flush
8.12

5 Fixup Ports🔗ℹ

Added in version 1.1 of package binaryio-lib.

 (require binaryio/fixup-port) package: binaryio-lib

procedure

(open-fixup-port)  fixup-port?

Creates a new fixup port. A fixup port acts as an output port that writes to an internal buffer. It also supports a stack of fixupslocations in the output buffer where additional data must be inserted later. The primary use case for fixups is length-prefixed data, where the length is not known in advance.

Operations on fixup ports are not thread-safe.

procedure

(fixup-port? v)  boolean?

  v : any/c
Returns #t if v is a fixup port created by open-fixup-port, #f otherwise.

procedure

(push-fixup fp [size])  void?

  fp : fixup-port?
  size : (or/c exact-positive-integer? #f) = #f
Pushes a new fixup corresponding to the current location in the output buffer. If size is an integer, then size bytes are reserved for the fixup and its value must be exactly size bytes; otherwise the fixup’s value may be any size. (Sized fixups may have better performance than unsized fixups.)

procedure

(pop-fixup fp fixup)  void?

  fp : fixup-port?
  fixup : (-> exact-nonnegative-integer? bytes?)
Pops the current fixup and sets its value to the result of (fixup len), where len is the number of bytes (including subsequent fixup values) written to fp since the fixup was pushed.

If the fixup was created with size size, then (fixup len) must return exactly size bytes, otherwise an error is raised.

procedure

(fixup-port-flush fp out)  void?

  fp : fixup-port?
  out : output-port?
Writes the buffered output and fixups to out. There must be no pending fixups on fp; otherwise an exception is raised.