-- Memcached interface.-- Copyright (C) 2005 Evan Martin <martine@danga.com>moduleNetwork.Memcache.Serializable(Serializable,serialize,deserialize)whereimportData.ByteString(ByteString)importCodec.Binary.UTF8.Light(encode,decode)-- It'd be nice to use "show" for serialization, but when we-- serialize a String we want to serialize it without the quotes.-- TODO:-- - allow serializing bytes as Ptr-- to do this, add a "putToHandle", etc. method in Serializable-- where the default uses serialize, but for Ptr uses socket stuff.--import Foreign.Marshal.Utils--import Foreign.Storable (Storable, sizeOf)classSerializableawhereserialize::a->ByteStringdeserialize::ByteString->MaybeaserializeL::[a]->ByteStringdeserializeL::ByteString->[a]serializeL=error"unimp"deserializeL=error"unimp"instanceSerializableCharwhere-- people will rarely want to serialize a single char,-- but we define them for completeness.serializex=encode[x]deserializes=casedecodesof(c:[])->Justc_->Nothing-- the real use is for serializing strings.serializeL=encodedeserializeL=decodeinstanceSerializableByteStringwhereserialize=iddeserialize=Just-- ...do I really need to copy everything instance of Show?instanceSerializableIntwhereserialize=encode.showdeserialize=Just.read.decodeinstance(Serializablea)=>Serializable[a]whereserialize=serializeLdeserialize=Just.deserializeL-- vim: set ts=2 sw=2 et :