Skip to content

Why has methods are not generated using protoc 3.17.* if in protobuf repo they say it should? #1336

Closed
@frederikhors

Description

@frederikhors

Reading here: https://github.com/protocolbuffers/protobuf/blob/master/docs/field_presence.md#go-example the Golang example:

m := GetProto()
if (m.HasFoo()) {
  // Clear the field:
  m.Foo = nil
} else {
  // Field is not present, so set it.
  m.Foo = proto.Int32(1);
}

if I use:

protoc pkg/user.proto --go_out=. --go_opt=module=my_app --go-grpc_out=. --go-grpc_opt=module=my_app

with:

syntax = "proto3";

package example;

message MyPlayer {
  uint64 id = 1;
  optional string description = 2;
  uint32 qty = 3;
  optional uint64 age = 4;
}

it doesn't generate any has<T>() method.

Why?

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.26.0
// 	protoc        v3.17.3

Am I wrong if I use MyPlayer generated proto fields instead of methods?

Example:

if MyPlayer.description != nil {
  description = *MyPlayer.description
}

instead of

description = MyPlayer.GetDescription()

which is not what I want (I want to detect nil values).

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