| 78 | } |
| 79 | |
| 80 | function replaceFirstBytes( |
| 81 | bytes: Uint8Array, |
| 82 | search: Uint8Array, |
| 83 | replacement: Uint8Array, |
| 84 | ): Uint8Array { |
| 85 | expect(search.length).toBe(replacement.length); |
| 86 | const result = new Uint8Array(bytes); |
| 87 | for (let i = 0; i <= result.length - search.length; i++) { |
| 88 | let matched = true; |
| 89 | for (let j = 0; j < search.length; j++) { |
| 90 | if (result[i + j] !== search[j]) { |
| 91 | matched = false; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | if (matched) { |
| 96 | result.set(replacement, i); |
| 97 | return result; |
| 98 | } |
| 99 | } |
| 100 | throw new Error("bytes not found"); |
| 101 | } |
| 102 | |
| 103 | describe("typemeta", () => { |
| 104 | test("splits dotted names", () => { |