feat(new tool): JSON <> Message Pack

Fix #1139
This commit is contained in:
ShareVB committed 2025-11-12 21:37:46 +01:00
1 parent 29c14837b6
commit b7a28dbfaa
6 files changed
+287 -15

No files matched your search

+1
View File
@@ -246,6 +246,7 @@
"moment": "^2.30.1",
"monaco-editor": "^0.54.0",
"morsee": "^1.0.10",
"msgpackr": "^1.11.5",
"naive-ui": "^2.35.0",
"nanoid": "^5.1.6",
"nanoid-dictionary": "^5.0.0",
+85 -15
View File
@@ -626,6 +626,9 @@ importers:
morsee:
specifier: ^1.0.10
version: 1.0.10
msgpackr:
specifier: ^1.11.5
version: 1.11.5
naive-ui:
specifier: ^2.35.0
version: 2.41.0(vue@3.3.4)
@@ -3133,6 +3136,36 @@ packages:
'@monaco-editor/loader@1.5.0':
resolution: {integrity: sha512-hKoGSM+7aAc7eRTRjpqAZucPmoNOC4UUbknb/VNoTkEIkCPhqV8LfbsgM1webRM7S/z21eHEx9Fkwx8Z/C/+Xw==}
'@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3':
resolution: {integrity: sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw==}
cpu: [arm64]
os: [darwin]
'@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3':
resolution: {integrity: sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw==}
cpu: [x64]
os: [darwin]
'@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3':
resolution: {integrity: sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg==}
cpu: [arm64]
os: [linux]
'@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3':
resolution: {integrity: sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw==}
cpu: [arm]
os: [linux]
'@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3':
resolution: {integrity: sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg==}
cpu: [x64]
os: [linux]
'@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3':
resolution: {integrity: sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ==}
cpu: [x64]
os: [win32]
'@napi-rs/canvas-android-arm64@0.1.70':
resolution: {integrity: sha512-I/YOuQ0wbkVYxVaYtCgN42WKTYxNqFA0gTcTrHIGG1jfpDSyZWII/uHcjOo4nzd19io6Y4+/BqP8E5hJgf9OmQ==}
engines: {node: '>= 10'}
@@ -6030,10 +6063,6 @@ packages:
engines: {node: '>=0.10'}
hasBin: true
detect-libc@2.0.3:
resolution: {integrity: sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==}
engines: {node: '>=8'}
detect-libc@2.0.4:
resolution: {integrity: sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==}
engines: {node: '>=8'}
@@ -7419,9 +7448,6 @@ packages:
is-core-module@2.13.0:
resolution: {integrity: sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==}
is-core-module@2.13.1:
resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==}
is-core-module@2.16.1:
resolution: {integrity: sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==}
engines: {node: '>= 0.4'}
@@ -8497,6 +8523,13 @@ packages:
ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
msgpackr-extract@3.0.3:
resolution: {integrity: sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA==}
hasBin: true
msgpackr@1.11.5:
resolution: {integrity: sha512-UjkUHN0yqp9RWKy0Lplhh+wlpdt9oQBYgULZOiFhV3VclSF1JnSQWZ5r9gORQlNYaUKQoR8itv7g7z1xDDuACA==}
muggle-string@0.3.1:
resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==}
@@ -8608,6 +8641,10 @@ packages:
resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==}
engines: {node: '>= 6.13.0'}
node-gyp-build-optional-packages@5.2.2:
resolution: {integrity: sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw==}
hasBin: true
node-gyp-build@4.8.4:
resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==}
hasBin: true
@@ -14032,6 +14069,24 @@ snapshots:
dependencies:
state-local: 1.0.7
'@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3':
optional: true
'@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3':
optional: true
'@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3':
optional: true
'@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3':
optional: true
'@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3':
optional: true
'@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3':
optional: true
'@napi-rs/canvas-android-arm64@0.1.70':
optional: true
@@ -17254,8 +17309,6 @@ snapshots:
detect-libc@1.0.3:
optional: true
detect-libc@2.0.3: {}
detect-libc@2.0.4: {}
detect-node@2.1.0: {}
@@ -18857,10 +18910,6 @@ snapshots:
dependencies:
has: 1.0.3
is-core-module@2.13.1:
dependencies:
hasown: 2.0.2
is-core-module@2.16.1:
dependencies:
hasown: 2.0.2
@@ -19974,6 +20023,22 @@ snapshots:
ms@2.1.3: {}
msgpackr-extract@3.0.3:
dependencies:
node-gyp-build-optional-packages: 5.2.2
optionalDependencies:
'@msgpackr-extract/msgpackr-extract-darwin-arm64': 3.0.3
'@msgpackr-extract/msgpackr-extract-darwin-x64': 3.0.3
'@msgpackr-extract/msgpackr-extract-linux-arm': 3.0.3
'@msgpackr-extract/msgpackr-extract-linux-arm64': 3.0.3
'@msgpackr-extract/msgpackr-extract-linux-x64': 3.0.3
'@msgpackr-extract/msgpackr-extract-win32-x64': 3.0.3
optional: true
msgpackr@1.11.5:
optionalDependencies:
msgpackr-extract: 3.0.3
muggle-string@0.3.1: {}
mute-stdout@2.0.0: {}
@@ -20083,6 +20148,11 @@ snapshots:
node-forge@1.3.1: {}
node-gyp-build-optional-packages@5.2.2:
dependencies:
detect-libc: 2.0.4
optional: true
node-gyp-build@4.8.4: {}
node-int64@0.4.0: {}
@@ -20659,7 +20729,7 @@ snapshots:
prebuild-install@7.1.3:
dependencies:
detect-libc: 2.0.3
detect-libc: 2.0.4
expand-template: 2.0.3
github-from-package: 0.0.0
minimist: 1.2.8
@@ -21165,7 +21235,7 @@ snapshots:
resolve@1.22.2:
dependencies:
is-core-module: 2.13.1
is-core-module: 2.16.1
path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0
+13
View File
@@ -0,0 +1,13 @@
import { Binary } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'JSON to MessagePack',
path: '/json-to-msgpack',
description: 'Convert JSON to MessagePack',
keywords: ['json', 'message', 'pack', 'msgpack'],
component: () => import('./json-to-msgpack.vue'),
icon: Binary,
createdAt: new Date('2025-11-11'),
category: 'JSON',
});
@@ -0,0 +1,97 @@
<script setup lang="ts">
import type { Buffer } from 'node:buffer';
import { pack } from 'msgpackr';
import JSON5 from 'json5';
import { useValidation } from '@/composable/validation';
const jsonInput = ref('');
const fileName = ref('');
const error = ref('');
const jsonValidation = useValidation({
source: jsonInput,
rules: [
{
validator: (v) => {
return JSON5.parse(v);
},
message: 'JSON is invalid',
},
],
});
const msgPackHex = ref('');
const msgPacked = ref<Buffer | null>(null);
function convertToMsgPack() {
error.value = '';
msgPackHex.value = '';
try {
msgPacked.value = pack(JSON5.parse(jsonInput.value));
msgPackHex.value = msgPacked.value.toString('hex');
}
catch (e: any) {
error.value = e.toString();
}
}
function downloadURL(data: string, fileName: string) {
const a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style.display = 'none';
a.click();
a.remove();
}
function downloadBlob(data: Uint8Array, fileName: string) {
const blob = new Blob([data], {
type: 'application/octet-stream',
});
const url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(() => window.URL.revokeObjectURL(url), 1000);
}
</script>
<template>
<div>
<c-input-text
v-model:value="fileName"
label="Output filename:"
label-position="left"
placeholder="Enter output filename"
mb-2
/>
<c-input-text
v-model:value="jsonInput"
label="JSON to convert:"
multiline
placeholder="Enter JSON to convert..."
:validation="jsonValidation"
rows="5"
mb-2
/>
<div mb-2 flex justify-center>
<n-button @click="convertToMsgPack()">
Convert
</n-button>
</div>
<c-card v-if="msgPackHex" title="MsgPack Binary:">
<textarea-copyable :value="msgPackHex" mb-3 />
<div flex justify-center>
<c-button :disabled="jsonInput === '' || !jsonValidation.isValid" @click="downloadBlob(msgPacked!, fileName)">
Download MsgPack file
</c-button>
</div>
</c-card>
<c-alert v-if="error">
{{ error }}
</c-alert>
</div>
</template>
+13
View File
@@ -0,0 +1,13 @@
import { Binary } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Message Pack to JSON',
path: '/msgpack-to-json',
description: 'Convert MessagePack file to JSON',
keywords: ['msgpack', 'message', 'pack', 'json'],
component: () => import('./msgpack-to-json.vue'),
icon: Binary,
createdAt: new Date('2025-11-01'),
category: 'JSON',
});
@@ -0,0 +1,78 @@
<script setup lang="ts">
import { Buffer } from 'node:buffer';
import { unpack } from 'msgpackr';
import hexArray from 'hex-array';
const inputType = ref<'file' | 'content'>('file');
const fileInput = ref() as Ref<File | null>;
const hexInput = ref('');
const error = ref('');
const results = computedAsync(async () => {
error.value = '';
try {
if (inputType.value === 'file') {
const file = fileInput.value;
if (file == null) {
return null;
}
return unpack(Buffer.from(await file.arrayBuffer()));
}
else {
return unpack(hexArray.fromString(hexInput.value));
}
}
catch (e: any) {
error.value = e.toString();
return [];
}
});
const resultsJson = computed(() => JSON.stringify(results.value || [], (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
function onUpload(file: File) {
if (file) {
fileInput.value = file;
}
}
</script>
<template>
<div>
<c-card title="Input Message Pack file or content" mb-2>
<n-radio-group v-model:value="inputType" name="radiogroup" mb-2 flex justify-center>
<n-space>
<n-radio
value="file"
label="File"
/>
<n-radio
value="content"
label="Hex Content"
/>
</n-space>
</n-radio-group>
<c-file-upload
v-if="inputType === 'file'"
title="Drag and drop MsgPack file here, or click to select a file"
@file-upload="onUpload"
/>
<c-input-text
v-if="inputType === 'content'"
v-model:value="hexInput"
label="Hex Content:"
multiline
/>
</c-card>
<c-alert v-if="error">
{{ error }}
</c-alert>
<c-card title="JSON Content">
<textarea-copyable :value="resultsJson" language="json" :download-file-name="`${fileInput?.name}.json`" />
</c-card>
</div>
</template>