|
1 |
| -const ProtocolManager = preload("./ProtocolManager.gd") |
| 1 | +class_name ByteBuffer |
2 | 2 |
|
3 | 3 | const EMPTY: String = ""
|
4 | 4 |
|
@@ -71,9 +71,6 @@ func isReadable() -> bool:
|
71 | 71 | func toBytes() -> PackedByteArray:
|
72 | 72 | return buffer.data_array.slice(0, writeOffset)
|
73 | 73 |
|
74 |
| -func newInstance(protocolId: int) -> Object: |
75 |
| - return ProtocolManager.newInstance(protocolId) |
76 |
| - |
77 | 74 | # -------------------------------------------------write/read-------------------------------------------------
|
78 | 75 | func writeBytes(value: PackedByteArray):
|
79 | 76 | var length: int = value.size()
|
@@ -304,14 +301,12 @@ func readString() -> String:
|
304 | 301 | readOffset += length
|
305 | 302 | return value
|
306 | 303 |
|
307 |
| -func writePacket(packet, protocolId): |
308 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
309 |
| - protocolRegistration.write(self, packet) |
| 304 | +func writePacket(packet: Object, protocol: Object): |
| 305 | + protocol.write(self, packet) |
310 | 306 | pass
|
311 | 307 |
|
312 |
| -func readPacket(protocolId) -> Object: |
313 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
314 |
| - return protocolRegistration.read(self) |
| 308 | +func readPacket(protocol: Object) -> Object: |
| 309 | + return protocol.read(self) |
315 | 310 |
|
316 | 311 | func writeBoolArray(array):
|
317 | 312 | if (array == null):
|
@@ -449,24 +444,21 @@ func readStringArray() -> Array[String]:
|
449 | 444 | array.append(readString())
|
450 | 445 | return array
|
451 | 446 |
|
452 |
| -func writePacketArray(array, protocolId): |
| 447 | +func writePacketArray(array: Array, protocol: Object): |
453 | 448 | if (array == null):
|
454 | 449 | writeInt(0)
|
455 | 450 | else:
|
456 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
457 | 451 | writeInt(array.size())
|
458 | 452 | for element in array:
|
459 |
| - protocolRegistration.write(self, element) |
| 453 | + protocol.write(self, element) |
460 | 454 | pass
|
461 | 455 |
|
462 |
| -func readPacketArray(protocolId) -> Array: |
463 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
464 |
| - var protocol = ProtocolManager.getProtocolClass(protocolId) |
| 456 | +func readPacketArray(protocol: Object) -> Array: |
465 | 457 | var array = Array([], typeof(protocol), StringName("RefCounted"), protocol)
|
466 | 458 | var size = readInt()
|
467 | 459 | if (size > 0):
|
468 | 460 | for index in range(size):
|
469 |
| - array.append(protocolRegistration.read(self)) |
| 461 | + array.append(protocol.read(self)) |
470 | 462 | #var a = array.get_typed_class_name()
|
471 | 463 | #var b = array.get_typed_script()
|
472 | 464 | #var c = array.get_typed_builtin()
|
@@ -537,26 +529,23 @@ func readIntStringMap() -> Dictionary[int, String]:
|
537 | 529 | map[key] = value
|
538 | 530 | return map
|
539 | 531 |
|
540 |
| -func writeIntPacketMap(map, protocolId): |
| 532 | +func writeIntPacketMap(map: Dictionary, protocol: Object): |
541 | 533 | if (map == null):
|
542 | 534 | writeInt(0)
|
543 | 535 | else:
|
544 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
545 | 536 | writeInt(map.size())
|
546 | 537 | for key in map:
|
547 | 538 | writeInt(key)
|
548 |
| - protocolRegistration.write(self, map[key]) |
| 539 | + protocol.write(self, map[key]) |
549 | 540 | pass
|
550 | 541 |
|
551 |
| -func readIntPacketMap(protocolId) -> Dictionary: |
552 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
553 |
| - var protocol = ProtocolManager.getProtocolClass(protocolId) |
| 542 | +func readIntPacketMap(protocol: Object) -> Dictionary: |
554 | 543 | var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
555 | 544 | var size = readInt()
|
556 | 545 | if (size > 0):
|
557 | 546 | for index in range(size):
|
558 | 547 | var key = readInt()
|
559 |
| - var value = protocolRegistration.read(self) |
| 548 | + var value = protocol.read(self) |
560 | 549 | map[key] = value
|
561 | 550 | return map
|
562 | 551 |
|
@@ -620,26 +609,23 @@ func readLongStringMap() -> Dictionary[int, String]:
|
620 | 609 | map[key] = value
|
621 | 610 | return map
|
622 | 611 |
|
623 |
| -func writeLongPacketMap(map, protocolId): |
| 612 | +func writeLongPacketMap(map: Dictionary, protocol: Object): |
624 | 613 | if (map == null):
|
625 | 614 | writeInt(0)
|
626 | 615 | else:
|
627 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
628 | 616 | writeInt(map.size())
|
629 | 617 | for key in map:
|
630 | 618 | writeLong(key)
|
631 |
| - protocolRegistration.write(self, map[key]) |
| 619 | + protocol.write(self, map[key]) |
632 | 620 | pass
|
633 | 621 |
|
634 |
| -func readLongPacketMap(protocolId) -> Dictionary: |
635 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
636 |
| - var protocol = ProtocolManager.getProtocolClass(protocolId) |
| 622 | +func readLongPacketMap(protocol: Object) -> Dictionary: |
637 | 623 | var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
638 | 624 | var size = readInt()
|
639 | 625 | if (size > 0):
|
640 | 626 | for index in range(size):
|
641 | 627 | var key = readLong()
|
642 |
| - var value = protocolRegistration.read(self) |
| 628 | + var value = protocol.read(self) |
643 | 629 | map[key] = value
|
644 | 630 | return map
|
645 | 631 |
|
@@ -703,25 +689,22 @@ func readStringStringMap() -> Dictionary[String, String]:
|
703 | 689 | map[key] = value
|
704 | 690 | return map
|
705 | 691 |
|
706 |
| -func writeStringPacketMap(map, protocolId): |
| 692 | +func writeStringPacketMap(map: Dictionary, protocol: Object): |
707 | 693 | if (map == null):
|
708 | 694 | writeInt(0)
|
709 | 695 | else:
|
710 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
711 | 696 | writeInt(map.size())
|
712 | 697 | for key in map:
|
713 | 698 | writeString(key)
|
714 |
| - protocolRegistration.write(self, map[key]) |
| 699 | + protocol.write(self, map[key]) |
715 | 700 | pass
|
716 | 701 |
|
717 |
| -func readStringPacketMap(protocolId) -> Dictionary: |
718 |
| - var protocolRegistration = ProtocolManager.getProtocol(protocolId) |
719 |
| - var protocol = ProtocolManager.getProtocolClass(protocolId) |
| 702 | +func readStringPacketMap(protocol: Object) -> Dictionary: |
720 | 703 | var map = Dictionary({}, TYPE_STRING, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
721 | 704 | var size = readInt()
|
722 | 705 | if (size > 0):
|
723 | 706 | for index in range(size):
|
724 | 707 | var key = readString()
|
725 |
| - var value = protocolRegistration.read(self) |
| 708 | + var value = protocol.read(self) |
726 | 709 | map[key] = value
|
727 | 710 | return map
|
0 commit comments