1 package edu.jiangxin.apktoolbox.convert.protobuf.unsupervised;
2
3 import com.google.protobuf.WireFormat;
4 import org.apache.commons.collections4.CollectionUtils;
5 import org.json.JSONObject;
6
7 import java.util.List;
8
9 public class DecoderResult {
10
11
12
13
14 private List<Integer> byteRange;
15
16
17
18 private int fieldNumber;
19
20
21
22 private int type;
23
24
25
26 private String content;
27
28
29
30 private List<DecoderResult> subResults;
31
32 public List<Integer> getByteRange() {
33 return byteRange;
34 }
35
36 public void setByteRange(List<Integer> byteRange) {
37 this.byteRange = byteRange;
38 }
39
40 public int getFieldNumber() {
41 return fieldNumber;
42 }
43
44 public void setFieldNumber(int fieldNumber) {
45 this.fieldNumber = fieldNumber;
46 }
47
48 public int getType() {
49 return type;
50 }
51
52 public void setType(int type) {
53 this.type = type;
54 }
55
56 public String getContent() {
57 return content;
58 }
59
60 public void setContent(String content) {
61 this.content = content;
62 }
63
64 public List<DecoderResult> getSubResults() {
65 return subResults;
66 }
67
68 public void setSubResults(List<DecoderResult> subResults) {
69 this.subResults = subResults;
70 }
71
72 public JSONObject toJson() {
73 JSONObject json = new JSONObject();
74 json.put("byteRange", byteRange);
75 json.put("fieldNumber", fieldNumber);
76 json.put("type", typeToString(type));
77 if (CollectionUtils.isEmpty(subResults)) {
78 json.put("content", content);
79 } else {
80 json.put("content", subResults);
81 }
82 return json;
83 }
84
85
86
87
88
89
90
91 private static String typeToString(int type) {
92 switch (type) {
93 case WireFormat.WIRETYPE_VARINT:
94 return "varint";
95 case WireFormat.WIRETYPE_LENGTH_DELIMITED:
96 return "length_delimited";
97 case WireFormat.WIRETYPE_FIXED32:
98 return "fixed32";
99 case WireFormat.WIRETYPE_FIXED64:
100 return "fixed64";
101 default:
102 return "unknown";
103 }
104 }
105 }