Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict ByteString support #79

Open
schernichkin opened this issue Dec 27, 2018 · 0 comments
Open

Add strict ByteString support #79

schernichkin opened this issue Dec 27, 2018 · 0 comments

Comments

@schernichkin
Copy link

Exposed API use lazy bytestrings, however internally protobuf works with strict chunks. Some libraries can provide stream of strict bytestrings directly. Having an API which accepts strict bytestrings will allow to get get rid of unnecessary wrapping when feeding protobuf deserializer. Example:

protobufSink :: (Monad m, ReflectDescriptor a, Wire a) => ConduitT ByteString {- strict, taken from http-conduit -} o m a
protobufSink = do
  maybeInput <- await
  case maybeInput of 
    Just input -> go $ runGet messageGetM (LBS.fromStrict input) {- unnecessary wrapping -}
      where 
        go (Failed i s) = fail ("Failed at "++show i++" : "++s)
        go (Finished _ _ a) = return a  
        go (Partial f) = f . fmap LBS.fromStrict {- unnecessary wrapping -} <$> await >>= go
    Nothing -> fail "No input."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant