title: Packing ext type in C++ with Msgpack
body: <p>I am looking for a sample how to pack ext types with msgpack in C++ as I am not sure about how to do this.</p>
  
  <p>The only information I found is located in this section <a href="https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_packer#pack-manually" rel="nofollow noreferrer">https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_packer#pack-manually</a>.</p>
  
  <p>Assumed I want to pack an object of type Foo as a msgpack ext type with an adaptor class template. How to use <code>pack_ext</code> and <code>pack_ext_body</code>? Do I have to create a "sub packer" within the template, pack my Foo data manually and then pass size of the binary data and the data itself to <code>pack_ext</code>and <code>pack_ext_body</code>? It would be create if some C++ expert could give me a minimal example.</p>
  
  <pre><code>MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
      namespace adaptor {
          template&lt;&gt;
          struct pack&lt;Foo&gt; {
              template &lt;typename Stream&gt;
              packer&lt;Stream&gt;&amp; operator()(msgpack::packer&lt;Stream&gt;&amp; o, Foo const&amp; v) const {
                  // how to use ?
                  o.pack_ext(size_t l, int8_t type);
                  o.pack_ext_body(const char* b, size_t l);
              }
         }
   }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in advance!</p>