[CRIU] [PATCH 1/2] pycriu: images: pb2dict: support 'all hex' messages

Ruslan Kuprieiev kupruser at gmail.com
Mon Jan 19 03:33:13 PST 2015


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

diff --git a/pycriu/images/pb2dict.py b/pycriu/images/pb2dict.py
index c01442c..204fd4d 100644
--- a/pycriu/images/pb2dict.py
+++ b/pycriu/images/pb2dict.py
@@ -40,18 +40,22 @@ _basic_cast = {
 	FD.TYPE_STRING		: unicode
 }
 
-def _pb2dict_cast(field, value, print_hex = False):
+def _marked_as_hex(field):
+	return field.GetOptions().Extensions[opts_pb2.criu].hex
+
+def _pb2dict_cast(field, value, print_hex = False, is_hex = False):
+	if not is_hex:
+		is_hex = _marked_as_hex(field)
+
 	if field.type == FD.TYPE_MESSAGE:
-		return pb2dict(value, print_hex)
+		return pb2dict(value, print_hex, is_hex)
 	elif field.type == FD.TYPE_BYTES:
 		return value.encode('base64')
 	elif field.type == FD.TYPE_ENUM:
 		return field.enum_type.values_by_number.get(value, None).name
 	elif field.type in _basic_cast:
 		cast = _basic_cast[field.type]
-		if (cast == int or cast == long) and \
-		   field.GetOptions().Extensions[opts_pb2.criu].hex and \
-		   print_hex:
+		if (cast == int or cast == long) and is_hex and print_hex:
 			# Fields that have (criu).hex = true option set
 			# should be stored in hex string format.
 			return "0x%x" % value
@@ -60,7 +64,7 @@ def _pb2dict_cast(field, value, print_hex = False):
 	else:
 		raise Exception("Field(%s) has unsupported type %d" % (field.name, field.type))
 
-def pb2dict(pb, print_hex = False):
+def pb2dict(pb, print_hex = False, is_hex = False):
 	"""
 	Convert protobuf msg to dictionary.
 	Takes a protobuf message and returns a dict.
@@ -70,9 +74,9 @@ def pb2dict(pb, print_hex = False):
 		if field.label == FD.LABEL_REPEATED:
 			d_val = []
 			for v in value:
-				d_val.append(_pb2dict_cast(field, v, print_hex))
+				d_val.append(_pb2dict_cast(field, v, print_hex, is_hex))
 		else:
-			d_val = _pb2dict_cast(field, value, print_hex)
+			d_val = _pb2dict_cast(field, value, print_hex, is_hex)
 
 		d[field.name] = d_val
 	return d
-- 
2.1.0



More information about the CRIU mailing list