Skip to content

Commit

Permalink
Improved compression support
Browse files Browse the repository at this point in the history
  • Loading branch information
Achilleas Anagnostopoulos committed Dec 20, 2014
1 parent f58d800 commit bf2a6e9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.pub/
build/
packages/
~packages/

# Or the files created by dart2js.
*.dart.js
Expand Down
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ If the Cassandra cluster requires authentication but none is supplied or an inco

In order to keep external dependencies to a minimum, the driver does not ship with native implementations for the two compression schemes currently supported by Cassandra (lz4 and snappy).

The driver however allows provides a mechanism for registering a [Codec\<Uint8List, Uint8List>](https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:convert.Codec) that implements one of the above compression schemes. This allows you to use a third-party dart package for handling compression if your particular application requires it.
The driver however allows provides a mechanism for registering a [Codec\<Uint8List, Uint8List>](https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:convert.Codec) that implements one of the above compression schemes. This allows you to use a third-party dart package (e.g [dart_lz4](https://github.com/achilleasa/dart_lz4) native extension) for handling compression if your particular application requires it.

To use this feature you need to invoke the public method ```registerCodec(String, Codec<Object, Uint8List>)``` and specify one of the [Compression](https://github.com/achilleasa/dart_cassandra_cql/blob/master/lib/src/types/enums/compression.dart) enum **values** (e.g. ```Compression.LZ4.value```) as the first argument and a class instance implementing ```Codec<Uint8, Uint8>``` as the second argument.

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.3 (December 20, 2014)

Improved support for compression codecs
Driver is now compatible with [dart_lz4](https://github.com/achilleasa/dart_lz4)

## 0.1.2 (December 6, 2014)

Renamed lib/driver to lib/src so that docgen works
Expand Down
7 changes: 3 additions & 4 deletions lib/src/protocol/frame/frame_decompressor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class FrameDecompressor {
}

// Decompress and replace body data. According to the spec, if the compression algorithm is LZ4
// then we need to skip the first 4 bytes which signify the uncompressed length
Uint8List bodyData = _compression == Compression.LZ4
? new Uint8List.view(frame.body.buffer, 4, frame.body.lengthInBytes - 4)
: new Uint8List.view(frame.body.buffer, 0, frame.body.lengthInBytes);
// then the first four bytes of the payload should include its decompressed length so compliant
// LZ4 codecs should expect this.
Uint8List bodyData = new Uint8List.view(frame.body.buffer, 0, frame.body.lengthInBytes);

// Generate uncompressed frame
bodyData = compressionCodec.decode(bodyData);
Expand Down
5 changes: 0 additions & 5 deletions lib/src/protocol/frame/frame_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ class FrameWriter {
}

// Replace writer blocks with compressed output and enable the compression flag for the header
// According to the protocol spec, when using LZ4 we need to prepend a 4-byte int with the
// uncompressed data length before the payload
_header.flags |= HeaderFlag.COMPRESSION.value;
_typeEncoder.writer.clear();
if (compression == Compression.LZ4) {
_typeEncoder.writeUInt32(uncompressedLen);
}
_typeEncoder.writer.addLast(compressedData);
}

Expand Down

0 comments on commit bf2a6e9

Please sign in to comment.