Skip to content

Add strict ByteString support #79

Description

@schernichkin

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions