module Rattletrap.Utility.Bytes where

import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Char8 as Latin1
import qualified Data.Text as Text

encodeLatin1 :: Text.Text -> ByteString.ByteString
encodeLatin1 :: Text -> ByteString
encodeLatin1 Text
text = String -> ByteString
Latin1.pack (Text -> String
Text.unpack Text
text)

padBytes :: Integral a => a -> ByteString.ByteString -> ByteString.ByteString
padBytes :: forall a. Integral a => a -> ByteString -> ByteString
padBytes a
size ByteString
bytes = ByteString
bytes
  forall a. Semigroup a => a -> a -> a
<> Int -> Word8 -> ByteString
ByteString.replicate (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
size forall a. Num a => a -> a -> a
- ByteString -> Int
ByteString.length ByteString
bytes) Word8
0x00