text: #include <assert.h>
  #include <string.h>
  #include "binson_writer.h"
  
  /*
  {
    "A": "B", 
    "B": 1, 
    "C": 3.0, 
    "D": false, 
    "E": "0x0102", 
    "F": {
    }, 
    "G": [
      false,
      "A",
      "0x0102",
      {
      },
      "",
      "?",
      "EEEEE",
      false,
      false,
      false,
      {
        "E": "E"
      },
      "B",
      "B",
      1,
      "C",
      "FEEEEEEEEEEEEEEEEEE",
      false,
      false,
      false,
      false,
      false,
      false,
      {
        "E": "E"
      },
      "B",
      "B",
      1,
      "C",
      2.1747253248E10,
      1,
      "C",
      9.665790144E9
    ], 
    "?": [
      
    ]
  }
  */
  int main(void)
  {
      uint8_t expected[223] = "\x40\x14\x01\x41\x14\x01\x42\x14\x01\x42\x10\x01\x14\x01\x43\x46\x00\x00\x00\x00\x00\x00\x08\x40\x14\x01\x44\x45\x14\x01\x45\x18\x02\x01\x02\x14\x01\x46\x40\x41\x14\x01\x47\x42\x45\x14\x01\x41\x18\x02\x01\x02\x40\x41\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x16\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x13\xef\xbf\xbd\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x45\x45\x45\x45\x45\x45\x45\x45\x40\x14\x01\x45\x14\x01\x45\x41\x14\x01\x42\x14\x01\x42\x10\x01\x14\x01\x43\x14\x14\x14\x46\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x40\x14\x01\x45\x14\x01\x45\x41\x14\x01\x42\x14\x01\x42\x10\x01\x14\x01\x43\x46\x00\x00\x00\x00\xf3\x40\x14\x42\x10\x01\x14\x01\x43\x46\x00\x00\x00\x06\x02\x01\x02\x42\x43\x14\x03\xef\xbf\xbd\x42\x43\x41";
      uint8_t created[223];
      binson_writer w;
      binson_writer_init(&w, created, sizeof(created));
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x41", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_integer(&w, 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x43", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_double(&w, 3.0);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x44", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x45", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_bytes(&w, (uint8_t *)"\x01\x02", 2);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x46", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x47", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_array_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x41", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_bytes(&w, (uint8_t *)"\x01\x02", 2);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14", 20);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x13\xef\xbf\xbd\x14\x14\x14\x14\x14\x14", 22);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x45\x45\x45\x45\x45", 20);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x45", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x45", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_integer(&w, 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x43", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x14\x46\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45\x45", 20);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_boolean(&w, false);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\x45", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x45", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x42", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_integer(&w, 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x43", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_double(&w, 2.1747253248E10);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_integer(&w, 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_string_with_len(&w, "\x43", 1);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_double(&w, 9.665790144E9);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_array_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_name_with_len(&w, "\xef\xbf\xbd", 3);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_array_begin(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_array_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      binson_write_object_end(&w);
      assert(w.error_flags == BINSON_ID_OK);
      assert(memcmp(expected, created, sizeof(expected)) == 0);
      return 0;
  }
  
  