4

I tried this but have scope issues.

message DataCollectionMessage {

    message subData
    {
        message SubDataList {
            repeated string data = 1;
        }
        map<string, subData> parameters = 1;
    }
    map<string,SubDataList> parameters =1;
}

Here SubDataList and subData have unresolved references.

tom
  • 21,844
  • 6
  • 43
  • 36
Deepak Garg
  • 47
  • 1
  • 6
  • message SubDataList { repeated string data = 1; } message subData { map parameters = 1; } message DataCollectionMessage { map parameters =1; } – Deepak Garg Aug 24 '17 at 04:20
  • It looks like you've solved your problem, which is great. You can write that comment as an answer and mark it as accepted, or delete your question if you don't think it will be of value to anyone else. – tom Aug 24 '17 at 04:23
  • If your comment above isn't the solution to your problem, please explain what error message your are getting now (because it looks right to me). – tom Aug 24 '17 at 04:25

1 Answers1

0

There is just one minor issue with the protobuf in the question: the innermost map uses subData and the outer map uses SubDataList, but it should be the other way round:

message DataCollectionMessage {
    message SubData {
        message SubDataList {
            repeated string data = 1;
        }
        map<string, SubDataList> parameters = 1;
    }
    map<string, SubData> parameters = 1;
}

(I've also capitalized SubData for consistency.)

The generated Java code will have the following classes (snipped and reordered for clarity):

public static final class DataCollectionMessage {

  public Map<String, DataCollectionMessage.SubData> getParametersMap() { ... }

  public static final class SubData {

    public Map<String, DataCollectionMessage.SubData.SubDataList> getParametersMap() { ... }

    public static final class SubDataList {
      public ProtocolStringList getDataList() { ... }
    }
  }
}

Note that SubDataList has a ProtocolStringList, which is like List<String>.

If you get different results, post the protobuf file that you are using and the relevant parts of the generated Java code.

tom
  • 21,844
  • 6
  • 43
  • 36