How to control the order of field while converting a protobuf message to string using TextFormat in java?

11 views
Skip to first unread message

tuk

unread,
Mar 22, 2020, 10:10:36 AM3/22/20
to Protocol Buffers
Cross-posting from stackoverflow

 have a protobuf message which when converted to string using TextFormat.printToString()

deploymentDef {
  id: "PX3C1ED"
  default: true
  type: ONPREM
  limits {
    clusterSize: 3
    limits {
      numVMs: 18000
      numVMsWithFlows: 18000
      activeFlows: 6000000
      totalFlows: 24000000
      flowPlanning: 4000000
      numDevices: 40
    }
  }
  isEnterprise: false
  brickSize: XLARGE
  clusterSize: 3
  description: "Default Role, Non-Enterprise, App-Discovery and Vf services stopped"
}

The proto definition looks like below

message DeploymentDef {
    optional string id = 1;
    optional bool default = 2;
    optional DeploymentType type = 3;
    optional PlatformClusterLimits limits = 4;
    repeated Role roles = 5;
    optional bool isEnterprise = 6;
    optional Configs overrides = 7;
    optional BrickSize brickSize = 8;
    optional int32 clusterSize = 9;
    optional string description = 10;
}

Is it possible to display description as the first field while converting the proto message to string using TextFormat.printToString() ? 



Marc Gravell

unread,
Mar 22, 2020, 1:13:38 PM3/22/20
to tuk, Protocol Buffers
I would imagine that most implementations are still going to use field number order. Is there a specific reason you need to control it? Most JSON tools won't care, and if you want to control the JSON, frankly you shouldn't be using an opinionated serializer like protobuf - you should be using a suitable highly configurable JSON-dedicated serializer for your platform.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/a3e94ffc-3723-4b70-b647-15452f4f5731%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages