Skip to content

Commit da6a2ae

Browse files
committed
[scripts] helpers: add is_vst3_xml / extract_vst3_xml
1 parent d7c34b4 commit da6a2ae

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

helpers.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,42 @@ def print_parameter_properties(parameter):
114114
except AttributeError as e:
115115
# If the property does not exist, print an error message
116116
pprint(f"{property_name}: Property does not exist. Error: {e}")
117+
118+
119+
def is_vst3_xml(raw_state):
120+
"""
121+
Check if the raw state looks like VST3 XML.
122+
123+
This function checks if the 9th to 13th bytes are '<?xml' and the last byte is a null byte (0x00).
124+
125+
Args:
126+
raw_state (bytes): The raw state to check.
127+
128+
Returns:
129+
bool: True if the raw state looks like VST3 XML, False otherwise.
130+
"""
131+
return (
132+
len(raw_state) > 13 and
133+
raw_state[8:13] == b'<?xml' and
134+
raw_state[-1] == 0x00
135+
)
136+
137+
138+
def extract_vst3_xml(raw_state):
139+
"""
140+
Extract the XML content from the VST3 raw state if it is valid.
141+
142+
Args:
143+
raw_state (bytes): The raw state to extract XML from.
144+
145+
Returns:
146+
str or None: The extracted XML content if valid, otherwise None.
147+
"""
148+
if is_vst3_xml(raw_state):
149+
try:
150+
# Extract the bytes between the 8-byte header and the null byte
151+
xml_part = raw_state[8:-1].decode('utf-8')
152+
return xml_part
153+
except UnicodeDecodeError:
154+
pass
155+
return None

0 commit comments

Comments
 (0)