[m-dev.] for discussion: reading multibyte integers from binary streams
Julien Fischer
jfischer at opturion.com
Wed Jan 2 22:40:14 AEDT 2019
Hi Zoltan,
On Wed, 2 Jan 2019, Zoltan Somogyi wrote:
> 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".
Those seem unwieldly. I think the name should be fairly generic since
we are very likely to end up with a similar type in stream.m as well.
> 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.
Ok, I'll go ahead and implement the rest of it using that approach.
Julien.
More information about the developers
mailing list