diff --git a/src/Data/ByteArray/Builder.hs b/src/Data/ByteArray/Builder.hs index 6e5ade5..65364c2 100644 --- a/src/Data/ByteArray/Builder.hs +++ b/src/Data/ByteArray/Builder.hs @@ -32,6 +32,7 @@ module Data.ByteArray.Builder , word32Dec , word16Dec , word8Dec + , wordDec , int64Dec , int32Dec , int16Dec @@ -282,6 +283,12 @@ word16Dec w = fromBounded Nat.constant (Bounded.word16Dec w) word8Dec :: Word8 -> Builder word8Dec w = fromBounded Nat.constant (Bounded.word8Dec w) +-- | Encodes an unsigned machine-sized integer as decimal. +-- This encoding never starts with a zero unless the +-- argument was zero. +wordDec :: Word -> Builder +wordDec w = fromBounded Nat.constant (Bounded.wordDec 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 diff --git a/src/Data/ByteArray/Builder/Bounded.hs b/src/Data/ByteArray/Builder/Bounded.hs index 0450234..ecb983d 100644 --- a/src/Data/ByteArray/Builder/Bounded.hs +++ b/src/Data/ByteArray/Builder/Bounded.hs @@ -29,6 +29,7 @@ module Data.ByteArray.Builder.Bounded , word32Dec , word16Dec , word8Dec + , wordDec , int64Dec , int32Dec , int16Dec @@ -162,6 +163,12 @@ word16Dec (W16# w) = wordCommonDec# w word8Dec :: Word8 -> Builder 3 word8Dec (W8# w) = wordCommonDec# w +-- | Requires up to 19 bytes. Encodes an unsigned machine-sized integer +-- as decimal. This encoding never starts with a zero unless the argument +-- was zero. +wordDec :: Word -> Builder 19 +wordDec (W# 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