Skip to content

A parser for Google proto source files to protopuf C++ headers

License

Notifications You must be signed in to change notification settings

ArchNemSyS/proto-to-protopuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proto-to-protopuf

A simple parser for Google proto source files to protopuf C++ headers

  • default usage is to convert all proto sources in one directory into protopuf headers

Build

git clone https://github.com/ArchNemSyS/proto-to-protopuf.git
cd proto-to-protopuf
cmake .
make

Run

  • copy proto_parser executable and .proto files to an empty directory
  • run ./proto_parser
  • with any luck the parsed c++ protopuf headers will be in the protopuf subdirectory

Limitations

  • only supports proto version 2 files and common field types - (should be relatively easy to overload)
  • supports includes but cannot resolve enums and messages with the same name
  • doesnt resolve symbol dependancy order - ie forward declares / reordering of declarations
  • ignores namespace/package attributes
  • tokenizer is confused by comment looking string literals aka - file paths // and /*
  • doesn't generate make files or wrapper classes etc

Supported tags

message fields

proto protopuf
int32 int32_field
unit32 uint32_field
int64 int64_field
uint64 uint64_field
float float_field
double double_field
string string_field
bool bool_field
enum enum_field
message message_field

comments

  • /* multiline */
  • // singleline

import

import "filename.proto";

--convert--

include "filename.proto.h"

enum

enum TYPE {
    FIELD_NAME = INT;
    FIELD_NAME = INT;
}

--convert--

enum TYPE {
   FIELD_NAME = INT,
   FIELD_NAME = INT,
}

message

message Student {
    uint32 id = 1;
    string name = 3;
}

message Class {
    string name = 8;
    repeated Student students = 3;
}

--convert--

using Student = message<
    uint32_field<"id", 1>, 
    string_field<"name", 3>
>;

using Class = message<
    string_field<"name", 8>, 
    message_field<"students", 3, Student, repeated>
>;

About

A parser for Google proto source files to protopuf C++ headers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published