Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 669 #693

Merged
merged 11 commits into from
Apr 22, 2024
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);
});
});
}
Loading