Different ByteStrings, what now?

Hello once again! My forays into Haskell are once again stopped by my weak Haskell Fu. I am working with ProtocolBuffers and so far everything worked fine, but now I have encountered a problem. I am trying to serialize a message that contains, among other things, a blob of binary data. My problem now is to get that binary data into the message. The message requires the data type Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type Data.ByteString. How can I turn one into the other or get my data into the right format in te first place? I tried to find a function to solve this, but I couldn't find it in the ProtoBuff documentation. Thanks Raf

On Thursday 02 June 2011 15:23:40, Raphael Päbst wrote:
Hello once again! My forays into Haskell are once again stopped by my weak Haskell Fu. I am working with ProtocolBuffers and so far everything worked fine, but now I have encountered a problem. I am trying to serialize a message that contains, among other things, a blob of binary data. My problem now is to get that binary data into the message. The message requires the data type Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type Data.ByteString. How can I turn one into the other or get my data into the right format in te first place? I tried to find a function to solve this, but I couldn't find it in the ProtoBuff documentation.
I don't know ProtoBuff, but I suspect that one uses lazy ByteStrings [there are only lazy and strict ByteStrings in the bytestring package], in which case you could simply transform your strict ByteString via strictToLazy bs = Data.ByteString.Lazy.fromChunks [bs] into a lazy ByteString (the reverse transformation would be Data.ByteString.concat . Data.ByteString.Lazy.toChunks, but it might be better to work with lists of strict ByteStrings as delivered by toChunks).
Thanks
Raf

Ah thanks, that's it. I know about ByteString and ByteString.Lazy, but
the error message confused me, since it said it was expecting
Text.ProtocoelBuffers.Header.ByteString of which I had never heard
before.
Raf
On 6/2/11, Daniel Fischer
On Thursday 02 June 2011 15:23:40, Raphael Päbst wrote:
Hello once again! My forays into Haskell are once again stopped by my weak Haskell Fu. I am working with ProtocolBuffers and so far everything worked fine, but now I have encountered a problem. I am trying to serialize a message that contains, among other things, a blob of binary data. My problem now is to get that binary data into the message. The message requires the data type Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type Data.ByteString. How can I turn one into the other or get my data into the right format in te first place? I tried to find a function to solve this, but I couldn't find it in the ProtoBuff documentation.
I don't know ProtoBuff, but I suspect that one uses lazy ByteStrings [there are only lazy and strict ByteStrings in the bytestring package], in which case you could simply transform your strict ByteString via
strictToLazy bs = Data.ByteString.Lazy.fromChunks [bs]
into a lazy ByteString (the reverse transformation would be Data.ByteString.concat . Data.ByteString.Lazy.toChunks, but it might be better to work with lists of strict ByteStrings as delivered by toChunks).
Thanks
Raf

On Thursday 02 June 2011 15:46:14, Raphael Päbst wrote:
Ah thanks, that's it. I know about ByteString and ByteString.Lazy, but the error message confused me, since it said it was expecting Text.ProtocolBuffers.Header.ByteString of which I had never heard before.
Raf
Yes, that's quite understandable. How GHC prints types in error messages depends (in a non-obvious way, unfortunately) on the way in which they were imported. Often that's helpful (Explicitly.Imported.Module.Type vs. Some.Very.Well.Hidden.Module.Never.Heard.Of.Type), but sometimes it leads to confusing results (as here).
participants (2)
-
Daniel Fischer
-
Raphael Päbst