Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1213

Membuffer should provide a way to get back the buffer

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.7
    • None
    • None
    • Patch Available

    Description

      I wanted to get the binary representation of a serialized thrift object and had to do something like

      thrift_something_to_binary (SomeThing) ->
        {ok, TF} = thrift_memory_buffer:new_transport_factory(),
        {ok, PF} = thrift_binary_protocol:new_protocol_factory(TF,[]),
        {ok, P0} = PF(),
        {{ protocol, thrift_binary_protocol,{ binary_protocol,{transport, thrift_memory_buffer, {memory_buffer,B} },true,true}},ok} 
          = thrift_protocol:write (P0,{{list, some_types:struct_info('some')}, SomeThing }),
        iolist_to_binary(B).
      

      With the attached patch instead the flush call of the transport will return the buffer so the large brittle pattern match above can be accomplished instead with

      thrift_something_to_binary (SomeThing) ->
        {ok, TF} = thrift_memory_buffer:new_transport_factory(),
        {ok, PF} = thrift_binary_protocol:new_protocol_factory(TF,[]),
        {ok, P0} = PF(),
        {P1, ok} = thrift_protocol:write (P0,{{list, some_types:struct_info('some')}, SomeThing }),
        {_P2, B} = thrift_protocol:flush_transport (P1),
        iolist_to_binary(B).
      

      Attachments

        1. THRIFT-1213
          7 kB
          Anthony Molinaro

        Activity

          People

            djnym Anthony Molinaro
            djnym Anthony Molinaro
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: