Class BufferConsumer

extends Object
A consumer of data.
Due to the operations that take an offset (like put-int16-big-endian), consumers must buffer their data to allow future modifications of it.
Deprecated.

Class summary


size -> int
The size of the consumed data.
write-byte byte/int -> none
Writes the byte into the consumer.
put-byte offset/int data/int -> none
Writes the byte of data at the given offset.
write data/Data from/int= to/int= -> int
Writes the given data into this consumer.
write-producer producer/Producer -> none
Writes the data from the producer into this consumer.
grow amount/int -> none
Grows this consumer by amount bytes.
reserve amount/int -> none
Reserves amount bytes.
close -> none
Closes this buffer.
clear -> none
Resets the buffer, discarding all accumulated data.
write-int64-big-endian data/int -> none
Writes the 64 bits of data at the end.
write-int32-big-endian data/int -> none
Writes the 32 bits of data at the end.
write-int16-big-endian data/int -> none
Writes the 16 bits of data at the end.
put-int64-big-endian offset/int data/int -> none
Writes the 64 bits of data at the given offset.
put-int32-big-endian offset/int data/int -> none
Writes the 32 bits of data at the given offset.
put-int16-big-endian offset/int data/int -> none
Writes the 16 bits of data at the given offset.
write-int64-little-endian data/int -> none
Writes the 64 bits of data at the end.
write-int32-little-endian data/int -> none
Writes the 32 bits of data at the end.
write-int16-little-endian data/int -> none
Writes the 16 bits of data at the end.
put-int64-little-endian offset/int data/int -> none
Writes the 64 bits of data at the given offset.
put-int32-little-endian offset/int data/int -> none
Writes the 32 bits of data at the given offset.
put-int16-little-endian offset/int data/int -> none
Writes the 16 bits of data at the given offset.
operator == other/any -> bool
Whether this object is equal to the other.
stringify -> string
Stringifies this object.

Methods

clear -> none
Resets the buffer, discarding all accumulated data.

close -> none
Closes this buffer.
It is an error to write to this consumer after a call to close.
It is legal to close this consumer multiple times.

grow amount/int -> none
Grows this consumer by amount bytes.
This operation is equivalent to writing an empty byte-array of size amount.
The allocated bytes are filled with 0s and can be accessed with all methods that take an offset (such as put-int16-big-endian).
Further write operations (like write-byte or write) append their data after the grown bytes.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

put-byte offset/int data/int -> none
Writes the byte of data at the given offset.
The offset must be valid and the backing store must be able to write a byte at this offset. If necessary use grow before doing this operation.

put-int16-big-endian offset/int data/int -> none
Writes the 16 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 16 bits at this offset. If necessary use grow before doing this operation.

put-int16-little-endian offset/int data/int -> none
Writes the 16 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 16 bits at this offset. If necessary use grow before doing this operation.

put-int32-big-endian offset/int data/int -> none
Writes the 32 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 32 bits at this offset. If necessary use grow before doing this operation.

put-int32-little-endian offset/int data/int -> none
Writes the 32 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 32 bits at this offset. If necessary use grow before doing this operation.

put-int64-big-endian offset/int data/int -> none
Writes the 64 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 64 bits at this offset. If necessary use grow before doing this operation.

put-int64-little-endian offset/int data/int -> none
Writes the 64 bits of data at the given offset.
The offset must be valid and the backing store must be able to write 64 bits at this offset. If necessary use grow before doing this operation.

reserve amount/int -> none
Reserves amount bytes.
Doesn't change the size of this buffer, but increases the size of the backing store.
This method is purely for efficiency, so that this consumer doesn't need to regrow its internal backing store too often.

The size of the consumed data.
This value increases with operations that write into this consumer, such as write-byte or write. It is reset with clear, and unchanged by operations that take an offset, such as put-int16-big-endian.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write data/Data from/int=0 to/int=data.byte-size -> int
Writes the given data into this consumer.

write-byte byte/int -> none
Writes the byte into the consumer.
This is equivalent to using write with a one-sized byte array.

Writes the 16 bits of data at the end.
The backing store is automatically grown by 16 bits.

Writes the 16 bits of data at the end.
The backing store is automatically grown by 16 bits.

Writes the 32 bits of data at the end.
The backing store is automatically grown by 32 bits.

Writes the 32 bits of data at the end.
The backing store is automatically grown by 32 bits.

Writes the 64 bits of data at the end.
The backing store is automatically grown by 64 bits.

Writes the 64 bits of data at the end.
The backing store is automatically grown by 64 bits.

write-producer producer/Producer -> none
Writes the data from the producer into this consumer.