leb128-binary-0.1.3: Signed and unsigned LEB128 codec for binary library
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Binary.SLEB128

Description

Signed LEB128 codec. This codec encodes the two's complement of a signed number as described here.

Any getXXX decoder can decode bytes generated using any of the putXXX encoders, provided the encoded number fits in the target type.

WARNING: This is not compatible with the Unsigned LEB128 codec at Data.Binary.ULEB128 nor with the ZigZag LEB128 codec at Data.Binary.ZLEB128.

Synopsis

Documentation

newtype SLEB128 x Source #

Newtype wrapper for Binary encoding and decoding x using the Signed LEB128 codec. Useful in conjunction with DerivingVia.

Constructors

SLEB128 x 

Instances

Instances details
Binary (SLEB128 Int16) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Int32) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Int64) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Int8) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Word16) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Word32) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Word64) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Word8) Source # 
Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Integer) Source #

Note: Maximum allowed number of input bytes is restricted to 1000. Use putNatural if you want a greater limit.

Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Natural) Source #

Note: Maximum allowed number of input bytes is restricted to 1000. Use putNatural if you want a greater limit.

Instance details

Defined in Data.Binary.SLEB128

Binary (SLEB128 Int) Source # 
Instance details

Defined in Data.Binary.SLEB128

Methods

put :: SLEB128 Int -> Put #

get :: Get (SLEB128 Int) #

putList :: [SLEB128 Int] -> Put #

Binary (SLEB128 Word) Source # 
Instance details

Defined in Data.Binary.SLEB128

Put

Get

getInteger Source #

Arguments

:: Int

Maximum number of bytes to consume. If the Integer number can be determined before consuming this number of bytes, it will be. If 0, parsing fails.

Each SLEB128 byte encodes at most 7 bits of data. That is, \(length(encoded) == \lceil\frac{length(data)}{7}\rceil\).

-> Get Integer 

getNatural Source #

Arguments

:: Int

Maximum number of bytes to consume. If the Natural number can be determined before consuming this number of bytes, it will be. If 0, parsing fails.

Each SLEB128 byte encodes at most 7 bits of data. That is, \(length(encoded) == \lceil\frac{length(data)}{7}\rceil\).

-> Get Natural 

Extras

Scientific

putScientific :: Scientific -> Put Source #

Compact Scientific encoding. Internally, it uses both ULEB128 and SLEB128. 0 is encoded as \x00, other numbers take at least two bytes.

Compatible decoders are getFixed and getScientific.

getScientific Source #

Arguments

:: Int

Maximum number of ULEB128 bytes to consume for the coefficient part. See getNatural.

-> Get Scientific 

Decode a Scientific encoded with putScientific or putFixed.

Rational

putRational :: Rational -> Put Source #

Compact Rational encoding. Internally, it uses both ULEB128 and SLEB128. Decode with getRational. 0 is encoded as \x00, other numbers take at least four bytes.

getRational Source #

Arguments

:: Int

Maximum number of bytes to consume for each of the numerator and denominator parts. See getNatural.

-> Get Rational 

Decode a Rational encoded with putRational.

Fixed

putFixed :: HasResolution r => Fixed r -> Put Source #

Same encoding as putScientific.

Compatible decoders are getFixed and getScientific.

getFixed Source #

Arguments

:: HasResolution r 
=> Int

Maximum number of ULEB128 bytes to consume for the coefficient part. See getNatural.

-> Get (Fixed r) 

Decode a Fixed encoded with putFixed or putScientific.