var_test.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "libbinom/include/binom.h"
  2. using namespace binom;
  3. void var_test() {
  4. std::clog << "\n\nvar_test()\n\n\n";
  5. OutputManip::buffer_array = OutputManip::BufferArray::PRIMITIVE;
  6. OutputManip::primitive = OutputManip::Primitive::UNSIGNED;
  7. Variable var = vobj{
  8. {"a", 1_ui8},
  9. {"b", 2_ui16},
  10. {"c", 4_ui32},
  11. {"d", 8_ui64},
  12. {"e", ui8arr{1,2,3}},
  13. {"f", ui16arr{4,5,6}},
  14. {"g", ui32arr{7,8,9}},
  15. {"h", ui64arr{10,11,12}},
  16. {"j", varr{1,2,3}},
  17. {"k", vobj{
  18. {"a", 1_ui8},
  19. {"b", 2_ui16},
  20. {"c", 4_ui32},
  21. {"d", 8_ui64},
  22. {"e", ui8arr{1,2,3}},
  23. {"f", ui16arr{4,5,6}},
  24. {"g", ui32arr{7,8,9}},
  25. {"h", ui64arr{10,11,12}},
  26. {"j", varr{1,2,3}}
  27. }}
  28. };
  29. ByteArray ser = var.serialize();
  30. FileIO file("test.binom");
  31. file.write(0, ser);
  32. Variable var_deser = Variable::deserialize(ser);
  33. std::clog << "Constructed:\n" << var << "\n\n"
  34. "Serialized: " << BufferArray(ser) << "\n\n"
  35. "Deserialized:\n" << var_deser << "\n\n";
  36. NodeVisitor visitor = &var_deser;
  37. visitor["h"](1).getValue().asUi64();
  38. }