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 :: Float -> Word32
f32_w32 = Float -> Word32
I.floatToWord
w32_f32 :: Word32 -> Float
w32_f32 :: Word32 -> Float
w32_f32 = Word32 -> Float
I.wordToFloat
f64_w64 :: Double -> Word64
f64_w64 :: Double -> Word64
f64_w64 = Double -> Word64
I.doubleToWord
w64_f64 :: Word64 -> Double
w64_f64 :: Word64 -> Double
w64_f64 = Word64 -> Double
I.wordToDouble
str_cstr :: String -> [Word8]
str_cstr :: String -> [Word8]
str_cstr String
s = (Char -> Word8) -> String -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Word8
int_to_word8 (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) String
s [Word8] -> [Word8] -> [Word8]
forall a. [a] -> [a] -> [a]
++ [Word8
0]
cstr_str :: [Word8] -> String
cstr_str :: [Word8] -> String
cstr_str = (Word8 -> Char) -> [Word8] -> String
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Char
chr (Int -> Char) -> (Word8 -> Int) -> Word8 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
word8_to_int) ([Word8] -> String) -> ([Word8] -> [Word8]) -> [Word8] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8 -> Bool) -> [Word8] -> [Word8]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0)
str_pstr :: String -> [Word8]
str_pstr :: String -> [Word8]
str_pstr String
s = Int -> Word8
int_to_word8 (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) Word8 -> [Word8] -> [Word8]
forall a. a -> [a] -> [a]
: (Char -> Word8) -> String -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Word8
int_to_word8 (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) String
s
pstr_str :: [Word8] -> String
pstr_str :: [Word8] -> String
pstr_str = (Word8 -> Char) -> [Word8] -> String
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Char
chr (Int -> Char) -> (Word8 -> Int) -> Word8 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
word8_to_int) ([Word8] -> String) -> ([Word8] -> [Word8]) -> [Word8] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Word8] -> [Word8]
forall a. Int -> [a] -> [a]
drop Int
1