"") ############################################################################# putU8 :: Word8 -> DecS () putU8 a = do x <- get put (a:x) return () putU16 :: Word16 -> DecS () putU16 a = do x <- get let b1 = fromIntegral (a `shiftR` 8) :: Word8 b2 = fromIntegral a :: Word8 put (b2:b1:x) -- check endians enc_U8 :: Word8 -> DecS () enc_U8 = putU8 enc_U16 :: Word16 -> DecS () enc_U16 = putU16 enc_U32 :: Word32 -> DecS () enc_U32 a = let b1 = fromIntegral (a `shiftR` 16) :: Word16 b2 = fromIntegral a :: Word16 putU16 b1 -- check the goddamn endians marc :) putU16 b2 enc_U64 :: Word64 -> DecS () enc_U64 a = let b1 = fromIntegral (a `shiftR` 48) :: Word16 b2 = fromIntegral (a `shiftR` 32) :: Word16 b3 = fromIntegral (a `shiftR` 16) :: Word16 b4 = fromIntegral a :: Word16 putU16 b1 -- check the goddamn endians marc :) putU16 b2 putU16 b3 putU16 b4 enc_I8 :: Int8 -> DecS () enc_I8 a = putU8 (fromIntegral a :: Word8) enc_I16 :: Int16 -> DecS () enc_I16 a = let b1 = fromIntegral (a `shiftR` 8) :: Word8 b2 = fromIntegral a :: Word8 putU8 b1 putU8 b2 enc_I32 :: Int32 -> DecS () enc_I32 a = let b1 = fromIntegral (a `shiftR` 16) :: Word16 b2 = fromIntegral a :: Word16 putU16 b1 putU16 b2 enc_DATA :: [Word8] -> DecS () enc_DATA d = do x <- get put $ (reverse d) ++ x enc_STRING :: String -> DecS () enc_STRING s = do let mstr = reverse s putall (u:ls) = do putU8 u putall ls putall [] = return () putall mstr putU8 0 enc_CONSTANT :: a -> DecS () enc_CONSTANT _ = return () enc_password :: Password -> DecS () enc_password p = enc_U64 p {- marc??? sub enc_password { require Math::BigInt; # I insist on 32-bit-perl.. should use C # $hash must be 64 bit my $hash = new Math::BigInt; $hash = $hash * 1055 + ord for split //, $_[0]; enc_U64 $hash; } -} ]]> ############################################################################# # types ############################################################################# # structures ############################################################################# # "less" primitive types ############################################################################# # messages } 1; dec_ :: State [Word8] [Char] dec_ = do -- decode UCS-2 string of length -- the first 0 terminates the string, but not the field enc_ = -- likewise, encode as UCS-2, fill space with 0 dec_ :: State [Word8] [Char] dec_ = do -- decode ASCII string of length -- the first 0 terminates the string, but not the field enc_ = -- likewise, encode as ASCII, fill space with 0 dec_ = do n <- dec return n * (1 / ) enc_ n = enc $ n * -- $r->{} = (my $array = []); while (length $data) { push @$array, dec_ ; } -- decode next only when -- <- dec -- default -- enc defined $_[0]{} ? $_[0]{ s } : ( ); dec_ = do -- result has class -- enc_ s = -- dec__ = do -- type "" -- enc__ = encU16 0x