Skip to content

Commit

Permalink
Fix issue 669 (#693)
Browse files Browse the repository at this point in the history
* Fix issue 669

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fix dart format issue.
Fix prefer single quote issue.

* Update pubspec and changelog to avoid merge check
publish / validate
validate packages

* Add test for GRPC Compression Flag

* Fix dart analyze issues.

* Fix latest dart analyze issue (uninizialized variable)
  • Loading branch information
RubenGarcia authored Apr 22, 2024
1 parent bb8b6e5 commit bdbe5f5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.5

* Set compressed flag correctly for grpc-encoding = identity. Fixes [#669](https://github.com/grpc/grpc-dart/issues/669) (https://github.com/grpc/grpc-dart/pull/693)

## 3.2.4

* Forward internal `GrpcError` on when throwing while sending a request.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/shared/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ List<int> frame(List<int> rawPayload, [Codec? codec]) {
final payloadLength = compressedPayload.length;
final bytes = Uint8List(payloadLength + 5);
final header = bytes.buffer.asByteData(0, 5);
header.setUint8(0, codec == null ? 0 : 1);
header.setUint8(
0, (codec == null || codec.encodingName == 'identity') ? 0 : 1);
header.setUint32(1, payloadLength);
bytes.setRange(5, bytes.length, compressedPayload);
return bytes;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: grpc
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
version: 3.2.4
version: 3.2.5

repository: https://github.com/grpc/grpc-dart

Expand Down
26 changes: 26 additions & 0 deletions test/grpc_compression_flag_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:grpc/src/shared/codec.dart';
import 'package:grpc/src/shared/message.dart';
import 'package:test/test.dart';

void main() {
group('GRPC Compression Flag', () {
test('compression flag 0 with null codec', () {
final rawPayload = <int>[1, 2, 3, 4];
final Codec? codec = null;
final data = frame(rawPayload, codec);
expect(data[0], 0);
});
test('compression flag 0 with grpc-encoding identity', () {
final rawPayload = <int>[1, 2, 3, 4];
final Codec codec = IdentityCodec();
final data = frame(rawPayload, codec);
expect(data[0], 0);
});
test('compression flag 1 with grpc-encoding gzip', () {
final rawPayload = <int>[1, 2, 3, 4];
final Codec codec = GzipCodec();
final data = frame(rawPayload, codec);
expect(data[0], 1);
});
});
}

0 comments on commit bdbe5f5

Please sign in to comment.