From 141542fe40a89fa8ee5176890d4a4d45794f031e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 27 Feb 2016 07:51:04 +0100 Subject: [PATCH] Add base class for future compacts --- .gitignore | 1 + src/Makefile.am | 1 + src/matrix-compacts.vala | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/matrix-compacts.vala diff --git a/.gitignore b/.gitignore index 9ef1177..db191e5 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ Makefile.in /src/matrix-enums.c /src/matrix-http-api.c /src/matrix-http-client.c +/src/matrix-compacts.c diff --git a/src/Makefile.am b/src/Makefile.am index 3273a95..52ee23a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-enums.vala \ matrix-http-api.vala \ matrix-http-client.vala \ + matrix-compacts.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-compacts.vala b/src/matrix-compacts.vala new file mode 100644 index 0000000..bf4d318 --- /dev/null +++ b/src/matrix-compacts.vala @@ -0,0 +1,38 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with matrix-glib-sdk. If not, see + * . + */ +namespace Matrix { + /** + * Abstract parent class for classes that can be saved to JSON. + */ + public abstract class JsonCompact { + public abstract Json.Node? + get_json_node() + throws Matrix.Error; + + public string + get_json_data(out size_t datalen) + throws Matrix.Error + { + var generator = new Json.Generator(); + + generator.set_root(get_json_node()); + + return generator.to_data(out datalen); + } + } +}