From 20166e94b18fe550188ffa3403a4826888b37e4d Mon Sep 17 00:00:00 2001 From: Roman Karwacik Date: Fri, 21 Aug 2026 13:33:16 +0200 Subject: [PATCH] Add BYTEARRAY8 opcode --- fickling/fickle.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fickling/fickle.py b/fickling/fickle.py index c71b7f1..d6e62d1 100644 --- a/fickling/fickle.py +++ b/fickling/fickle.py @@ -2386,6 +2386,29 @@ class BinBytes8(BinBytes): length_bytes = 8 +class Bytearray8(DynamicLength, ConstantOpcode): + name = "BYTEARRAY8" + priority = BinBytes8.priority + 1 + length_bytes = 8 + + def encode_body(self) -> bytes: + arg = self.arg + return arg if isinstance(arg, bytes) else bytes(arg) + + @classmethod + def validate(cls, obj): + if not isinstance(obj, bytearray): + raise ValueError(f"{cls.__name__} must be instantiated with a bytearray, not {obj!r}") + return super().validate(obj) + + def run(self, interpreter: Interpreter): + arg = self.arg + data = arg if isinstance(arg, bytes) else bytes(arg) + interpreter.stack.append( + ast.Call(ast.Name("bytearray", ast.Load()), [make_constant(data)], []) + ) + + class Long1(ConstantInt): name = "LONG1" num_bytes = 1