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

Cleanup bytestring usage #18

Open
jaseemabid opened this issue Mar 27, 2015 · 1 comment
Open

Cleanup bytestring usage #18

jaseemabid opened this issue Mar 27, 2015 · 1 comment

Comments

@jaseemabid
Copy link
Contributor

We use both lazy and strict version interchangeably everywhere. We need to stick to one. I have a feeling that the lazy version might work everywhere.

See http://blog.ezyang.com/2010/08/strings-in-haskell/ for some additional info.

@jaseemabid
Copy link
Contributor Author

Example:

handShakeMsg :: InfoDict -> String -> ByteString
handShakeMsg m peer_id = let pstrlen = concat $ toChunks $ Bin.encode (19 :: Int8)
                             pstr = pack "BitTorrent protocol"
                             reserved = replicate 8 '\0'
                             infoH = infoHash m
                             peerID = pack peer_id
                         in concat [pstrlen, pstr, reserved, infoH, peerID]

Bin.encode returns the lazy version, and concat . toChunks makes it strict.
This might be unnecessary.

Ref: http://stackoverflow.com/questions/1451755/many-types-of-string-bytestring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant