On this page:
read-uint*
write-uint*
read-sint*
write-sint*
read-int*
write-int*
read-bool
write-bool
read-fixed32
read-fixed64
write-fixed32
write-fixed64
read-sfixed32
read-sfixed64
write-sfixed32
write-sfixed64
read-float
read-double
write-float
write-double
read-sized-bytes
write-sized-bytes
read-sized-string
write-sized-string
read-sized
write-sized
read-tag/  type
write-tag/  type
type/  c
8.2

3 Encoding

 (require (lib "protobuf/encoding")) package: protobuf
Low-level functions dealing with the binary wire format of protocol buffers.

procedure

(read-uint* [in max-size])

  (or/c exact-nonnegative-integer? eof-object?)
  in : input-port? = (current-input-port)
  max-size : (or/c exact-positive-integer? #f) = 10

procedure

(write-uint* n [out max-size])  void?

  n : exact-nonnegative-integer?
  out : output-port? = (current-output-port)
  max-size : (or/c exact-positive-integer? #f) = 10
Read/write a variable length unsigned integer. If max-size is not false, it defines the maximum number of bytes that the encoded number may use.

procedure

(read-sint* [in max-size])  (or/c exact-integer? eof-object?)

  in : input-port? = (current-input-port)
  max-size : (or/c exact-positive-integer? #f) = 10

procedure

(write-sint* i [out max-size])  void?

  i : exact-integer?
  out : output-port? = (current-output-port)
  max-size : (or/c exact-positive-integer? #f) = 10
Read/write a variable length signed integer in zigzag encoding. If max-size is not false, it defines the maximum number of bytes that the encoded number may use.

procedure

(read-int* [in])  (or/c exact-integer? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-int* i [out])  void?

  i : exact-integer?
  out : output-port? = (current-output-port)
Read/write a variable length signed integer in tows-complement encoding. The maximum number of bytes used by the encoded number is 10, the maximum bit length of the number is 64.

procedure

(read-bool [in])  (or/c bool? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-bool v [out])  void?

  v : any/c
  out : output-port? = (current-output-port)
Read/write a boolean as a one byte integer.

procedure

(read-fixed32 [in])

  (or/c exact-nonnegative-integer? eof-object?)
  in : input-port? = (current-input-port)

procedure

(read-fixed64 [in])

  (or/c exact-nonnegative-integer? eof-object?)
  in : input-port? = (current-input-port)

procedure

(write-fixed32 n [out])  void?

  n : exact-nonnegative-integer?
  out : output-port? = (current-output-port)

procedure

(write-fixed64 n [out])  void?

  n : exact-nonnegative-integer?
  out : output-port? = (current-output-port)
Read/write unsigned integers as fixed length 32/64-bit values with little endian byte order.

procedure

(read-sfixed32 [in])  (or/c exact-integer? eof-object?)

  in : input-port? = (current-input-port)

procedure

(read-sfixed64 [in])  (or/c exact-integer? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-sfixed32 i [out])  void?

  i : exact-integer?
  out : output-port? = (current-output-port)

procedure

(write-sfixed64 i [out])  void?

  i : exact-integer?
  out : output-port? = (current-output-port)
Read/write signed integers as fixed length 32/64-bit values in twos-complement encoding with little endian byte order.

procedure

(read-float [in])  (or/c real? eof-object?)

  in : input-port? = (current-input-port)

procedure

(read-double [in])  (or/c real? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-float x [out])  void?

  x : real?
  out : output-port? = (current-output-port)

procedure

(write-double x [out])  void?

  x : real?
  out : output-port? = (current-output-port)
Read/write real numbers as fixed length 32/64-bit IEEE floating point values with little endian byte order.

procedure

(read-sized-bytes [in])  (or/c bytes? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-sized-bytes bstr [out])  void?

  bstr : bytes?
  out : output-port? = (current-output-port)
Read/write a byte string with size prefix. The size is read and written using read-uint* and write-uint*.

procedure

(read-sized-string [in])  (or/c string? eof-object?)

  in : input-port? = (current-input-port)

procedure

(write-sized-string str [out])  void?

  str : string?
  out : output-port? = (current-output-port)
Read/write a UTF-8 encoded string with size prefix. The size in bytes is read and written using read-uint* and write-uint*.

procedure

(read-sized read [in])  any/c

  read : (-> input-port? any/c)
  in : input-port? = (current-input-port)

procedure

(write-sized write v [out])  any

  write : (-> any/c output-port? any)
  v : any/c
  out : output-port? = (current-output-port)
Read/write any object with size prefix. The size in bytes is read and written using read-uint* and write-uint*.

On input, read is called on an input port limited according to the size prefix. On output, write is called on v and a byte string output port; the buffered output’s length is then written to the actual output port.

procedure

(read-tag/type [in])

  
(or/c tag/c eof-object?)
(or/c exact-nonnegative-integer? eof-object?)
  in : input-port? = (current-input-port)

procedure

(write-tag/type tag type [out])  void?

  tag : tag/c
  type : exact-nonnegative-integer?
  out : output-port? = (current-output-port)
Read/write the tag and type of a protocol buffer message field.

value

type/c : flat-contract?

Contract matching any of the protocol buffer message field wire type enumeration items:
  • 'int*: The field value is encoded as a variable length integer.

  • '64bit: The field value is always encoded in 64 bits.

  • '32bit: The field value is always encoded in 32 bits.

  • 'sized: The field value is encoded with a byte size prefix.