From 071b55568d4482f4e1f6a637f4c292b429aec5da Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Wed, 4 Sep 2019 14:34:33 -0400 Subject: [PATCH] add decWord for machine-sized words --- src/Data/ByteArray/Builder.hs | 7 +++++++ src/Data/ByteArray/Builder/Bounded.hs | 7 +++++++ 2 files changed, 14 insertions(+) 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