Skip to content

Commit b060949

Browse files
committed
#RIVS-256 - Vector formatters are displayed incorrectly
1 parent d3e4a1b commit b060949

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/webviews/src/utils/formatters/valueFormatters.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
binaryToBuffer,
2323
bufferToFloat64Array,
2424
bufferToFloat32Array,
25+
isEqualBuffers,
26+
UTF8ToBuffer,
2527
} from 'uiSrc/utils'
2628
import { reSerializeJSON } from 'uiSrc/utils/formatters/json'
2729

@@ -107,13 +109,18 @@ const formattingBuffer = (
107109
}
108110
}
109111
case KeyValueFormat.Vector32Bit: {
112+
const valueUTF = bufferToUTF8(reply)
110113
try {
114+
if (isEqualBuffers(reply, UTF8ToBuffer(valueUTF))) {
115+
return { value: valueUTF, isValid: false }
116+
}
117+
111118
const vector = Array.from(bufferToFloat32Array(reply.data as Uint8Array))
112119
const value = JSONBigInt.stringify(vector)
113120

114121
return JSONViewer({ value, useNativeBigInt: false, ...props })
115122
} catch (e) {
116-
return { value: bufferToUTF8(reply), isValid: false }
123+
return { value: valueUTF, isValid: false }
117124
}
118125
}
119126
case KeyValueFormat.Vector64Bit: {
@@ -170,8 +177,8 @@ const bufferToSerializedFormat = (
170177
case KeyValueFormat.HEX: return bufferToHex(value)
171178
case KeyValueFormat.Binary: return bufferToBinary(value)
172179
case KeyValueFormat.JSON: return reSerializeJSON(bufferToUTF8(value), space)
173-
case KeyValueFormat.Vector32Bit: return bufferToFloat32Array(value.data as Uint8Array)
174-
case KeyValueFormat.Vector64Bit: return bufferToFloat64Array(value.data as Uint8Array)
180+
case KeyValueFormat.Vector32Bit: return bufferToFloat32Array(value.data as Uint8Array) as any
181+
case KeyValueFormat.Vector64Bit: return bufferToFloat64Array(value.data as Uint8Array) as any
175182
case KeyValueFormat.Msgpack: {
176183
try {
177184
const decoded = decode(Uint8Array.from(value.data))

0 commit comments

Comments
 (0)