add word32Dec builder
This commit is contained in:
parent
5d3d6d1afd
commit
22dfde2936
2 changed files with 17 additions and 1 deletions
|
@ -27,6 +27,7 @@ module Data.ByteArray.Builder.Small
|
|||
-- * Encode Integral Types
|
||||
-- ** Human-Readable
|
||||
, word64Dec
|
||||
, word32Dec
|
||||
, word16Dec
|
||||
, int64Dec
|
||||
, word64PaddedUpperHex
|
||||
|
@ -80,6 +81,9 @@ instance Semigroup Builder where
|
|||
instance Monoid Builder where
|
||||
mempty = Builder $ \_ off0 _ s0 -> (# s0, off0 #)
|
||||
|
||||
instance IsString Builder where
|
||||
fromString = shortTextUtf8 . TS.fromString
|
||||
|
||||
-- | Run a builder. An accurate size hint is important for good performance.
|
||||
-- The size hint should be slightly larger than the actual size.
|
||||
run ::
|
||||
|
@ -260,6 +264,12 @@ shortTextJsonString a =
|
|||
word64Dec :: Word64 -> Builder
|
||||
word64Dec w = fromUnsafe (Unsafe.word64Dec w)
|
||||
|
||||
-- | Encodes an unsigned 16-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the
|
||||
-- argument was zero.
|
||||
word32Dec :: Word32 -> Builder
|
||||
word32Dec w = fromUnsafe (Unsafe.word32Dec w)
|
||||
|
||||
-- | Encodes an unsigned 16-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the
|
||||
-- argument was zero.
|
||||
|
|
|
@ -26,6 +26,7 @@ module Data.ByteArray.Builder.Small.Unsafe
|
|||
-- * Encode Integral Types
|
||||
-- ** Human-Readable
|
||||
, word64Dec
|
||||
, word32Dec
|
||||
, word16Dec
|
||||
, int64Dec
|
||||
, word64PaddedUpperHex
|
||||
|
@ -142,7 +143,12 @@ doubleDec (D# d) = Builder (\arr off0 s0 -> doubleDec# d arr off0 s0)
|
|||
word64Dec :: Word64 -> Builder 19
|
||||
word64Dec (W64# w) = wordCommonDec# w
|
||||
|
||||
-- | Requires up to 19 bytes. Encodes an unsigned 64-bit integer as decimal.
|
||||
-- | Requires up to 10 bytes. Encodes an unsigned 32-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the argument was zero.
|
||||
word32Dec :: Word32 -> Builder 10
|
||||
word32Dec (W32# w) = wordCommonDec# w
|
||||
|
||||
-- | Requires up to 5 bytes. Encodes an unsigned 16-bit integer as decimal.
|
||||
-- This encoding never starts with a zero unless the argument was zero.
|
||||
word16Dec :: Word16 -> Builder 5
|
||||
word16Dec (W16# w) = wordCommonDec# w
|
||||
|
|
Loading…
Reference in a new issue