Skip to content

Commit 95e4e1e

Browse files
committed
Use encode/decode functions
1 parent 37c46f9 commit 95e4e1e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

redisinsight/ui/src/utils/formatters/valueFormatters.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unpack, pack } from 'msgpackr';
1+
import { encode, decode } from 'msgpackr';
22
// eslint-disable-next-line import/order
33
import { Buffer } from 'buffer'
44
import { isUndefined } from 'lodash'
@@ -72,7 +72,7 @@ const formattingBuffer = (
7272
case KeyValueFormat.JSON: return bufferToJSON(reply, props as FormattingProps)
7373
case KeyValueFormat.Msgpack: {
7474
try {
75-
const decoded = unpack(new Uint8Array(reply.data));
75+
const decoded = decode(reply.data);
7676
const value = JSONBigInt.stringify(decoded)
7777
return JSONViewer({ value, ...props })
7878
} catch (e) {
@@ -139,7 +139,7 @@ const bufferToSerializedFormat = (
139139
case KeyValueFormat.JSON: return reSerializeJSON(bufferToUTF8(value), space)
140140
case KeyValueFormat.Msgpack: {
141141
try {
142-
const decoded = unpack(new Uint8Array(value.data)
142+
const decoded = decode(value.data)
143143
const stringified = JSON.stringify(decoded)
144144
return reSerializeJSON(stringified, space)
145145
} catch (e) {
@@ -180,7 +180,7 @@ const stringToSerializedBufferFormat = (format: KeyValueFormat, value: string):
180180
case KeyValueFormat.Msgpack: {
181181
try {
182182
const json = JSON.parse(value)
183-
const encoded = Uint8Array.from(pack(json))
183+
const encoded = encode(json)
184184
return anyToBuffer(encoded)
185185
} catch (e) {
186186
return stringToBuffer(value, format)

redisinsight/ui/src/utils/tests/formatters/valueFormatters.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pack } from 'msgpackr'
1+
import { encode } from 'msgpackr'
22
import { serialize } from 'php-serialize'
33
import { KeyValueFormat } from 'uiSrc/constants'
44
import { anyToBuffer, bufferToSerializedFormat, stringToBuffer, stringToSerializedBufferFormat } from 'uiSrc/utils'
@@ -25,7 +25,7 @@ describe('bufferToSerializedFormat', () => {
2525
describe(KeyValueFormat.Msgpack, () => {
2626
describe('should properly serialize', () => {
2727
const testValues = [{}, '""', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
28-
input: anyToBuffer(Uint8Array.from(pack(v))),
28+
input: anyToBuffer(encode(v)),
2929
expected: JSON.stringify(v)
3030
}))
3131

@@ -88,7 +88,7 @@ describe('stringToSerializedBufferFormat', () => {
8888
describe('should properly unserialize', () => {
8989
const testValues = [{}, '""', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
9090
input: JSON.stringify(v),
91-
expected: anyToBuffer(Uint8Array.from(pack(v)))
91+
expected: anyToBuffer(encode(v))
9292
}))
9393

9494
test.each(testValues)('test %j', ({ input, expected }) => {

0 commit comments

Comments
 (0)