typelevel / typelevel/cats-parse

Non-string inputs?

Open
#281 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
245
Forks
51
Avg merge
3h 20m
Merged PRs (30d)
1

Description

Has any thought been given to abstracting over the input type? I'm thinking specifically of binary inputs like Array[Byte], fs2.Chunk, scodec.bits.ByteVector, or java.nio.ByteBuffer. I'm struggling to compete with an HTTP/1 parser that works on Array[Byte].

The obvious answer is scodec. The old fs2-http parser built on it, while beautiful, is also much slower. I'm dreaming of a scodec with the cats-parse mutability trick.

I spiked on it a bit. Problems I encountered:

  • To remain compatible, we have to do unspeakable things with the String and Char based parsers when the underlying type is binary. If we added binary parsers, we'd have to do unspeakable things when the underlying type is characters.
  • Some desired types, like BitVector, are Long-indexed instead of Int. This ripples at least into State and Expectation.
  • A typeclass for inputs seems the right way, but maintaining compatibility gets even harder.
  • All of this could be overcome with a parallel BinParser and BinParser0, but the duplication is an awful shame. It might not even be the same library anymore.

A more modest abstraction is to accept CharSequence as input, at which point we can wrap binary inputs with something like Netty's AsciiString. It's still abusive with respect to Char vs. Byte. It also doesn't help with HTTP/2, where we might benefit from a BitVector.

This is probably all a terrible idea, but I thought I'd ask.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing String- and Char-based parsers, then trace how input types affect State and Expectation. Compare the proposed typeclass, CharSequence, and parallel BinParser/BinParser0 approaches against Array[Byte], fs2.Chunk, ByteVector, and ByteBuffer. Done would require an agreed design that preserves compatibility and addresses the indexing concerns.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.