Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate an Erlang module from a CSV of message/code mappings. #63

Merged
merged 3 commits into from
Dec 18, 2013

Conversation

seancribbs
Copy link

This replaces the manual maintenance of the mappings in riak_pb_codec and opens the door for generating the appropriate code for the same information in other languages.

This also updates the encoding_test to cover the entire message code space, since we now have gaps in it.

NOTE: I hacked the preprocess callback in the plugin to do the generation, instead of more appropriately calling it at the beginning of the compile phase. This deserves more investigation, as I'm probably doing it wrong.

This replaces the manual maintenance of the mappings in riak_pb_codec
and opens the door for generating the appropriate code for the same
information in other languages.

This also updates the encoding_test to cover the entire message code
space, since we now have gaps in it.

NOTE: I hacked the 'preprocess' callback in the plugin to do the
generation, instead of more appropriately calling it at the beginning
of the compile phase. This deserves more investigation, as I'm
probably doing it wrong.
|| Line <- Lines].

generate_module(Name, Tuples) ->
%% TODO: Add generated doc comment at the top

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, willfix

@bookshelfdave
Copy link

+1, nice work as always @seancribbs

might cause a deps issue after merging as riak_api seems to be pinned at 2.0.0.11

@bookshelfdave
Copy link

also, all tests pass.

Not riak_tested.

==> riak_pb (eunit)
Compiled test/bucket_props_codec_eqc.erl
Compiled src/riak_pb_search_codec.erl
Compiled src/riak_pb_messages.erl
Compiled test/encoding_test.erl
Compiled src/riak_pb_kv_codec.erl
Compiled src/riak_pb_dt_codec.erl
Compiled src/riak_pb_codec.erl
======================== EUnit ========================
module 'bucket_props_codec_eqc'
module 'encoding_test'
  encoding_test:8: pb_test_ (content encode decode)...[0.007 s] ok
  encoding_test:34: pb_test_ (deleted header encode decode)...ok
  encoding_test:52: pb_test_ (indexes encode decode)...ok
  encoding_test:65: pb_test_ (empty content encode decode)...ok
  encoding_test:76: pb_test_ (empty repeated metas are removed/ignored)...ok
  encoding_test:87: pb_test_ (msg code encode decode)...ok
  [done in 0.025 s]
module 'riak_pb_codec'
module 'riak_pb_dt_codec'
module 'riak_pb_kv_codec'
module 'riak_pb_messages'
module 'riak_pb_search_codec'
=======================================================
  All 6 tests passed.

@bookshelfdave
Copy link

one more thing, just giving a heads up for https://github.com/basho/riak_repl_pb_api, I think it should be fine.

@seancribbs
Copy link
Author

@metadave One more look, please? I added some doc comments for the generated module.

@bookshelfdave
Copy link

Confirmed that this comment appeared at the top of riak_pb_messages.erl:

%% @doc This module contains message code mappings generated from
%% src/riak_pb_messages.csv. DO NOT EDIT OR COMMIT THIS FILE!

And test results look good:

R15B01:[feature/sdc/msgcodegen]prime:~/basho/riak_ee/deps/riak_pb$ ./rebar eunit skip_deps=true
==> riak_pb (eunit)
Compiled src/riak_pb_search_codec.erl
Compiled src/riak_pb_messages.erl
Compiled test/encoding_test.erl
Compiled src/riak_pb_kv_codec.erl
Compiled src/riak_pb_dt_codec.erl
Compiled src/riak_pb_codec.erl
Compiled test/bucket_props_codec_eqc.erl
======================== EUnit ========================
module 'bucket_props_codec_eqc'
  bucket_props_codec_eqc:36: bucket_codec_test_ (bucket properties encode decode)...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 2000 tests
[3.539 s] ok
  [done in 3.541 s]
module 'encoding_test'
  encoding_test:8: pb_test_ (content encode decode)...[0.005 s] ok
  encoding_test:34: pb_test_ (deleted header encode decode)...ok
  encoding_test:52: pb_test_ (indexes encode decode)...ok
  encoding_test:65: pb_test_ (empty content encode decode)...ok
  encoding_test:76: pb_test_ (empty repeated metas are removed/ignored)...ok
  encoding_test:87: pb_test_ (msg code encode decode)...[0.001 s] ok
  [done in 0.023 s]
module 'riak_pb_codec'
module 'riak_pb_dt_codec'
module 'riak_pb_kv_codec'
module 'riak_pb_messages'
module 'riak_pb_search_codec'
=======================================================
  All 7 tests passed.

=INFO REPORT==== 18-Dec-2013::13:28:37 ===
    application: inets
    exited: killed
    type: temporary

@bookshelfdave
Copy link

👍

@seancribbs
Copy link
Author

Thanks @metadave!

seancribbs added a commit that referenced this pull request Dec 18, 2013
Generate an Erlang module from a CSV of message/code mappings.
@seancribbs seancribbs merged commit d419cd7 into develop Dec 18, 2013
@seancribbs seancribbs deleted the feature/sdc/msgcodegen branch December 18, 2013 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants