From 6ec335dbdb11f01a2b8df610c4ea53a85eec0dcd Mon Sep 17 00:00:00 2001 From: Wang Qian <1498953301@qq.com> Date: Tue, 24 Oct 2023 19:20:57 +0800 Subject: [PATCH] fix(adaptive):make CompressInfo's attribuite public. --- adaptive/adaptive.go | 12 ++++++------ adaptive/reader.go | 15 ++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/adaptive/adaptive.go b/adaptive/adaptive.go index 46ee2b6..9b8d754 100644 --- a/adaptive/adaptive.go +++ b/adaptive/adaptive.go @@ -1,12 +1,12 @@ package adaptive type CompressInfo struct { - pkgId int - compressType int - compressTime int64 - tranportTime int64 - decompressTime int64 - compressRatio float64 + PkgId int + CompressType int + CompressTime int64 + TranportTime int64 + DecompressTime int64 + CompressRatio float64 } type ReportFunction func(CompressInfo) diff --git a/adaptive/reader.go b/adaptive/reader.go index 0cd5a13..ab62ace 100644 --- a/adaptive/reader.go +++ b/adaptive/reader.go @@ -28,6 +28,7 @@ func NewReader(r io.Reader, reportFunc ReportFunction) *Reader { inR: r, cmpr: snappy.NewDecompressor(), reportFunc: reportFunc, + pkgID: 0, } } @@ -46,6 +47,8 @@ type Reader struct { start int reportFunc ReportFunction + + pkgID int } func (r *Reader) Read(p []byte) (int, error) { @@ -103,13 +106,15 @@ func (r *Reader) fill() error { r.oBuf = r.cmpr.Decompress(nil, compressedData) endTs := time.Now().UnixNano() compressInfo := CompressInfo{ - compressType: int(compressType), - compressTime: midTs - startTs, - tranportTime: mid2Ts - midTs, - decompressTime: endTs - mid2Ts, - compressRatio: float64(len(r.oBuf)) / float64(dataLen), + PkgId: r.pkgID, + CompressType: int(compressType), + CompressTime: midTs - startTs, + TranportTime: mid2Ts - midTs, + DecompressTime: endTs - mid2Ts, + CompressRatio: float64(len(r.oBuf)) / float64(dataLen), } r.reportFunc(compressInfo) r.start = 0 + r.pkgID += 1 return nil }