Skip to content

Proto3 Nested Message Getter is not useful #54

Closed
@mwitkow

Description

@mwitkow

Take this generated code:

type FlagId struct {
    Deployment *DeploymentId `protobuf:"bytes,1,opt,name=deployment" json:"deployment,omitempty"`
    Name       string        `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
}

func (m *FlagId) Reset()         { *m = FlagId{} }
func (m *FlagId) String() string { return proto.CompactTextString(m) }
func (*FlagId) ProtoMessage()    {}

func (m *FlagId) GetDeployment() *DeploymentId {
    if m != nil {
        return m.Deployment
    }
    return nil
}

What is the purpose of this Getter? It will not be called on a nil m *FlagId.
I actually hoped it would create an new instance of the type behind the Deployment field, but it seems to not do anything other than a normal m.Deployment would.

I really hoped it would create a new instance if it was nil, this way I could solve the problem in without reflection:
grpc-ecosystem/grpc-gateway#32

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