MCPcopy
hub / github.com/lowlighter/metrics / encodeNumber

Method encodeNumber

source/plugins/community/splatoon/s3si/index.ts:2429–2473  ·  view source on GitHub ↗
(object)

Source from the content-addressed store, hash-verified

2427 }
2428 }
2429 encodeNumber(object) {
2430 if (Number.isSafeInteger(object)) {
2431 if (object >= 0) {
2432 if (object < 0x80) {
2433 this.writeU8(object);
2434 } else if (object < 0x100) {
2435 this.writeU8(0xcc);
2436 this.writeU8(object);
2437 } else if (object < 0x10000) {
2438 this.writeU8(0xcd);
2439 this.writeU16(object);
2440 } else if (object < 0x100000000) {
2441 this.writeU8(0xce);
2442 this.writeU32(object);
2443 } else {
2444 this.writeU8(0xcf);
2445 this.writeU64(object);
2446 }
2447 } else {
2448 if (object >= -0x20) {
2449 this.writeU8(0xe0 | object + 0x20);
2450 } else if (object >= -0x80) {
2451 this.writeU8(0xd0);
2452 this.writeI8(object);
2453 } else if (object >= -0x8000) {
2454 this.writeU8(0xd1);
2455 this.writeI16(object);
2456 } else if (object >= -0x80000000) {
2457 this.writeU8(0xd2);
2458 this.writeI32(object);
2459 } else {
2460 this.writeU8(0xd3);
2461 this.writeI64(object);
2462 }
2463 }
2464 } else {
2465 if (this.forceFloat32) {
2466 this.writeU8(0xca);
2467 this.writeF32(object);
2468 } else {
2469 this.writeU8(0xcb);
2470 this.writeF64(object);
2471 }
2472 }
2473 }
2474 writeStringHeader(byteLength) {
2475 if (byteLength < 32) {
2476 this.writeU8(0xa0 + byteLength);

Callers 1

doEncodeMethod · 0.95

Calls 10

writeU8Method · 0.95
writeU16Method · 0.95
writeU32Method · 0.95
writeU64Method · 0.95
writeI8Method · 0.95
writeI16Method · 0.95
writeI32Method · 0.95
writeI64Method · 0.95
writeF32Method · 0.95
writeF64Method · 0.95

Tested by

no test coverage detected