8000 Decoder: detect end of content · Issue #24 · elm/bytes · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Decoder: detect end of content #24
Open
@cdevienne

Description

@cdevienne

When parsing a protocol chunk by chunk, we need to stop successfully with every thing we decoded so far, and keep the remaining bytes for later.
The current decoder API provides no way to do such a thing.

Two examples of what I need to do when parsing the NATS protocol in Elm Nats:

  • a decoder that read a string up to a delimiter or the end of content. When parsing a message, if the end of line is found then the message is complete. If not, I want to get everything up to the end of the bytes, and keep it for later.
  • a decoder that reads up to N bytes. This is for reading a binary payload: I know the payload size, but it may not be complete. If not, I need to keep it for later.

To workaround this I need to have multiple decode phases, cut the bytes to decode the tail, and I get a complicated recursive function instead of a single Decoder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    < 2CC4 span class="Box-sc-g0xbh4-0 dCKzSy prc-Text-Text-0ima0">None yet

    Development

    No branches or pull requests

    Issue actions

      0