add word8 and int
This commit is contained in:
parent
b47c1b2ed1
commit
7ed17f5b6d
2 changed files with 29 additions and 0 deletions
|
@ -31,7 +31,9 @@ module Data.ByteArray.Builder
|
|||
, word64Dec
|
||||
, word32Dec
|
||||
, word16Dec
|
||||
, word8Dec
|
||||
, int64Dec
|
||||
, intDec
|
||||
, word64PaddedUpperHex
|
||||
, word32PaddedUpperHex
|
||||
, word16PaddedUpperHex
|
||||
|
@ -271,6 +273,12 @@ word32Dec w = fromBounded Nat.constant (Bounded.word32Dec w)
|
|||
word16Dec :: Word16 -> Builder
|
||||
word16Dec w = fromBounded Nat.constant (Bounded.word16Dec w)
|
||||
|
||||
-- | Encodes an unsigned 8-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the
|
||||
-- argument was zero.
|
||||
word8Dec :: Word8 -> Builder
|
||||
word8Dec w = fromBounded Nat.constant (Bounded.word8Dec w)
|
||||
|
||||
-- | Encode a double-floating-point number, using decimal notation or
|
||||
-- scientific notation depending on the magnitude. This has undefined
|
||||
-- behavior when representing @+inf@, @-inf@, and @NaN@. It will not
|
||||
|
@ -285,6 +293,13 @@ doubleDec w = fromBounded Nat.constant (Bounded.doubleDec w)
|
|||
int64Dec :: Int64 -> Builder
|
||||
int64Dec w = fromBounded Nat.constant (Bounded.int64Dec w)
|
||||
|
||||
-- | Encodes a signed machine-sized integer as decimal.
|
||||
-- This encoding never starts with a zero unless the argument was zero.
|
||||
-- Negative numbers are preceded by a minus sign. Positive numbers
|
||||
-- are not preceded by anything.
|
||||
intDec :: Int -> Builder
|
||||
intDec w = fromBounded Nat.constant (Bounded.intDec w)
|
||||
|
||||
-- | Encode a 64-bit unsigned integer as hexadecimal, zero-padding
|
||||
-- the encoding to 16 digits. This uses uppercase for the alphabetical
|
||||
-- digits. For example, this encodes the number 1022 as @00000000000003FE@.
|
||||
|
|
|
@ -28,7 +28,9 @@ module Data.ByteArray.Builder.Bounded
|
|||
, word64Dec
|
||||
, word32Dec
|
||||
, word16Dec
|
||||
, word8Dec
|
||||
, int64Dec
|
||||
, intDec
|
||||
, word64PaddedUpperHex
|
||||
, word32PaddedUpperHex
|
||||
, word16PaddedUpperHex
|
||||
|
@ -151,6 +153,11 @@ word32Dec (W32# w) = wordCommonDec# w
|
|||
word16Dec :: Word16 -> Builder 5
|
||||
word16Dec (W16# w) = wordCommonDec# w
|
||||
|
||||
-- | Requires up to 3 bytes. Encodes an unsigned 8-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the argument was zero.
|
||||
word8Dec :: Word8 -> Builder 3
|
||||
word8Dec (W8# w) = wordCommonDec# w
|
||||
|
||||
-- | Requires up to 20 bytes. Encodes a signed 64-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the argument was zero.
|
||||
-- Negative numbers are preceded by a minus sign. Positive numbers
|
||||
|
@ -158,6 +165,13 @@ word16Dec (W16# w) = wordCommonDec# w
|
|||
int64Dec :: Int64 -> Builder 20
|
||||
int64Dec (I64# w) = int64Dec# w
|
||||
|
||||
-- | Requires up to 20 bytes. Encodes a signed machine-sized integer
|
||||
-- as decimal. This encoding never starts with a zero unless the
|
||||
-- argument was zero. Negative numbers are preceded by a minus sign.
|
||||
-- Positive numbers are not preceded by anything.
|
||||
intDec :: Int -> Builder 20
|
||||
intDec (I# w) = int64Dec# w
|
||||
|
||||
-- Requires a number of bytes that is bounded by the size of
|
||||
-- the word. This is only used internally.
|
||||
wordCommonDec# :: Word# -> Builder n
|
||||
|
|
Loading…
Reference in a new issue