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 8650cfe643a400cfba7dd4b99b505f151fa82bd7..0ef49f9715e01e8c56d503570e82abbbbfbb1d4a 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 6e0837f5de981501166a2f78067c37402a37bd3c..38d652b9368dd9c81dc8d6bb419e207785cc44eb 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