Skip to content

proto3 no-longer generates pointers to fields #15

Closed
@ralfthewise

Description

@ralfthewise

In proto2 fields were generated as pointers, which allowed us to check if a field was specified or not. This no longer seems to be the case. For example:

proto2:

syntax = "proto2";

message Foo {
  required int32 ID = 1;
  optional int32 SortOrder = 2;
}

gives

type Foo struct {
    ID               *int32 `protobuf:"varint,1,req" json:"ID,omitempty"`
    SortOrder        *int32 `protobuf:"varint,2,opt" json:"SortOrder,omitempty"`
    XXX_unrecognized []byte `json:"-"`
}

proto3:

syntax = "proto3";

message Foo {
  int32 ID = 1;
  optional int32 SortOrder = 2;
}

gives

type Foo struct {
    ID        int32 `protobuf:"varint,1,opt" json:"ID,omitempty"`
    SortOrder int32 `protobuf:"varint,2,opt" json:"SortOrder,omitempty"`
}

Is this the expected behavior, and if so how are we supposed to differentiate a client making a call with SortOrder = 0 vs one making a call and not specifying the SortOrder?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions