joao-r-reis commented on code in PR #1822:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1822#discussion_r1813047807
##########
compressor.go:
##########
@@ -32,6 +32,7 @@ type Compressor interface {
Name() string
Encode(data []byte) ([]byte, error)
Decode(data []byte) ([]byte, error)
+ DecodeSized(data []byte, size uint32) ([]byte, error)
Review Comment:
To truly make it 100% "append-like" (examples:
https://github.com/golang/go/issues/53693):
```
type Compressor interface {
Name() string
// AppendCompressedWithLength compresses src bytes, appends the length
of the compressed bytes to dst and then appends the compressed bytes to dst.
// It returns a new byte slice that is the result of the append
operation.
AppendCompressedWithLength(dst, src []byte) ([]byte, error)
// AppendDecompressedWithLength reads the length of the decompressed
bytes from src, decompresses bytes from src and appends the decompressed bytes
to dst.
// It returns a new byte slice that is the result of the append
operation.
AppendDecompressedWithLength(dst, src []byte) ([]byte, error)
// AppendCompressed compresses src bytes and appends the compressed
bytes to dst.
// It returns a new byte slice that is the result of the append
operation.
AppendCompressed(dst, src []byte) ([]byte, error)
// AppendDecompressed decompresses bytes from src and appends the
decompressed bytes to dst.
// It returns a new byte slice that is the result of the append
operation.
AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte,
error)
}
```
The lz4 library does not support append like semantics so we're going to
have to expand `dst` slice before passing it to the lz4 library functions. If
`cap(dst)` is not large enough then we'll have to allocate a new byte slice and
append it to `dst` instead. `AppendDecompressed` has the `decompressedLength`
parameter so we can check if we can reuse `dst` or if we have to allocate a new
byte slice.
I used the name `Compress` and `Decompress` instead of `Encode` / `Decode`
because it felt more natural to me but I'm fine with keeping `Encode` and
`Decode`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]