From 1599f676b0f295bc9a2aadbe8018862c45d71e8b Mon Sep 17 00:00:00 2001 From: yihuiyang Date: Wed, 1 Nov 2023 17:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E8=81=94=E9=97=AE=E9=A2=98=E5=8D=9575?= =?UTF-8?q?77=E5=92=8C6097=EF=BC=8C=E8=A7=A3=E5=86=B3StandardMessageCodec?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E5=92=8C=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yihuiyang --- .../plugin/common/StandardMessageCodec.ets | 25 ++++++++++++++----- .../flutter/src/main/ets/util/ByteBuffer.ets | 6 ++--- 2 files changed, 22 insertions(+), 9 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 8650cfe643..0ef49f9715 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 @@ -102,18 +102,25 @@ export default class StandardMessageCodec implements MessageCodec { stream.writeInt8(value ? StandardMessageCodec.TRUE : StandardMessageCodec.FALSE) } else if (typeof value === "number") { if (Number.isInteger(value)) { //整型 - if (-0x7fffffff - 1 <= value && value <= 0x7fffffff) { + if (-0x7fffffff - 1 <= value && value <= 0x7fffffff) { //int32 stream.writeInt8(StandardMessageCodec.INT32) stream.writeInt32(value, true) - } else { + } else if(-0x7fffffffffffffff - 1 <= value && value <= 0x7fffffffffffffff) { //int64 stream.writeInt8(StandardMessageCodec.INT64) - stream.writeInt64(value, true) + stream.writeBigInt64(BigInt(value), true) + } else { //被判为整型的double型 + stream.writeInt8(StandardMessageCodec.FLOAT64) + this.writeAlignment(stream, 8); + stream.writeFloat64(value, true) } } else { //浮点型 stream.writeInt8(StandardMessageCodec.FLOAT64) 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 === "string") { stream.writeInt8(StandardMessageCodec.STRING) let stringBuff = StringUtils.stringToArrayBuffer(value) @@ -126,6 +133,11 @@ export default class StandardMessageCodec implements MessageCodec { this.writeSize(stream, value.length); this.writeAlignment(stream, 4); value.forEach(item => stream.writeInt32(item, true)) + } else if(value instanceof BigInt64Array) { + stream.writeInt8(StandardMessageCodec.INT64_ARRAY) + this.writeSize(stream, value.length); + this.writeAlignment(stream, 8); + value.forEach(item => stream.writeBigInt64(item, true)) } else if (value instanceof Float32Array) { stream.writeInt8(StandardMessageCodec.FLOAT32_ARRAY) this.writeSize(stream, value.length); @@ -231,6 +243,7 @@ export default class StandardMessageCodec implements MessageCodec { break; case StandardMessageCodec.BIGINT: result = buffer.readBigInt64(true) + break; case StandardMessageCodec.FLOAT64: this.readAlignment(buffer, 8); result = buffer.readFloat64(true) @@ -254,12 +267,12 @@ export default class StandardMessageCodec implements MessageCodec { result = array; break; } - case StandardMessageCodec.INT64_ARRAY: { //这里是都城array 还是 bigint待定 + case StandardMessageCodec.INT64_ARRAY: { let length = this.readSize(buffer); - let array: Array = new Array(length) + let array = new BigInt64Array(length) this.readAlignment(buffer, 8); for (let i = 0; i < length; i++) { - array[i] = buffer.readInt64(true) + array[i] = buffer.readBigInt64(true) } result = array; break; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets index 6e0837f5de..38d652b936 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets @@ -573,8 +573,8 @@ export class ByteBuffer { * @param littleEndian If the value is little endian. * @returns The value. */ - getInt64(byteOffset: number, littleEndian?: boolean): number { - return Number(this.getBigInt64(byteOffset, littleEndian)) + getInt64(byteOffset: number, littleEndian?: boolean): bigint { + return this.getBigInt64(byteOffset, littleEndian) } /** @@ -582,7 +582,7 @@ export class ByteBuffer { * @param littleEndian If the value is little endian. * @returns The value. */ - readInt64(littleEndian?: boolean): number { + readInt64(littleEndian?: boolean): bigint { const value = this.getInt64(this.mByteOffset, littleEndian) this.mByteOffset += 8 return value -- Gitee