title: How to represent binary byte array data in C++?
body: <p>I am trying to retrieve data from Cassandra using <code>libCQL library in C++</code>.... The table that I have created in Cassandra is like this - </p>
  
  <pre><code>create table test_cql (user_id text, column_name text, column_value blob, primary key (id, column_name));
  </code></pre>
  
  <p>And below is the data that is there in the above table - </p>
  
  <pre><code>cqlsh:testks&gt; select column_name, column_value from test_cql where user_id = '1';
  
   column_name              | column_value
  --------------------------+--------------------------------------------------------------------------------------------
   @hello.1381780131229.dc1 | 0x7fff0000012c4ebb95550000001e42797465204172726179205465737420466f722042696720456e6469616e
  </code></pre>
  
  <p>Here column_value is the actual blob value which is what I am trying to retrieve...</p>
  
  <p>Now below is the C++ code I have which will try to retrieve the data from Cassandra for <code>user_id = 1</code> in which I am trying to print out column_name and column_value details.</p>
  
  <pre><code>    bool flag = false;
      std::map&lt;std::string, std::string&gt; m;
      std::string key, value;
  
      string query = "select column_name, column_value from test_cql where user_id ='1';";
      std::cout &lt;&lt; query &lt;&lt; endl;
  
  // the below line will execute the query
      cql_result_t&amp; result = execute_query(query);
  
  // this will print out the result after executing the above query
  
      while (result.next()) {
          for (size_t i = 0; i &lt; result.column_count(); ++i) {
              cql::cql_byte_t* data = NULL;
              cql::cql_int_t size = 0;
              result.get_data(i, &amp;data, size);
  
              if (!flag) {
                  key = reinterpret_cast&lt;char*&gt;(data);
                  flag = true;
              } else if (flag) {
                  value = reinterpret_cast&lt;char*&gt;(data);
                  m[key] = value;
                  flag = false;
              }
          }
  
          cout&lt;&lt;key &lt;&lt; "-" &lt;&lt; value &lt;&lt;endl;
  
      }
  </code></pre>
  
  <p>The above code only prints out key as <code>@hello.1381780131229.dc1</code> but not the value somehow.. It should be printing out value as <code>0x7fff0000012c4ebb95550000001e42797465204172726179205465737420466f722042696720456e6469616e</code> since the value is the byte array (binary blob) in Cassandra table which is column_value. </p>
  
  <p>And I have declared key and value both as string which might be the problem I guess in my above code.. But I believe value is actual blob in Cassandra table (column_value).. So I am not sure how to retrieve the binary blob (byte array) using the above C++ code? </p>
  
  <p><strong>And also this binary byte array blob value can be of any variable length and it is always stored in BIG-ENDIAN byte order format.</strong></p>
  
  <p>Coming from Java background, I am having little bit problem... Any help will be appreciated on this... As I guess, its totally C++ question like which datatype I should use to represent binary byte array..</p>