Skip to content

Commit

Permalink
Improve info display at verbosity 5
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Sep 21, 2024
1 parent 3890a6d commit 54a2a4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions v2/Event.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
EVT_COMPRESSION_END = 6 // Compression ends
EVT_DECOMPRESSION_END = 7 // Decompression ends
EVT_AFTER_HEADER_DECODING = 8 // Compression header decoding ends
EVT_BLOCK_INFO = 9 // Display block information

EVT_HASH_NONE = 0
EVT_HASH_32BITS = 32
Expand Down
41 changes: 23 additions & 18 deletions v2/io/CompressedStream.go
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ func (this *decodingTask) decode(res *decodingTaskResult) {
}

// Read shared bitstream sequentially
blockOffset := this.ibs.Read()
lr := uint(this.ibs.ReadBits(5)) + 3
read := this.ibs.ReadBits(lr)

Expand All @@ -1621,8 +1622,7 @@ func (this *decodingTask) decode(res *decodingTaskResult) {
}

if len(data) < maxL {
extraBuf := make([]byte, maxL-len(data))
data = append(data, extraBuf...)
data = make([]byte, maxL)
this.iBuffer.Buf = data
}

Expand Down Expand Up @@ -1682,7 +1682,7 @@ func (this *decodingTask) decode(res *decodingTaskResult) {
mask := uint64(1<<length) - 1
preTransformLength := uint(ibs.ReadBits(length) & mask)

if preTransformLength == 0 || preTransformLength > _MAX_BITSTREAM_BLOCK_SIZE {
if preTransformLength == 0 || preTransformLength > _MAX_BITSTREAM_BLOCK_SIZE {
// Error => cancel concurrent decoding tasks
errMsg := fmt.Sprintf("Invalid compressed block size: %d", preTransformLength)
res.err = &IOError{msg: errMsg, code: kanzi.ERR_BLOCK_SIZE}
Expand All @@ -1701,18 +1701,25 @@ func (this *decodingTask) decode(res *decodingTaskResult) {
}

if len(this.listeners) > 0 {
// Notify before entropy (block size in bitstream is unknown)
evt := kanzi.NewEvent(kanzi.EVT_BEFORE_ENTROPY, int(this.currentBlockID),
int64(-1), checksum1, hashType, time.Now())
notifyListeners(this.listeners, evt)
}
sf := skipFlags

bufferSize := this.blockLength
if mode&_TRANSFORMS_MASK == 0 {
sf >>= 4
}

msg := fmt.Sprintf("{ \"type\":\"%s\", \"id\": %d, \"offset\":%d, \"skipFlags\":%.8b }",
"BLOCK_INFO", int(this.currentBlockID), blockOffset, sf)
evt1 := kanzi.NewEventFromString(kanzi.EVT_BLOCK_INFO, int(this.currentBlockID), msg, time.Now())
notifyListeners(this.listeners, evt1)

if bufferSize < preTransformLength+_EXTRA_BUFFER_SIZE {
bufferSize = preTransformLength + _EXTRA_BUFFER_SIZE
// Notify before entropy
evt2 := kanzi.NewEvent(kanzi.EVT_BEFORE_ENTROPY, int(this.currentBlockID),
int64(r), checksum1, hashType, time.Now())
notifyListeners(this.listeners, evt2)
}

bufferSize := max(this.blockLength, preTransformLength+_EXTRA_BUFFER_SIZE)

if len(buffer) < int(bufferSize) {
buffer = make([]byte, int(bufferSize))
this.oBuffer.Buf = buffer
Expand Down Expand Up @@ -1742,16 +1749,14 @@ func (this *decodingTask) decode(res *decodingTaskResult) {

if len(this.listeners) > 0 {
// Notify after entropy
evt := kanzi.NewEvent(kanzi.EVT_AFTER_ENTROPY, int(this.currentBlockID),
int64(ibs.Read())/8, checksum1, hashType, time.Now())
notifyListeners(this.listeners, evt)
}
evt1 := kanzi.NewEvent(kanzi.EVT_AFTER_ENTROPY, int(this.currentBlockID),
int64(preTransformLength), checksum1, hashType, time.Now())
notifyListeners(this.listeners, evt1)

if len(this.listeners) > 0 {
// Notify before transform
evt := kanzi.NewEvent(kanzi.EVT_BEFORE_TRANSFORM, int(this.currentBlockID),
evt2 := kanzi.NewEvent(kanzi.EVT_BEFORE_TRANSFORM, int(this.currentBlockID),
int64(preTransformLength), checksum1, hashType, time.Now())
notifyListeners(this.listeners, evt)
notifyListeners(this.listeners, evt2)
}

this.ctx["size"] = preTransformLength
Expand Down

0 comments on commit 54a2a4b

Please sign in to comment.