-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement decodeMessageDelimitedH (decoding from a file handle); fix #61
(#324)
- Loading branch information
1 parent
4e8369d
commit 5eb4ea1
Showing
5 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
syntax = "proto3"; | ||
package test.decode_delimited; | ||
|
||
message Foo { | ||
int32 a = 1; | ||
string b = 2; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Main (main) where | ||
|
||
import qualified Data.ByteString as B | ||
import qualified Data.Text as T | ||
import Data.ProtoLens | ||
import Data.ProtoLens.Encoding.Bytes (runBuilder) | ||
import Lens.Family2 ((&), (.~)) | ||
import Test.Framework.Providers.HUnit (testCase) | ||
import Test.HUnit ((@=?)) | ||
|
||
import Data.ProtoLens.TestUtil | ||
import Proto.DecodeDelimited | ||
import Proto.DecodeDelimited_Fields | ||
|
||
import System.IO (openBinaryFile, hClose, IOMode(ReadMode)) | ||
import System.IO.Temp (withSystemTempFile) | ||
|
||
filename_template :: String | ||
filename_template = "test_decode_delimited" | ||
|
||
main :: IO () | ||
main = testMain | ||
[ testCase "buildDelimited/decodeDelimited-short" (testWithMessage foo1) | ||
, testCase "buildDelimited/decodeDelimited-long" (testWithMessage foo2) | ||
] | ||
where | ||
foo1 = defMessage & a .~ 42 & b .~ "hello" :: Foo | ||
foo2 = defMessage | ||
& a .~ 43 | ||
& b .~ (T.pack . take 300 . repeat $ 'x') :: Foo | ||
|
||
testWithMessage :: (Eq msg, Show msg, Message msg) => msg -> IO () | ||
testWithMessage msg = | ||
let bs = runBuilder . buildMessageDelimited $ msg | ||
in | ||
withSystemTempFile filename_template $ \fname h -> do | ||
B.hPut h bs | ||
hClose h | ||
h' <- openBinaryFile fname ReadMode | ||
any1 <- decodeMessageDelimitedH h' | ||
Right msg @=? any1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters