[Haskell-cafe] ByteString and ByteString.Builder questions

Viktor Dukhovni ietf-dane at dukhovni.org
Thu Nov 30 08:07:25 UTC 2023


On Thu, Nov 30, 2023 at 06:58:32AM +0000, Zoran BoĆĄnjak wrote:

> Thanks for your answer. That makes sense. In particular the fact that
> there should be no need to read own output.
> 
> However, one problem remains. Data format I am working with contains a
> total-length prefix. That is: 2 bytes of total length somewhere in the
> header of the message (header is of the fixed length). But the builder
> does not directly provide length.

I knew you'd eventually ask this question.

> So, how do I suppose to effectively encode the message in the form:
> 
> msg = header <> chunk1 <> chunk2 <> ...

Take a look at my DNS Stub resolver codec:

    https://github.com/dnsbase/dnsbase/blob/7f381795d190ff4096095e90c34a5d3a16ef91c1/internal/Net/DNSBase/Encode/Internal/State.hs#L65-L133

and its "passLen" function:

    https://github.com/dnsbase/dnsbase/blob/7f381795d190ff4096095e90c34a5d3a16ef91c1/internal/Net/DNSBase/Encode/Internal/State.hs#L297-L302

-- 
    Viktor.


More information about the Haskell-Cafe mailing list