module Sound.OSC.Coding.Cast (f32_w32,w32_f32
,f64_w64,w64_f64
,str_cstr,cstr_str
,str_pstr,pstr_str) where
import qualified Data.Binary.IEEE754 as I
import Data.Char
import Data.Word
f32_w32 :: Float -> Word32
f32_w32 = I.floatToWord
w32_f32 :: Word32 -> Float
w32_f32 = I.wordToFloat
f64_w64 :: Double -> Word64
f64_w64 = I.doubleToWord
w64_f64 :: Word64 -> Double
w64_f64 = I.wordToDouble
str_cstr :: String -> [Word8]
str_cstr s = map (fromIntegral . ord) s ++ [0]
cstr_str :: [Word8] -> String
cstr_str = map (chr . fromIntegral) . takeWhile (/= 0)
str_pstr :: String -> [Word8]
str_pstr s = fromIntegral (length s) : map (fromIntegral . ord) s
pstr_str :: [Word8] -> String
pstr_str = map (chr . fromIntegral) . drop 1