Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
refactor decompressValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
keisku committed Oct 25, 2021
1 parent 55ef5ac commit 3fe165b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions decompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,21 @@ func (d *Decompressor) dodTimestampBitN() (n uint, err error) {
}

func (d *Decompressor) decompressValue() (float64, error) {
bit, err := d.br.readBit()
if err != nil {
return 0, fmt.Errorf("failed to read value: %w", err)
}
if bit {
var read byte
for i := 0; i < 2; i++ {
bit, err := d.br.readBit()
if err != nil {
return 0, fmt.Errorf("failed to read value: %w", err)
}
if bit {
// New leading and trailing zeros
read <<= 1
read++
} else {
break
}
}
if read == 0x1 || read == 0x3 { // read byte is '1' or '11'
if read == 0x3 { // read byte is '11'
leadingZeros, err := d.br.readBits(5)
if err != nil {
return 0, fmt.Errorf("failed to read value: %w", err)
Expand All @@ -188,17 +192,16 @@ func (d *Decompressor) decompressValue() (float64, error) {
if significantBits == 0 {
significantBits = 64
}

d.leadingZeros = uint8(leadingZeros)
d.trailingZeros = 64 - uint8(significantBits) - d.leadingZeros
}
// read byte is '11' or '1'
valueBits, err := d.br.readBits(int(64 - d.leadingZeros - d.trailingZeros))
if err != nil {
return 0, fmt.Errorf("failed to read value: %w", err)
}
valueBits <<= uint64(d.trailingZeros)
d.value ^= valueBits
}

return math.Float64frombits(d.value), nil
}

0 comments on commit 3fe165b

Please sign in to comment.