-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
345efa7
commit 55b41b3
Showing
7 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@msgpack/msgpack": "3.0.0-beta2", | ||
"debounce": "^2.0.0", | ||
"type-fest": "^4.10.2" | ||
}, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * as JsonMap from './json-map.ts'; | ||
export * as MSGPack from './msg-pack.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { JsonValue } from 'type-fest'; | ||
import { decode, encode } from '@msgpack/msgpack'; | ||
|
||
export function parse(data: any): Map<string, JsonValue> { | ||
if (typeof data !== 'string') { | ||
throw new Error('MessagePack data must be a string'); | ||
} | ||
const buffer = Buffer.from(data, 'base64'); | ||
const decoded = decode(buffer); | ||
|
||
if (typeof decoded !== 'object') { | ||
throw new Error('MessagePack data must be an object'); | ||
} | ||
|
||
return new Map(Object.entries(decoded as object)); | ||
} | ||
|
||
export function stringify(data: any): string { | ||
if (!(data instanceof Map)) { | ||
throw new Error('MessagePack data must be a Map'); | ||
} | ||
const obj = Object.fromEntries(data); | ||
const encoded = encode(obj); | ||
const buffer = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength); | ||
return buffer.toString('base64'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters