Skip to content

How to add UDA's to fields? eg, to customize behavior of vibe serialization #118

@timotheecour

Description

@timotheecour

@msoucy
proto syntax supports annotations via option:
https://developers.google.com/protocol-buffers/docs/proto

import "google/protobuf/descriptor.proto";

extend google.protobuf.FieldOptions {
  optional float my_field_option = 50002;
}

message MyMessage {
  optional int32 foo = 1 [(my_field_option) = 4.5];
}

this could map into a UDA on D side, which I could then use to customize behavior for D code that uses these protos, eg, customizing vibe serialization (via tagging a field as @optional or @ignore, etc)

Is theer a simple way to do this?

looks like extend declarations are allowed but ignored in import/dproto/parse.d

/** Reads an extend declaration (just ignores the content).
@todo */

  •            void readExtend() {
                       readName(); // Ignore this for now
                       unexpected(readChar() == '{', "Expected '{'");
                       while (true) {
                               readDocumentation();
                               if (peekChar() == '}') {
                                       pos++;
                                       break;
                               }
                               //readDeclaration();
                       }
                       return;
               }
    

Is there a simpler way (at least in meantime) to do what I want in my particular case, ie add a @optional or @ignore UDA for a particular field in a generated proto message?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions