On Thu, May 14, 2009 at 8:57 PM, David Leimbach <leimy2k@gmail.com> wrote:
On Thu, May 14, 2009 at 8:54 PM, Don Stewart <dons@galois.com> wrote:> I'm speaking specifically of the encode/decode functions. I have no idea howOh, 'encode' has type:
> they're implemented.
>
> Are you saying that encode is doing something really simple and the default
> encodings for things just happen to be big endian? If so, then I understand
> the pain.... but it still means I have to roll my own :-) I guess if one must
> choose, big endian kind of makes sense, except that the whole world is little
> endian now, except for networks :-) (No one *really* cares about anything but
> x86 anyway these days right?)
encode :: Binary a => a -> ByteString
it just encodes with the default instances, which are all network order:
http://en.wikipedia.org/wiki/Endianness#Endianness_in_networkingYeah I understand that Big Endian == Network Byte Order... which would be true, if I wasn't talking about Plan 9's 9P protocol which specifies little endian bytes on the wire (as far as I can tell anyway from the man page).DaveFYI here's what I've ended up trying to write to negotiate the "version" of a 9p server:main = withSocketsDo $doainfo <- getAddrInfo Nothing (Just "127.0.0.1") (Just "6872") -- hardcoded for now, it's an IRC filesystem serverlet a = head ainfosock <- socket AF_INET Stream defaultProtocolconnect sock (addrAddress a)sendAll sock $ (toLazyByteString (putWord32le (fromIntegral (16 ::Int32))))sendAll sock $ (encode (100 ::Int8))sendAll sock $ (toLazyByteString (putWord32le (fromIntegral (1024 ::Int32))))sendAll sock $ (encode (C.pack "9P2000"))
I feel like I should use wireshark or something to watch the bytes :-) I'm not feeling very sure about this.
-- Don