Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-1469

binary packing issue

    • Type: Icon: Task Task
    • Resolution: Done
    • WT2.5.3
    • Affects Version/s: None
    • Component/s: None
    • None

      I found binary packing issue that cannot get last binay length.
      in folloing code:

      ~~~

      include <stdio.h>

      include <stdlib.h>

      include <string.h>

      include <assert.h>

      include <wiredtiger.h>

      int main(void)
      {
      WT_CONNECTION *conn;
      WT_SESSION *session;
      int i, rc;
      unsigned char buf[32];
      WT_ITEM items[] = {

      {"a", 2}

      ,

      {"bb", 3}

      ,

      {"ccc", 4}

      ,
      };
      WT_ITEM a, b, c;

      memset(buf, 0xff, sizeof(buf));

      rc = wiredtiger_open("data", NULL, "create", &conn);
      assert(rc == 0);
      rc = conn->open_session(conn, NULL, NULL, &session);
      assert(rc == 0);

      rc = wiredtiger_struct_pack(session, buf, sizeof(buf),
      "uuu", &items[0], &items[1], &items[2]);
      assert(rc == 0);

      printf("Packed: ");
      for(i=0;i<sizeof(buf);i++)

      { printf("%02x", buf[i]); }

      printf("\n");

      rc = wiredtiger_struct_unpack(session, buf, sizeof(buf),
      "uuu", &a, &b, &c);
      assert(rc == 0);
      printf("a: size=%ld, data=%s\n", a.size, a.data);
      printf("b: size=%ld: data=%s\n", b.size, b.data);
      printf("c: size=%ld, data=%s\n", c.size, c.data);

      rc = conn->close(conn, NULL);
      assert(rc == 0);
      return 0;
      }
      ~~~

      We can not third binary length.
      unpack result:
      ~~~
      Packed: 8261008362620063636300ffffffffffffffffffffffffffffffffffffffffff
      a: size=2, data=a
      b: size=3: data=bb
      c: size=25, data=ccc
      ~~~

      Actually what I want to do is packing variable length array.
      I will ask next question, if this issue become clear.

      Thank you.

            Assignee:
            donald.anderson@mongodb.com Donald Anderson
            Reporter:
            hamano HAMANO Tsukasa
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: