Skip to content

Comments

Kostiantyn Shchepanovskyi edited this page Nov 22, 2015 · 5 revisions

Parser supports C/C++-style // comments syntax.

// Header.
// Proto file comments(first header block) is attached to `Proto`.
syntax = "proto3";

// Message comments.
message Request {
  // This comment is attached to `foo`
  string foo = 1; 
  int32 bar = 2; // This comment is attached to `bar`
  // These two lines
  // are attached to `baz`
  int32 baz = 3;  
}

All comments attached to element are accessible using comments property (list of strings). Parser automatically removes leading spaces from all comments if all lines has common number of spaces.

Comments can be attached to following objects:

  • proto
  • message
  • message field
  • oneof
  • enum
  • enum constant
  • service
  • service method

Comments attached to Proto instance should be first consecutive block of the comments in the file (empty line breaks comment block). Only one block is attached to Proto.

Note about /* */ comments: this style of comments is supported by parser but these comments are not accessible in generator.

Clone this wiki locally