1.8 Advanced Topics
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Google's Protocol Buffers Library
        • Google's Protocol Buffers
          • Advanced Topics
            • Precompiled Messages
            • Supplying Your Own Host Type Message Sequences

1.8.1 Precompiled Messages

Performance can be significantly improved using a strategy of precompiling the constant portions of your message. Enumerations for example, are excellent candidates for precompilation. Using protobuf_message/3, the precompiled portion of the message is inserted directly in the wire-stream on encode, and is unified with, and removed from the wire-stream on decode. The following shows how the "send_command" example above, can be converted to precompiled form:


:- dynamic precompiled_message/3.

send_precompiled_command(Command, Vector, Msg) :-
        basic_vector(Vector, Proto1),

        precompiled_message(commands(Command), Msg, Tail),

        protobuf_message(protobuf([embedded(3, Proto1)]), Tail).

precompile_commands :-
        abolish(precompiled_message/3),
        forall(protobufs:commands(Key, _),
              ( Proto = protobuf([atom(1, command),
                                  enum(2, commands(Key))]),
                protobuf_message(Proto, Msg, Tail),
                assert(precompiled_message(commands(Key), Msg, Tail))
              )),
        compile_predicates([precompiled_message/3]).

*
*
*
:- initialization
     precompile_commands.