From afbb3b1e807cc8fb3fd4d6b74689afd5d4f91fc3 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Sat, 20 Jul 2024 15:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bigint=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../ets/plugin/common/StandardMessageCodec.ets | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets index 5101b51213..ed6c8d611c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets @@ -100,6 +100,8 @@ export default class StandardMessageCodec implements MessageCodec { private static LIST = 12; private static MAP = 13; private static FLOAT32_ARRAY = 14; + private INT64_MAX = 9223372036854775807; + private INT64_MIN = -9223372036854775808; writeValue(stream: ByteBuffer, value: Any): Any { @@ -125,9 +127,18 @@ export default class StandardMessageCodec implements MessageCodec { this.writeAlignment(stream, 8); stream.writeFloat64(value, true); } - }else if (typeof value === "bigint") { - stream.writeInt8(StandardMessageCodec.INT64); - stream.writeBigInt64(value, true); + } else if (typeof value === "bigint") { + if (value >= this.INT64_MIN && value <= this.INT64_MAX) { + stream.writeInt8(StandardMessageCodec.INT64); + stream.writeBigInt64(value, true); + } else { + // Convert bigint to a hexadecimal string + stream.writeInt8(StandardMessageCodec.BIGINT); + const hexString = value.toString(16); + // Map each character in the hexadecimal string to its ASCII code + const asciiString = hexString.split('').map(char => char.charCodeAt(0)); + this.writeBytes(stream, Uint8Array.from(asciiString)); + } } else if (typeof value === "string") { stream.writeInt8(StandardMessageCodec.STRING); let stringBuff = StringUtils.stringToArrayBuffer(value); -- Gitee