tomas-abrahamsson/gpb — pull request #4 by squidfunk (2013-01-05 23:09:07+00:00)
Title: Support for packages

Hey Tomas,

I have good news: I implemented (full?) support for packages, as I require them in my production environment. I touched the following things:

- added a new option `use_packages`, which is off by default (due to backward compatibility)
- added `gpb_parse:absolutify_names/2` to pass options
- rewrote `gpb_parse:abs_names_2/2` to `gpb_parse:abs_names/4`, in order to hold the parsed top-level packages, as well as any options passed to the function. Furthermore, replaced `lists:map/2` with `lists:mapfoldl/3` in order to resolve absolute names and prepend packages in one turn. The currently active package is located at the head of the packages list passed to `lists:mapfoldl/3`
- added `gpb_parse:prepend_package/2` for convenience
- updated the documentation and added a testcase

This means that files, specifying separate packages are working (using imports, as you already implemented) are now working, as well as nested packages, so subpackages split across separate files are fine. Here is a testcase to try out:

blog.proto

package My.Blog;
message Posting {
required string Text = 1;
}

user.proto

import "blog.proto";
package My.Blog.User;
message Content {
repeated My.Blog.Posting postings = 1;
}

This will also work with my gpb-bindings extension -- I updated it today. Also tried to stick to your coding style, hope you're fine with it.

All the best,
Martin