-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refractor(adaptive):Drop snappy's Read and Writer used in adaptive re…
…ader/writer,replace them with snappy's Decode and Encode;Change interface to report compression info.
- Loading branch information
1 parent
b6bb931
commit daf952c
Showing
7 changed files
with
184 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package adaptive | ||
|
||
type CompressInfo struct { | ||
pkgId int | ||
compressType int | ||
compressTime int64 | ||
tranportTime int64 | ||
decompressTime int64 | ||
compressRatio float64 | ||
} | ||
|
||
type ReportFunction func(CompressInfo) | ||
|
||
type Reporter interface { | ||
Report(CompressInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package compression | ||
|
||
type Compressor interface { | ||
Compress([]byte) []byte | ||
} | ||
|
||
type Decompressor interface { | ||
Decompress([]byte, []byte) []byte | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package snappy | ||
|
||
import ( | ||
"github.com/golang/snappy" | ||
) | ||
|
||
func NewDecompressor() *SnappyDecompressor { | ||
return &SnappyDecompressor{} | ||
} | ||
|
||
type SnappyDecompressor struct { | ||
} | ||
|
||
// this will return a original data. | ||
func (c *SnappyDecompressor) Decompress(dst, src []byte) []byte { | ||
ans, err := snappy.Decode(dst, src) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package snappy | ||
|
||
import ( | ||
"github.com/golang/snappy" | ||
) | ||
|
||
func NewCompressor() *SnappyCompressor { | ||
return &SnappyCompressor{} | ||
} | ||
|
||
type SnappyCompressor struct { | ||
} | ||
|
||
// this will return a snappy format data. | ||
func (c *SnappyCompressor) Compress(src []byte) []byte { | ||
return snappy.Encode(nil, src) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters