Completed
Push — master ( 61d444...b3f358 )
by Jan
16s queued 14s
created

src/frames/frame-txxx.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 26
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
mnd 1
bc 1
fnc 0
dl 0
loc 26
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { FrameBuilder } from "../FrameBuilder"
2
import { FrameReader } from "../FrameReader"
3
import type { Data } from "./type"
4
5
export const TXXX = {
6
    create: (data: Data) => {
7
        if(!(data instanceof Array)) {
8
            data = [data]
9
        }
10
11
        return Buffer.concat(data.map((udt: Data) => new FrameBuilder("TXXX")
12
            .appendNumber(0x01, 1)
13
            .appendNullTerminatedValue(udt.description, 0x01)
14
            .appendValue(udt.value, null, 0x01)
15
            .getBuffer()))
16
    },
17
    read: (buffer: Buffer) => {
18
        const reader = new FrameReader(buffer, 0)
19
20
        return {
21
            description: reader.consumeNullTerminatedValue('string'),
22
            value: reader.consumeStaticValue('string')
23
        }
24
    }
25
}
26