… | |
… | |
53 | dec_U64 = |
53 | dec_U64 = |
54 | do a1 <- getU16 |
54 | do a1 <- getU16 |
55 | a2 <- getU16 |
55 | a2 <- getU16 |
56 | a3 <- getU16 |
56 | a3 <- getU16 |
57 | a4 <- getU16 |
57 | a4 <- getU16 |
58 | return $ (fI a1) `shiftL` 48 -- please check endians |
58 | return $ (fI a4) `shiftL` 48 |
59 | + (fI a2) `shiftL` 32 |
59 | + (fI a3) `shiftL` 32 |
60 | + (fI a3) `shiftL` 16 |
60 | + (fI a2) `shiftL` 16 |
61 | + (fI a4) |
61 | + (fI a1) |
62 | where fI a = fromIntegral a :: Word64 |
62 | where fI a = fromIntegral a :: Word64 |
63 | |
63 | |
64 | |
64 | |
65 | dec_I8 :: DecS Int8 |
65 | dec_I8 :: DecS Int8 |
66 | dec_I8 = |
66 | dec_I8 = |
… | |
… | |
74 | |
74 | |
75 | dec_I32 :: DecS Int32 |
75 | dec_I32 :: DecS Int32 |
76 | dec_I32 = |
76 | dec_I32 = |
77 | do w16_1 <- getU16 |
77 | do w16_1 <- getU16 |
78 | w16_2 <- getU16 |
78 | w16_2 <- getU16 |
79 | return $ (fI w16_1) `shiftL` 16 -- please cgecj endians |
79 | return $ (fI w16_2) `shiftL` 16 |
80 | + (fI w16_2) |
80 | + (fI w16_1) |
81 | where fI a = fromIntegral a :: Int32 |
81 | where fI a = fromIntegral a :: Int32 |
82 | |
82 | |
83 | dec_DATA :: DecS [Word8] |
83 | dec_DATA :: DecS [Word8] |
84 | dec_DATA = |
84 | dec_DATA = |
85 | do da <- get |
85 | do da <- get |
… | |
… | |
94 | mkstr str [] = |
94 | mkstr str [] = |
95 | (reverse str,[]) |
95 | (reverse str,[]) |
96 | mkstr str (0:rest) = |
96 | mkstr str (0:rest) = |
97 | (reverse str, rest) |
97 | (reverse str, rest) |
98 | mkstr str (c:rest) = |
98 | mkstr str (c:rest) = |
99 | mkstr ((toEnum (fromIntegra c :: Int)):str) rest |
99 | mkstr ((toEnum (fromIntegral c :: Int)):str) rest |
100 | |
100 | |
101 | {- |
101 | {- |
102 | sub dec_STRING { |
102 | sub dec_STRING { |
103 | $data =~ s/^((?:..)*?)(?:\x00\x00|\Z)//s; |
103 | $data =~ s/^((?:..)*?)(?:\x00\x00|\Z)//s; |
104 | # use Encode... |
104 | # use Encode... |
… | |
… | |
134 | putU16 :: Word16 -> DecS () |
134 | putU16 :: Word16 -> DecS () |
135 | putU16 a = |
135 | putU16 a = |
136 | do x <- get |
136 | do x <- get |
137 | let b1 = fromIntegral (a `shiftR` 8) :: Word8 |
137 | let b1 = fromIntegral (a `shiftR` 8) :: Word8 |
138 | b2 = fromIntegral a :: Word8 |
138 | b2 = fromIntegral a :: Word8 |
139 | put (b2:b1:x) -- check endians |
139 | put (b1:b2:x) |
140 | |
140 | |
141 | enc_U8 :: Word8 -> DecS () |
141 | enc_U8 :: Word8 -> DecS () |
142 | enc_U8 = |
142 | enc_U8 = |
143 | putU8 |
143 | putU8 |
144 | |
144 | |
… | |
… | |
148 | |
148 | |
149 | enc_U32 :: Word32 -> DecS () |
149 | enc_U32 :: Word32 -> DecS () |
150 | enc_U32 a = |
150 | enc_U32 a = |
151 | let b1 = fromIntegral (a `shiftR` 16) :: Word16 |
151 | let b1 = fromIntegral (a `shiftR` 16) :: Word16 |
152 | b2 = fromIntegral a :: Word16 |
152 | b2 = fromIntegral a :: Word16 |
153 | putU16 b1 -- check the goddamn endians marc :) |
|
|
154 | putU16 b2 |
153 | putU16 b2 |
|
|
154 | putU16 b1 |
155 | |
155 | |
156 | enc_U64 :: Word64 -> DecS () |
156 | enc_U64 :: Word64 -> DecS () |
157 | enc_U64 a = |
157 | enc_U64 a = |
158 | let b1 = fromIntegral (a `shiftR` 48) :: Word16 |
158 | let b1 = fromIntegral (a `shiftR` 48) :: Word16 |
159 | b2 = fromIntegral (a `shiftR` 32) :: Word16 |
159 | b2 = fromIntegral (a `shiftR` 32) :: Word16 |
160 | b3 = fromIntegral (a `shiftR` 16) :: Word16 |
160 | b3 = fromIntegral (a `shiftR` 16) :: Word16 |
161 | b4 = fromIntegral a :: Word16 |
161 | b4 = fromIntegral a :: Word16 |
162 | putU16 b1 -- check the goddamn endians marc :) |
162 | putU16 b4 |
|
|
163 | putU16 b3 |
163 | putU16 b2 |
164 | putU16 b2 |
164 | putU16 b3 |
165 | putU16 b1 |
165 | putU16 b4 |
|
|
166 | |
166 | |
167 | enc_I8 :: Int8 -> DecS () |
167 | enc_I8 :: Int8 -> DecS () |
168 | enc_I8 a = |
168 | enc_I8 a = |
169 | putU8 (fromIntegral a :: Word8) |
169 | putU8 (fromIntegral a :: Word8) |
170 | |
170 | |
171 | enc_I16 :: Int16 -> DecS () |
171 | enc_I16 :: Int16 -> DecS () |
172 | enc_I16 a = |
172 | enc_I16 a = |
173 | let b1 = fromIntegral (a `shiftR` 8) :: Word8 |
173 | let b1 = fromIntegral (a `shiftR` 8) :: Word8 |
174 | b2 = fromIntegral a :: Word8 |
174 | b2 = fromIntegral a :: Word8 |
|
|
175 | putU8 b2 |
175 | putU8 b1 |
176 | putU8 b1 |
176 | putU8 b2 |
|
|
177 | |
177 | |
178 | enc_I32 :: Int32 -> DecS () |
178 | enc_I32 :: Int32 -> DecS () |
179 | enc_I32 a = |
179 | enc_I32 a = |
180 | let |
180 | let |
181 | b1 = fromIntegral (a `shiftR` 16) :: Word16 |
181 | b1 = fromIntegral (a `shiftR` 16) :: Word16 |
182 | b2 = fromIntegral a :: Word16 |
182 | b2 = fromIntegral a :: Word16 |
|
|
183 | putU16 b2 |
183 | putU16 b1 |
184 | putU16 b1 |
184 | putU16 b2 |
|
|
185 | |
185 | |
186 | enc_DATA :: [Word8] -> DecS () |
186 | enc_DATA :: [Word8] -> DecS () |
187 | enc_DATA d = |
187 | enc_DATA d = |
188 | do x <- get |
188 | do x <- get |
189 | put $ (reverse d) ++ x |
189 | put $ (reverse d) ++ x |