> 32) & 0xffffffff; } sub enc_I8 { $data .= pack "c", $_[0]; } sub enc_I16 { enc_U16 unpack "S", pack "s", $_[0]; } sub enc_I32 { enc_U32 unpack "I", pack "i", $_[0]; } sub enc_DATA { # a dream! $data .= $_[0]; } sub enc_STRING { # should use encode for speed and clarity ;) $data .= pack "v*", map ord, split //, $_[0]; } sub enc_CONSTANT { # nop } 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; } sub enc_HEX { die "enc_HEX not defined for good"; } ]]> ############################################################################# # 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 = * enc $r->{} = (my $array = []); while (length $data) { push @$array, dec_ ; } if ($r->{} ) ; dec -- default -- enc defined $_[0]{} ? $_[0]{ } : ( ); sub dec_ { my $r = {}; bless $r, ::; $r; } sub enc_ { } # $dec_{0x} = sub { $data = $_[0]; my $r; $r->{type} = ""; $r; }; $enc_{} = sub { $data = ""; enc_U16 0x; $data; }; [ => " ", " ", " ;"],