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

LukaJCB / ts-mls / 20979592964

14 Jan 2026 02:00AM UTC coverage: 95.626% (-0.03%) from 95.658%
20979592964

Pull #214

github

web-flow
Merge df6cc819b into 6455ce4ec
Pull Request #214: Rename decodeX to xDecoder

412 of 419 branches covered (98.33%)

Branch coverage included in aggregate %.

165 of 169 new or added lines in 50 files covered. (97.63%)

3 existing lines in 2 files now uncovered.

2277 of 2393 relevant lines covered (95.15%)

73672.72 hits per line

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

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

4
/** @public */
5
export function decode<T>(dec: Decoder<T>, t: Uint8Array): T | undefined {
NEW
6
  return dec(t, 0)?.[0]
×
7
}
8

9
export function mapDecoder<T, U>(dec: Decoder<T>, f: (t: T) => U): Decoder<U> {
10
  return (b, offset) => {
23,217✔
11
    const x = dec(b, offset)
45,817✔
12
    if (x !== undefined) {
45,817✔
13
      const [t, l] = x
45,817✔
14
      return [f(t), l]
45,817✔
15
    }
16
  }
17
}
18

19
export function mapDecodersOption<T extends unknown[], R>(
20
  rsDecoder: { [K in keyof T]: Decoder<T[K]> },
21
  f: (...args: T) => R | undefined,
22
): Decoder<R> {
23
  return (b, offset) => {
3✔
24
    const initial = mapDecoders(rsDecoder, f)(b, offset)
1✔
25
    if (initial === undefined) return undefined
1✔
26
    else {
27
      const [r, len] = initial
1✔
28
      return r !== undefined ? [r, len] : undefined
1✔
29
    }
30
  }
31
}
32

33
export function mapDecoders<T extends unknown[], R>(
34
  rsDecoder: { [K in keyof T]: Decoder<T[K]> },
35
  f: (...args: T) => R,
36
): Decoder<R> {
37
  return (b, offset) => {
3,452✔
38
    const result = rsDecoder.reduce<
122,267✔
39
      | {
40
          values: unknown[]
41
          offset: number
42
          totalLength: number
43
        }
44
      | undefined
45
    >(
46
      (acc, decoder) => {
47
        if (!acc) return undefined
359,263✔
48

49
        const decoded = decoder(b, acc.offset)
359,261✔
50
        if (!decoded) return undefined
359,261✔
51

52
        const [value, length] = decoded
359,257✔
53
        return {
359,257✔
54
          values: [...acc.values, value],
55
          offset: acc.offset + length,
56
          totalLength: acc.totalLength + length,
57
        }
58
      },
59
      { values: [], offset, totalLength: 0 },
60
    )
61

62
    if (!result) return
122,267✔
63
    return [f(...(result.values as T)), result.totalLength]
122,263✔
64
  }
65
}
66

67
export function mapDecoderOption<T, U>(dec: Decoder<T>, f: (t: T) => U | undefined): Decoder<U> {
68
  return (b, offset) => {
39✔
69
    const x = dec(b, offset)
66,663✔
70
    if (x !== undefined) {
66,663✔
71
      const [t, l] = x
66,663✔
72
      const u = f(t)
66,663✔
73
      return u !== undefined ? [u, l] : undefined
66,663✔
74
    }
75
  }
76
}
77

78
export function flatMapDecoder<T, U>(dec: Decoder<T>, f: (t: T) => Decoder<U>): Decoder<U> {
79
  return flatMapDecoderAndMap(dec, f, (_t, u) => u)
7,167✔
80
}
81

82
export function orDecoder<T, U>(decT: Decoder<T>, decU: Decoder<U>): Decoder<T | U> {
83
  return (b, offset) => {
3✔
84
    const t = decT(b, offset)
4,764✔
85
    return t ? t : decU(b, offset)
4,764✔
86
  }
87
}
88

89
function flatMapDecoderAndMap<T, U, V>(dec: Decoder<T>, f: (t: T) => Decoder<U>, g: (t: T, u: U) => V): Decoder<V> {
90
  return (b, offset) => {
42✔
91
    const decodedT = dec(b, offset)
43,039✔
92
    if (decodedT !== undefined) {
43,039✔
93
      const [t, len] = decodedT
42,998✔
94
      const rUDecoder = f(t)
42,998✔
95
      const decodedU = rUDecoder(b, offset + len)
42,998✔
96
      if (decodedU !== undefined) {
42,998✔
97
        const [u, len2] = decodedU
42,998✔
98
        return [g(t, u), len + len2]
42,998✔
99
      }
100
    }
101
  }
102
}
103

104
export function succeedDecoder<T>(t: T): Decoder<T> {
105
  return () => [t, 0] as const
41✔
106
}
107

108
export function failDecoder<T>(): Decoder<T> {
109
  return () => undefined
×
110
}
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