(headers: Record<string, string>)
| 15 | // aimock's builder nests the payload one level too deep (contentBlockDelta inside contentBlockDelta), |
| 16 | // causing the AWS SDK deserializer's take() to miss the delta field entirely. |
| 17 | function encodeHeaders(headers: Record<string, string>): Buffer { |
| 18 | const parts: Buffer[] = [] |
| 19 | for (const [name, value] of Object.entries(headers)) { |
| 20 | const nameBytes = Buffer.from(name, "utf8") |
| 21 | const valueBytes = Buffer.from(value, "utf8") |
| 22 | const buf = Buffer.alloc(1 + nameBytes.length + 1 + 2 + valueBytes.length) |
| 23 | let off = 0 |
| 24 | buf.writeUInt8(nameBytes.length, off) |
| 25 | off += 1 |
| 26 | nameBytes.copy(buf, off) |
| 27 | off += nameBytes.length |
| 28 | buf.writeUInt8(7, off) |
| 29 | off += 1 // type 7 = string |
| 30 | buf.writeUInt16BE(valueBytes.length, off) |
| 31 | off += 2 |
| 32 | valueBytes.copy(buf, off) |
| 33 | parts.push(buf) |
| 34 | } |
| 35 | return Buffer.concat(parts) |
| 36 | } |
| 37 | |
| 38 | function encodeFrame(eventType: string, payload: object): Buffer { |
| 39 | const hdrs = encodeHeaders({ |
no test coverage detected