• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LukaJCB / ts-mls / 20546506344

28 Dec 2025 12:42AM UTC coverage: 96.121% (-0.1%) from 96.237%
20546506344

push

github

LukaJCB
Deprecate json codec for group state

1239 of 1388 branches covered (89.27%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

16 existing lines in 5 files now uncovered.

7162 of 7352 relevant lines covered (97.42%)

44152.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.49
/src/codec/tlsDecoder.ts
1
export type Decoder<T> = (b: Uint8Array, offset: number) => [T, number] | undefined
2

3
export function mapDecoder<T, U>(dec: Decoder<T>, f: (t: T) => U): Decoder<U> {
1✔
4
  return (b, offset) => {
18,050✔
5
    const x = dec(b, offset)
52,851✔
6
    if (x !== undefined) {
52,851✔
7
      const [t, l] = x
52,851✔
8
      return [f(t), l]
52,851✔
9
    }
52,851✔
10
  }
52,851✔
11
}
18,050✔
12

13
export function mapDecodersOption<T extends unknown[], R>(
1✔
14
  decoders: { [K in keyof T]: Decoder<T[K]> },
3✔
15
  f: (...args: T) => R | undefined,
3✔
16
): Decoder<R> {
3✔
17
  return (b, offset) => {
3✔
18
    const initial = mapDecoders(decoders, f)(b, offset)
1✔
19
    if (initial === undefined) return undefined
1!
20
    else {
1✔
21
      const [r, len] = initial
1✔
22
      return r !== undefined ? [r, len] : undefined
1!
23
    }
1✔
24
  }
1✔
25
}
3✔
26

27
export function mapDecoders<T extends unknown[], R>(
1✔
28
  decoders: { [K in keyof T]: Decoder<T[K]> },
3,443✔
29
  f: (...args: T) => R,
3,443✔
30
): Decoder<R> {
3,443✔
31
  return (b, offset) => {
3,443✔
32
    const result = decoders.reduce<
120,953✔
33
      | {
34
          values: unknown[]
35
          offset: number
36
          totalLength: number
37
        }
38
      | undefined
39
    >(
40
      (acc, decoder) => {
120,953✔
41
        if (!acc) return undefined
354,500✔
42

43
        const decoded = decoder(b, acc.offset)
354,498✔
44
        if (!decoded) return undefined
354,500✔
45

46
        const [value, length] = decoded
354,494✔
47
        return {
354,494✔
48
          values: [...acc.values, value],
354,494✔
49
          offset: acc.offset + length,
354,494✔
50
          totalLength: acc.totalLength + length,
354,494✔
51
        }
354,494✔
52
      },
354,500✔
53
      { values: [], offset, totalLength: 0 },
120,953✔
54
    )
120,953✔
55

56
    if (!result) return
120,953✔
57
    return [f(...(result.values as T)), result.totalLength]
120,949✔
58
  }
120,953✔
59
}
3,443✔
60

61
export function mapDecoderOption<T, U>(dec: Decoder<T>, f: (t: T) => U | undefined): Decoder<U> {
1✔
62
  return (b, offset) => {
48✔
63
    const x = dec(b, offset)
216,641✔
64
    if (x !== undefined) {
216,641✔
65
      const [t, l] = x
216,638✔
66
      const u = f(t)
216,638✔
67
      return u !== undefined ? [u, l] : undefined
216,638✔
68
    }
216,638✔
69
  }
216,641✔
70
}
48✔
71

72
export function flatMapDecoder<T, U>(dec: Decoder<T>, f: (t: T) => Decoder<U>): Decoder<U> {
1✔
73
  return flatMapDecoderAndMap(dec, f, (_t, u) => u)
45✔
74
}
45✔
75

76
export function orDecoder<T, U>(decT: Decoder<T>, decU: Decoder<U>): Decoder<T | U> {
1✔
77
  return (b, offset) => {
6✔
78
    const t = decT(b, offset)
6,493✔
79
    return t ? t : decU(b, offset)
6,493✔
80
  }
6,493✔
81
}
6✔
82

83
export function flatMapDecoderAndMap<T, U, V>(
1✔
84
  dec: Decoder<T>,
45✔
85
  f: (t: T) => Decoder<U>,
45✔
86
  g: (t: T, u: U) => V,
45✔
87
): Decoder<V> {
45✔
88
  return (b, offset) => {
45✔
89
    const decodedT = dec(b, offset)
42,766✔
90
    if (decodedT !== undefined) {
42,766✔
91
      const [t, len] = decodedT
42,744✔
92
      const decoderU = f(t)
42,744✔
93
      const decodedU = decoderU(b, offset + len)
42,744✔
94
      if (decodedU !== undefined) {
42,744✔
95
        const [u, len2] = decodedU
42,744✔
96
        return [g(t, u), len + len2]
42,744✔
97
      }
42,744✔
98
    }
42,744✔
99
  }
42,766✔
100
}
45✔
101

102
export function succeedDecoder<T>(t: T): Decoder<T> {
1✔
103
  return () => [t, 0] as const
2✔
104
}
2✔
105

106
export function failDecoder<T>(): Decoder<T> {
1✔
UNCOV
107
  return () => undefined
×
UNCOV
108
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc