From 2b42258ae0ffa8c7f6f33b58ed4f1ff62825d576 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 14 May 2024 07:57:57 +0200 Subject: [PATCH] tty new serialization --- tty.cpp | 34 ++++++++++++++++------------------ tty.h | 7 +++---- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tty.cpp b/tty.cpp index dc710b2..d250e86 100644 --- a/tty.cpp +++ b/tty.cpp @@ -194,37 +194,35 @@ void tty::write_word(const uint16_t addr, uint16_t v) registers[(addr - PDP11TTY_BASE) / 2] = v; } -#if IS_POSIX -json_t *tty::serialize() +JsonDocument tty::serialize() { - json_t *j = json_object(); + JsonDocument j; - json_t *ja_reg = json_array(); + JsonArray ja_reg; for(size_t i=0; i<4; i++) - json_array_append(ja_reg, json_integer(registers[i])); - json_object_set(j, "registers", ja_reg); + ja_reg.add(registers[i]); + j["registers"] = ja_reg; - json_t *ja_buf = json_array(); + JsonArray ja_buf; for(auto & c: chars) - json_array_append(ja_buf, json_integer(c)); - json_object_set(j, "input-buffer", ja_buf); + ja_buf.add(c); + j["input-buffer"] = ja_buf; return j; } tty *tty::deserialize(const json_t *const j, bus *const b, console *const cnsl) { - tty *out = new tty(cnsl, b); + tty *out = new tty(cnsl, b); - json_t *ja_reg = json_object_get(j, "registers"); - for(size_t i=0; i<4; i++) - out->registers[i] = json_integer_value(json_array_get(ja_reg, i)); + JsonArray ja_reg = j["registers"]; + int i_reg = 0; + for(auto v: ja_reg) + out->registers[i_reg++] = v; - json_t *ja_buf = json_object_get(j, "input-buffer"); - size_t buf_size = json_array_size(ja_buf); - for(size_t i=0; ichars.push_back(json_integer_value(json_array_get(ja_buf, i))); + JsonArray ja_buf = j["input-buffer"]; + for(auto v: ja_buf) + out->chars.push_back(v); return out; } -#endif diff --git a/tty.h b/tty.h index 98a9769..008304f 100644 --- a/tty.h +++ b/tty.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -51,10 +52,8 @@ public: tty(console *const c, bus *const b); virtual ~tty(); -#if IS_POSIX - json_t *serialize(); - static tty *deserialize(const json_t *const j, bus *const b, console *const cnsl); -#endif + JsonDocument serialize(); + static tty *deserialize(const JsonDocument j, bus *const b, console *const cnsl); void reset();