File tree 2 files changed +27
-19
lines changed
2 files changed +27
-19
lines changed Original file line number Diff line number Diff line change 1
1
// @ts -check
2
2
3
3
/**
4
- * @template {number} Code
5
4
* @template T
6
- * @typedef {import('./interface').BlockCodec<Code, T> } BlockCodec
5
+ * @typedef {import('./interface').ByteView< T> } ByteView
7
6
*/
8
7
8
+ export const name = 'json'
9
+ export const code = 0x0200
10
+
11
+ /**
12
+ * @template T
13
+ * @param {T } node
14
+ * @returns {ByteView<T> }
15
+ */
16
+ export const encode = ( node ) => new TextEncoder ( ) . encode ( JSON . stringify ( node ) )
17
+
9
18
/**
10
19
* @template T
11
- * @type {BlockCodec<0x0200, T> }
20
+ * @param {ByteView<T> } data
21
+ * @returns {T }
12
22
*/
13
- export const { name, code, encode, decode } = {
14
- name : 'json' ,
15
- code : 0x0200 ,
16
- encode : json => new TextEncoder ( ) . encode ( JSON . stringify ( json ) ) ,
17
- decode : bytes => JSON . parse ( new TextDecoder ( ) . decode ( bytes ) )
18
- }
23
+ export const decode = ( data ) => JSON . parse ( new TextDecoder ( ) . decode ( data ) )
Original file line number Diff line number Diff line change 3
3
import { coerce } from '../bytes.js'
4
4
5
5
/**
6
- * @template {number} Code
7
6
* @template T
8
- * @typedef {import('./interface').BlockCodec<Code, T> } BlockCodec
7
+ * @typedef {import('./interface').ByteView< T> } ByteView
9
8
*/
10
9
11
10
/**
@@ -14,13 +13,17 @@ import { coerce } from '../bytes.js'
14
13
*/
15
14
const raw = ( bytes ) => coerce ( bytes )
16
15
16
+ export const name = 'raw'
17
+ export const code = 0x55
18
+
17
19
/**
18
- * @template T
19
- * @type {BlockCodec<0x55, Uint8Array> }
20
+ * @param {Uint8Array } node
21
+ * @returns {ByteView<Uint8Array> }
22
+ */
23
+ export const encode = ( node ) => raw ( node )
24
+
25
+ /**
26
+ * @param {ByteView<Uint8Array> } data
27
+ * @returns {Uint8Array }
20
28
*/
21
- export const { name, code, encode, decode } = {
22
- name : 'raw' ,
23
- code : 0x55 ,
24
- decode : raw ,
25
- encode : raw
26
- }
29
+ export const decode = ( data ) => raw ( data )
You can’t perform that action at this time.
0 commit comments