[CRIU] [PATCH 2/7] pycriu: images: merge payload field into entry and add extra field to entry if needed

Ruslan Kuprieiev kupruser at gmail.com
Wed Jan 14 06:32:36 PST 2015


Before:
{
    "magic" : "FOO",
    "entries" : [
        {
            "payload" : {
                "foo" : "bar",
                "bar" : "foo"
            },
            "extra" : "abc"
        },
        {
            "payload" : {
            "foo" : "bar",
            "bar" : "foo"
            },
            "extra" : "abc"
        }
    ]
}

After:
{
    "magic" : "FOO",
    "entries" : [
        {
            "foo" : "bar",
            "bar" : "foo"
            "extra" : "abc"
        },
        {
            "foo" : "bar",
            "bar" : "foo"
            "extra" : "abc"
        }
    ]
}

We don't have any fields named "extra" in our pb msgs and it is
not likely that we will ever have one, so there is no reason to
worry about that.

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 pycriu/images/images.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/pycriu/images/images.py b/pycriu/images/images.py
index a982dde..35abdec 100644
--- a/pycriu/images/images.py
+++ b/pycriu/images/images.py
@@ -30,7 +30,7 @@
 # Entry, in its turn, could be described as:
 #
 # {
-#	'payload' : pb_msg,
+#	pb_msg,
 #	'extra' : extra_msg
 # }
 #
@@ -77,7 +77,7 @@ class entry_handler:
 				break
 			size, = struct.unpack('i', buf)
 			pb.ParseFromString(f.read(size))
-			entry['payload'] = pb2dict.pb2dict(pb)
+			entry = pb2dict.pb2dict(pb)
 
 			# Read extra
 			if self.extra_handler:
@@ -101,17 +101,19 @@ class entry_handler:
 		in binary format to.
 		"""
 		for entry in entries:
+			extra = entry.pop('extra', None)
+
 			# Write payload
 			pb = self.payload()
-			pb2dict.dict2pb(entry['payload'], pb)
+			pb2dict.dict2pb(entry, pb)
 			pb_str = pb.SerializeToString()
 			size = len(pb_str)
 			f.write(struct.pack('i', size))
 			f.write(pb_str)
 
 			# Write extra
-			if self.extra_handler:
-				self.extra_handler.dump(entry['extra'], f, pb)
+			if self.extra_handler and extra:
+				self.extra_handler.dump(extra, f, pb)
 
 	def dumps(self, entries):
 		"""
-- 
2.1.0



More information about the CRIU mailing list