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

Proto3 repeated field not packed by default #345

Closed
kitak opened this issue Feb 1, 2020 · 1 comment · Fixed by #635
Closed

Proto3 repeated field not packed by default #345

kitak opened this issue Feb 1, 2020 · 1 comment · Fixed by #635
Assignees
Labels

Comments

@kitak
Copy link

kitak commented Feb 1, 2020

Message definitions

proto3_test.proto:

syntax = "proto3";

package test;

message Test3Int32RepDefault {
    repeated int32 repeated_int32 = 1;
}

message Test3Int32RepPackedTrue {
    repeated int32 repeated_int32 = 1 [packed = true];
}

Compiled via:

$ protoc --version
libprotoc 3.6.1
$ protoc --dart_out=grpc:. ./proto3_test.proto

Serialization Code and results

import './proto3_test.pb.dart';
import 'dart:io';

Future<void> main() async {
  final repDefault = Test3Int32RepDefault()
    ..repeatedInt32.addAll([2,3,5]);
  final file = File("./rep_default");
  file.writeAsBytes(repDefault.writeToBuffer());

  final packedTrue = Test3Int32RepPackedTrue()
    ..repeatedInt32.addAll([2,3,5]);
  final file2 = File("./packed_true");
  file2.writeAsBytes(packedTrue.writeToBuffer());
}
$ hexdump rep_default
0000000 08 02 08 03 08 05
0000006
$ hexdump packed_true
0000000 0a 03 02 03 05
0000005

The repeated field with default packed setting compiles to a non-packed field although it should be packed by default.

@shekohex
Copy link

I hit this bug today between my server (in Rust) which correctly packs the values by default as per protobuf3 spec, and dart does not do that by default!

I ended up explicitly adding [packed = true] to the fields as a workaround for now!

@osa1 osa1 self-assigned this Apr 13, 2022
osa1 added a commit to osa1/protobuf.dart that referenced this issue Apr 27, 2022
@osa1 osa1 added the bug label May 11, 2022
@osa1 osa1 closed this as completed in #635 May 17, 2022
osa1 added a commit that referenced this issue May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants