module Rattletrap.Type.U8 where import qualified Data.Word as Word import qualified Rattletrap.BitGet as BitGet import qualified Rattletrap.BitPut as BitPut import qualified Rattletrap.ByteGet as ByteGet import qualified Rattletrap.BytePut as BytePut import qualified Rattletrap.Schema as Schema import qualified Rattletrap.Utility.Json as Json newtype U8 = U8 Word.Word8 deriving (U8 -> U8 -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: U8 -> U8 -> Bool $c/= :: U8 -> U8 -> Bool == :: U8 -> U8 -> Bool $c== :: U8 -> U8 -> Bool Eq, Int -> U8 -> ShowS [U8] -> ShowS U8 -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [U8] -> ShowS $cshowList :: [U8] -> ShowS show :: U8 -> String $cshow :: U8 -> String showsPrec :: Int -> U8 -> ShowS $cshowsPrec :: Int -> U8 -> ShowS Show) instance Json.FromJSON U8 where parseJSON :: Value -> Parser U8 parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Word8 -> U8 fromWord8 forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. FromJSON a => Value -> Parser a Json.parseJSON instance Json.ToJSON U8 where toJSON :: U8 -> Value toJSON = forall a. ToJSON a => a -> Value Json.toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c . U8 -> Word8 toWord8 schema :: Schema.Schema schema :: Schema schema = String -> Value -> Schema Schema.named String "u8" forall a b. (a -> b) -> a -> b $ [Pair] -> Value Json.object [ forall value p. (ToJSON value, KeyValue p) => String -> value -> p Json.pair String "type" String "integer", forall value p. (ToJSON value, KeyValue p) => String -> value -> p Json.pair String "minimum" (forall a. Bounded a => a minBound :: Word.Word8), forall value p. (ToJSON value, KeyValue p) => String -> value -> p Json.pair String "maximum" (forall a. Bounded a => a maxBound :: Word.Word8) ] fromWord8 :: Word.Word8 -> U8 fromWord8 :: Word8 -> U8 fromWord8 = Word8 -> U8 U8 toWord8 :: U8 -> Word.Word8 toWord8 :: U8 -> Word8 toWord8 (U8 Word8 x) = Word8 x bytePut :: U8 -> BytePut.BytePut bytePut :: U8 -> BytePut bytePut = Word8 -> BytePut BytePut.word8 forall b c a. (b -> c) -> (a -> b) -> a -> c . U8 -> Word8 toWord8 bitPut :: U8 -> BitPut.BitPut bitPut :: U8 -> BitPut bitPut = BytePut -> BitPut BitPut.fromBytePut forall b c a. (b -> c) -> (a -> b) -> a -> c . U8 -> BytePut bytePut byteGet :: ByteGet.ByteGet U8 byteGet :: ByteGet U8 byteGet = forall a. String -> ByteGet a -> ByteGet a ByteGet.label String "U8" forall a b. (a -> b) -> a -> b $ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Word8 -> U8 fromWord8 ByteGet Word8 ByteGet.word8 bitGet :: BitGet.BitGet U8 bitGet :: BitGet U8 bitGet = forall a. ByteGet a -> Int -> BitGet a BitGet.fromByteGet ByteGet U8 byteGet Int 1