Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created January 7, 2017 13:40
Show Gist options
  • Save toshi0383/1531f5cec6de9f06e1bfa685fbc2b45b to your computer and use it in GitHub Desktop.
Save toshi0383/1531f5cec6de9f06e1bfa685fbc2b45b to your computer and use it in GitHub Desktop.
{-|
- MP4 Header (UInt8 Array) Parsing
-}
import Data.Char (chr)
toInt32 :: [Int] -> Int
toInt32 (a:b:c:d:[]) = (a*256*256*256) + (b*256*256) + (c*256) + d
toInt32 x = error "Unexpected parameter"
toString32 :: [Int] -> String
toString32 (a:b:c:d:[]) = map chr [a,b,c,d]
toString32 x = error "Unexpected parameter"
main = do
print $ "size:" ++ (show $ toInt32 sizeBytes) ++ ", type:" ++ map chr typeBytes
where
bufferBytes = [0,6,135,152,102,114,101,101]
sizeBytes = take 4 bufferBytes
typeBytes = (take 4 . drop 4) bufferBytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment