From d3b6534bc2a872c2fb762c5a0af815c94edce7fe Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Wed, 25 Oct 2017 22:55:38 +0200 Subject: [PATCH] packet: allow empty body --- src/mconnect/packet.vala | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mconnect/packet.vala b/src/mconnect/packet.vala index 0e1ccdd..75ee676 100644 --- a/src/mconnect/packet.vala +++ b/src/mconnect/packet.vala @@ -45,14 +45,14 @@ class Packet : GLib.Object { public int64 id { get; private set; default = 0; } - public Json.Object body { + public Json.Object ? body { get; private set; default = null; } public Payload ? payload { get; set; default = null; } - public Packet (string type, Json.Object body, int64 id = 0) { + public Packet (string type, Json.Object ? body, int64 id = 0) { this.pkt_type = type; this.body = body; if (id == 0) { @@ -162,7 +162,12 @@ class Packet : GLib.Object { var root_obj = new Json.Object (); root_obj.set_string_member ("type", pkt_type); root_obj.set_int_member ("id", id); - root_obj.set_object_member ("body", body); + + if (this.body != null) + root_obj.set_object_member ("body", body); + else + root_obj.set_object_member ("body", new Json.Object ()); + if (this.payload != null) { root_obj.set_int_member ("payloadSize", (int64) this.payload.size); var pti = new Json.Object ();