Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: GPL-2.0-only |
0076e742 SM |
2 | # |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
0076e742 SM |
5 | |
6 | import bt2 | |
7 | ||
8 | ||
9 | def to_string(p): | |
10 | # Print BT values in a predictable way (the order of map entries) and with | |
11 | # additional information (u suffix to differentiate unsigned integers from | |
12 | # signed integers). | |
13 | ||
14 | if type(p) is bt2._ArrayValueConst: | |
15 | s = '[{}]'.format(', '.join([to_string(x) for x in p])) | |
16 | elif type(p) is bt2._MapValueConst: | |
17 | s = '{{{}}}'.format( | |
18 | ', '.join([k + '=' + to_string(p[k]) for k in sorted(p.keys())]) | |
19 | ) | |
20 | elif type(p) is bt2._UnsignedIntegerValueConst: | |
21 | s = str(p) + 'u' | |
22 | elif ( | |
23 | type(p) | |
24 | in ( | |
25 | bt2._StringValueConst, | |
26 | bt2._SignedIntegerValueConst, | |
27 | bt2._RealValueConst, | |
28 | bt2._BoolValueConst, | |
29 | ) | |
30 | or p is None | |
31 | ): | |
32 | s = str(p) | |
33 | ||
34 | else: | |
35 | raise TypeError('Unexpected type', type(p)) | |
36 | ||
37 | return s |