[m-dev.] for discussion: reading multibyte integers from binary streams

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Jan 2 21:13:26 AEDT 2019



On Wed, 2 Jan 2019 03:24:18 +0000 (UTC), Julien Fischer <jfischer at opturion.com> wrote:
> I would like feedback on (1) the name of this new result type and (2) how much
> information it should actually return.  Here's a couple of proposals:

I would go with something like "multibyte_int_read_result" or "possibly_incomplete_read_result".
The former is more specific, which is better if this is the only use for the type,
while the latter would be preferable if there are any other read prediciates that may
also have truncated final items.
> 2.
> 
>     :- type compound_result(T, U)
>        --->    ok(T)
>        ;       eof
>        ;       incomplete(U)     % arg gives partial bytes for incomplete value
>        ;       error(io.error).
> 
> Alternatively, we could return the bytes already read for an incomplete value.
> (This value is polymorphic since returning a list of bytes for 16-bit values
> seems a bit silly.)  My suspicion is that this approach will be overkill for
> most applications.

I would return the list of bytes read for the incomplete value. You are right,
it is probably overkill for most use cases, but for the ones for which it is not,
nothing else will do.

I wouldn't bother with U; I would make it a list of bytes in all cases, even when
reading int/uint16. (For reading int/uint8, the existing return type would suffice.)

Zoltan.


More information about the developers mailing list