MCPcopy Create free account
hub / github.com/apache/fory / replaceFirstBytes

Function replaceFirstBytes

javascript/test/typemeta.test.ts:80–101  ·  view source on GitHub ↗
(
  bytes: Uint8Array,
  search: Uint8Array,
  replacement: Uint8Array,
)

Source from the content-addressed store, hash-verified

78}
79
80function 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
103describe("typemeta", () => {
104 test("splits dotted names", () => {

Callers 1

typemeta.test.tsFile · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected