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

LukaJCB / ts-mls / 20546274682

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

Pull #181

github

web-flow
Merge ba9453640 into 52bc104fb
Pull Request #181: Add group state codec using tls binary format

1239 of 1388 branches covered (89.27%)

Branch coverage included in aggregate %.

325 of 343 new or added lines in 12 files covered. (94.75%)

17 existing lines in 1 file now uncovered.

7162 of 7352 relevant lines covered (97.42%)

42350.34 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) => {
15,908✔
5
    const x = dec(b, offset)
49,552✔
6
    if (x !== undefined) {
49,552✔
7
      const [t, l] = x
49,552✔
8
      return [f(t), l]
49,552✔
9
    }
49,552✔
10
  }
49,552✔
11
}
15,908✔
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]> },
2,177✔
29
  f: (...args: T) => R,
2,177✔
30
): Decoder<R> {
2,177✔
31
  return (b, offset) => {
2,177✔
32
    const result = decoders.reduce<
121,043✔
33
      | {
34
          values: unknown[]
35
          offset: number
36
          totalLength: number
37
        }
38
      | undefined
39
    >(
40
      (acc, decoder) => {
121,043✔
41
        if (!acc) return undefined
354,680✔
42

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

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

56
    if (!result) return
121,043✔
57
    return [f(...(result.values as T)), result.totalLength]
121,039✔
58
  }
121,043✔
59
}
2,177✔
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,244✔
64
    if (x !== undefined) {
216,244✔
65
      const [t, l] = x
216,241✔
66
      const u = f(t)
216,241✔
67
      return u !== undefined ? [u, l] : undefined
216,241✔
68
    }
216,241✔
69
  }
216,244✔
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)
37,983✔
90
    if (decodedT !== undefined) {
37,983✔
91
      const [t, len] = decodedT
37,961✔
92
      const decoderU = f(t)
37,961✔
93
      const decodedU = decoderU(b, offset + len)
37,961✔
94
      if (decodedU !== undefined) {
37,961✔
95
        const [u, len2] = decodedU
37,961✔
96
        return [g(t, u), len + len2]
37,961✔
97
      }
37,961✔
98
    }
37,961✔
99
  }
37,983✔
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✔
NEW
107
  return () => undefined
×
NEW
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