From 04d481557c286bf62cc3e667f35113d11a96da62 Mon Sep 17 00:00:00 2001 From: godotg Date: Mon, 29 Jul 2024 11:29:47 +0800 Subject: [PATCH] chore[protocol]: deep clone log --- protocol/src/main/resources/php/ByteBuffer.php | 1 + protocol/src/main/resources/python/ByteBuffer.py | 1 + 2 files changed, 2 insertions(+) diff --git a/protocol/src/main/resources/php/ByteBuffer.php b/protocol/src/main/resources/php/ByteBuffer.php index 6067ab17..5481c09b 100644 --- a/protocol/src/main/resources/php/ByteBuffer.php +++ b/protocol/src/main/resources/php/ByteBuffer.php @@ -32,6 +32,7 @@ class ByteBuffer $this->writeInt($length); $this->writeOffset = $currentwriteIndex; } else { + // substr is deep clone $bytes = substr($this->buffer, $currentwriteIndex - $length, $length); $this->writeOffset = $beforewriteIndex; $this->writeInt($length); diff --git a/protocol/src/main/resources/python/ByteBuffer.py b/protocol/src/main/resources/python/ByteBuffer.py index 3f10b45b..5ebe7623 100644 --- a/protocol/src/main/resources/python/ByteBuffer.py +++ b/protocol/src/main/resources/python/ByteBuffer.py @@ -25,6 +25,7 @@ class ByteBuffer(): self.writeInt(length) self.setWriteOffset(currentWriteIndex) else: + # slice of bytearray is deep clone retainedByteBuf = self.buffer[(currentWriteIndex - length):currentWriteIndex] self.setWriteOffset(beforeWriteIndex) self.writeInt(length)