MCPcopy Create free account
hub / github.com/esengine/esengine / loadPackage

Method loadPackage

packages/fairygui/src/package/UIPackage.ts:270–510  ·  view source on GitHub ↗

* Load package from buffer * 从缓冲区加载包

(buffer: ByteBuffer)

Source from the content-addressed store, hash-verified

268 * 从缓冲区加载包
269 */
270 private loadPackage(buffer: ByteBuffer): void {
271 if (buffer.getUint32() !== PACKAGE_MAGIC) {
272 throw new Error('FairyGUI: invalid package format in \'' + this._resKey + '\'');
273 }
274
275 buffer.version = buffer.getInt32();
276 const compressed = buffer.readBool();
277 this.id = buffer.readUTFString();
278 this.name = buffer.readUTFString();
279 buffer.skip(20);
280
281 // Handle compressed data
282 if (compressed) {
283 // Note: Compression requires pako or similar library
284 // For now, we'll throw an error if the package is compressed
285 throw new Error('FairyGUI: compressed packages are not supported yet');
286 }
287
288 const ver2 = buffer.version >= 2;
289 const indexTablePos = buffer.pos;
290
291 // Read string table
292 buffer.seek(indexTablePos, 4);
293 const strCount = buffer.getInt32();
294 const stringTable: string[] = [];
295 for (let i = 0; i < strCount; i++) {
296 stringTable[i] = buffer.readUTFString();
297 }
298 buffer.stringTable = stringTable;
299
300 // Read custom strings (version 2+)
301 if (buffer.seek(indexTablePos, 5)) {
302 const customCount = buffer.readInt32();
303 for (let i = 0; i < customCount; i++) {
304 const index = buffer.readUint16();
305 const len = buffer.readInt32();
306 stringTable[index] = buffer.getCustomString(len);
307 }
308 }
309
310 // Read dependencies
311 buffer.seek(indexTablePos, 0);
312 const depCount = buffer.getInt16();
313 for (let i = 0; i < depCount; i++) {
314 this._dependencies.push({
315 id: buffer.readS(),
316 name: buffer.readS()
317 });
318 }
319
320 // Read branches (version 2+)
321 let branchIncluded = false;
322 if (ver2) {
323 const branchCount = buffer.getInt16();
324 if (branchCount > 0) {
325 this._branches = buffer.readSArray(branchCount);
326 if (UIPackage._branch) {
327 this._branchIndex = this._branches.indexOf(UIPackage._branch);

Callers 1

addPackageFromBufferMethod · 0.95

Calls 15

getUint32Method · 0.80
getInt32Method · 0.80
readBoolMethod · 0.80
readUTFStringMethod · 0.80
skipMethod · 0.80
readInt32Method · 0.80
readUint16Method · 0.80
getCustomStringMethod · 0.80
getInt16Method · 0.80
readSMethod · 0.80
readSArrayMethod · 0.80
getUint16Method · 0.80

Tested by

no test coverage detected