module Sound.OSC.Coding.Cast where
import Data.Char
import Data.Word
import qualified Data.Binary.IEEE754 as I
import Sound.OSC.Coding.Convert
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 (int_to_word8 . ord) s ++ [0]
cstr_str :: [Word8] -> String
cstr_str = map (chr . word8_to_int) . takeWhile (/= 0)
str_pstr :: String -> [Word8]
str_pstr s = int_to_word8 (length s) : map (int_to_word8 . ord) s
pstr_str :: [Word8] -> String
pstr_str = map (chr . word8_to_int) . drop 1