-
Notifications
You must be signed in to change notification settings - Fork 2
/
chepy_protobuf.py
44 lines (35 loc) · 1.15 KB
/
chepy_protobuf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import lazy_import
import logging
try:
blackboxprotobuf = lazy_import.lazy_module("blackboxprotobuf")
except ImportError:
logging.warning(
"Could not import blackboxprotobuf. Use pip install blackboxprotobuf"
)
import chepy.core
class Chepy_Protobuf(chepy.core.ChepyCore):
"""This plugin allows helps decoding protobuf without
proto file
"""
@chepy.core.ChepyDecorators.call_stack
def protobuf_decode_json(self, bytes_as_hex: bool = False):
"""Decode protobuf to json string
Args:
bytes_as_hex (bool, optional): Convert bytes to hex. Defaults to False.
Returns:
ChepyPlugin: The Chepy object.
"""
j, _ = blackboxprotobuf.protobuf_to_json(
self._convert_to_bytes(), bytes_as_hex=bytes_as_hex
)
self.state = j
return self
@chepy.core.ChepyDecorators.call_stack
def protobuf_decode_dict(self):
"""Decode protobuf to python dict
Returns:
ChepyPlugin: The Chepy object.
"""
j, _ = blackboxprotobuf.decode_message(self._convert_to_bytes())
self.state = j
return self