From 7197aff7034ad37c67bd14ea793ac0c8663ae9db Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 24 Jun 2015 11:57:00 +0300 Subject: [PATCH] pycriu: images: pb2dict: preserve fields order with "pretty" option Using collections.OrderedDict allows us to keep fields in the same order as they appear in corresponding proto files, which helps to impove readability. In non-pretty mode we still use regular dict. Signed-off-by: Ruslan Kuprieiev Signed-off-by: Pavel Emelyanov --- pycriu/images/pb2dict.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pycriu/images/pb2dict.py b/pycriu/images/pb2dict.py index 8d06dc94c..39670da6f 100644 --- a/pycriu/images/pb2dict.py +++ b/pycriu/images/pb2dict.py @@ -2,6 +2,7 @@ from google.protobuf.descriptor import FieldDescriptor as FD import opts_pb2 import ipaddr import socket +import collections # pb2dict and dict2pb are methods to convert pb to/from dict. # Inspired by: @@ -74,7 +75,7 @@ def pb2dict(pb, pretty = False, is_hex = False): Convert protobuf msg to dictionary. Takes a protobuf message and returns a dict. """ - d = {} + d = collections.OrderedDict() if pretty else {} for field, value in pb.ListFields(): if field.label == FD.LABEL_REPEATED: d_val = []