Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138683

Protobuf: repeated enum fields are serialized incorrectly

XMLWordPrintable

    • Windows
    • c764a9b22 (dev), 9370589e0 (6.10), cc3a18811 (6.9), e354582c0 (tqtc/lts-6.8)
    • Foundation PM Staging

      proto messages with repeated fields of enum-types are not serialized correctly.

      We had to replace all such occurrences with repeated int32 fields in order to to get correct binary data.

      Example proto-file repeatedenums.proto:

      package qtbugs;

      enum TestEnum {
          One = 1;
          Two = 2;
          Three = 3;
      }

      message TestMessage {
          repeated TestEnum state = 1;
      }

      Example program:

       

      The following sample program will write the binary data to a file:

          QProtobufSerializer serializer;
          qtbugs::TestMessage message;
          message.state().append(qtbugs::TestEnumGadget::One);
          message.state().append(qtbugs::TestEnumGadget::Two);
          message.state().append(qtbugs::TestEnumGadget::Three);
          QByteArray rawData = message.serialize(&serializer);
          qInfo() << rawData;
          QFile file{"testmessage.protobuf"};
          file.open(QIODevice::WriteOnly);
          file.write(rawData);

      Expected output as obtained via "protoc --decode_raw < testmessage.protobuf":

      1: 1
      1: 2
      1: 3

      Actual output as obtained via "protoc --decode_raw < testmessage.protobuf":

      1: "\000\001\002"

       

        For Gerrit Dashboard: QTBUG-138683
        # Subject Branch Project Status CR V

            tatiana.borisova Tatiana Borisova
            mcnepp Gernot Neppert
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes