Skip to content

Commit 588de01

Browse files
committed
test[protocol]: gdscript protocol test
1 parent 53d9752 commit 588de01

File tree

10 files changed

+125
-132
lines changed

10 files changed

+125
-132
lines changed

protocol/src/main/resources/gdscript/ByteBuffer.gd

+34-34
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var readOffset: int = 0
1313
func _init():
1414
buffer.big_endian = true
1515

16-
func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
16+
func adjustPadding(predictionLength: int, beforeWriteIndex: int):
1717
var currentWriteIndex = writeOffset
1818
var predictionCount = writeIntCount(predictionLength)
1919
var length = currentWriteIndex - beforeWriteIndex - predictionCount
@@ -24,7 +24,7 @@ func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
2424
writeInt(length)
2525
setWriteOffset(currentWriteIndex)
2626
else:
27-
# get_partial_data of StreamPeerBuffer is deep clone
27+
# get_partial_data of StreamPeerBuffer is deep clone
2828
buffer.seek(currentWriteIndex - length)
2929
var retainedByteBuf = buffer.get_partial_data(length)[1]
3030
setWriteOffset(beforeWriteIndex)
@@ -43,7 +43,7 @@ func compatibleRead(beforeReadIndex: int, length: int) -> bool:
4343
func getBuffer() -> StreamPeerBuffer:
4444
return buffer
4545

46-
func setWriteOffset(writeIndex: int) -> void:
46+
func setWriteOffset(writeIndex: int):
4747
if (writeIndex > buffer.get_size()):
4848
var template = "writeIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
4949
printerr(template.format([writeIndex, readOffset, writeOffset, buffer.get_size()], "{}"))
@@ -54,7 +54,7 @@ func setWriteOffset(writeIndex: int) -> void:
5454
func getWriteOffset() -> int:
5555
return writeOffset
5656

57-
func setReadOffset(readIndex: int) -> void:
57+
func setReadOffset(readIndex: int):
5858
if (readIndex > writeOffset):
5959
var template = "readIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
6060
printerr(template.format([readIndex, readOffset, writeOffset, buffer.size()], "{}"))
@@ -71,7 +71,7 @@ func isReadable() -> bool:
7171
func toBytes() -> PackedByteArray:
7272
return buffer.data_array.slice(0, writeOffset)
7373

74-
func newInstance(protocolId: int):
74+
func newInstance(protocolId: int) -> Object:
7575
return ProtocolManager.newInstance(protocolId)
7676

7777
# -------------------------------------------------write/read-------------------------------------------------
@@ -84,7 +84,7 @@ func writeBytes(value: PackedByteArray):
8484
func readBytes(length: int) -> PackedByteArray:
8585
return buffer.data_array.slice(0, length)
8686

87-
func writeBool(value: bool) -> void:
87+
func writeBool(value: bool):
8888
var byte: int = 1 if value else 0
8989
buffer.seek(writeOffset)
9090
buffer.put_8(byte)
@@ -97,7 +97,7 @@ func readBool() -> bool:
9797
readOffset += 1
9898
return byte == 1
9999

100-
func writeByte(value: int) -> void:
100+
func writeByte(value: int):
101101
buffer.seek(writeOffset)
102102
buffer.put_8(value)
103103
writeOffset += 1
@@ -109,7 +109,7 @@ func readByte() -> int:
109109
readOffset += 1
110110
return value
111111

112-
func writeShort(value: int) -> void:
112+
func writeShort(value: int):
113113
buffer.seek(writeOffset)
114114
buffer.put_16(value)
115115
writeOffset += 2
@@ -121,7 +121,7 @@ func readShort() -> int:
121121
readOffset += 2
122122
return value
123123

124-
func writeRawInt(value) -> void:
124+
func writeRawInt(value):
125125
buffer.seek(writeOffset)
126126
buffer.put_32(value)
127127
writeOffset += 4
@@ -133,7 +133,7 @@ func readRawInt() -> int:
133133
readOffset += 4
134134
return value
135135

136-
func writeInt(value) -> void:
136+
func writeInt(value):
137137
if !(minInt <= value && value <= maxInt):
138138
printerr("value must range between minInt:-2147483648 and maxInt:2147483647")
139139
return
@@ -158,7 +158,7 @@ func writeIntCount(value: int) -> int:
158158
func readInt() -> int:
159159
return readLong()
160160

161-
func writeLong(longValue: int) -> void:
161+
func writeLong(longValue: int):
162162
var value: int = (longValue << 1) ^ (longValue >> 63)
163163

164164
if (value >> 7 == 0):
@@ -257,7 +257,7 @@ func readLong() -> int:
257257
return mask ^ -(value & 1)
258258

259259

260-
func writeFloat(value: float) -> void:
260+
func writeFloat(value: float):
261261
buffer.seek(writeOffset)
262262
buffer.put_float(value)
263263
writeOffset += 4
@@ -269,7 +269,7 @@ func readFloat() -> float:
269269
readOffset += 4
270270
return value
271271

272-
func writeDouble(value: float) -> void:
272+
func writeDouble(value: float):
273273
buffer.seek(writeOffset)
274274
buffer.put_double(value)
275275
writeOffset += 8
@@ -282,7 +282,7 @@ func readDouble() -> float:
282282
return value
283283

284284

285-
func writeString(value: String) -> void:
285+
func writeString(value: String):
286286
if (value == null || value.length() ==0):
287287
writeInt(0)
288288
return
@@ -309,7 +309,7 @@ func writePacket(packet, protocolId):
309309
protocolRegistration.write(self, packet)
310310
pass
311311

312-
func readPacket(protocolId):
312+
func readPacket(protocolId) -> Object:
313313
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
314314
return protocolRegistration.read(self)
315315

@@ -356,7 +356,7 @@ func writeShortArray(array):
356356
writeShort(element)
357357
pass
358358

359-
func readShortArray():
359+
func readShortArray() -> Array[int]:
360360
var array: Array[int] = []
361361
var size = readInt()
362362
if (size > 0):
@@ -373,7 +373,7 @@ func writeIntArray(array):
373373
writeInt(element)
374374
pass
375375

376-
func readIntArray():
376+
func readIntArray() -> Array[int]:
377377
var array: Array[int] = []
378378
var size = readInt()
379379
if (size > 0):
@@ -390,7 +390,7 @@ func writeLongArray(array):
390390
writeLong(element)
391391
pass
392392

393-
func readLongArray():
393+
func readLongArray() -> Array[int]:
394394
var array: Array[int] = []
395395
var size = readInt()
396396
if (size > 0):
@@ -407,7 +407,7 @@ func writeFloatArray(array):
407407
writeFloat(element)
408408
pass
409409

410-
func readFloatArray():
410+
func readFloatArray() -> Array[float]:
411411
var array: Array[float] = []
412412
var size = readInt()
413413
if (size > 0):
@@ -424,7 +424,7 @@ func writeDoubleArray(array):
424424
writeDouble(element)
425425
pass
426426

427-
func readDoubleArray():
427+
func readDoubleArray() -> Array[float]:
428428
var array: Array[float] = []
429429
var size = readInt()
430430
if (size > 0):
@@ -441,7 +441,7 @@ func writeStringArray(array):
441441
writeString(element)
442442
pass
443443

444-
func readStringArray():
444+
func readStringArray() -> Array[String]:
445445
var array: Array[String] = []
446446
var size = readInt()
447447
if (size > 0):
@@ -459,7 +459,7 @@ func writePacketArray(array, protocolId):
459459
protocolRegistration.write(self, element)
460460
pass
461461

462-
func readPacketArray(protocolId):
462+
func readPacketArray(protocolId) -> Array:
463463
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
464464
var protocol = ProtocolManager.getProtocolClass(protocolId)
465465
var array = Array([], typeof(protocol), StringName("RefCounted"), protocol)
@@ -487,7 +487,7 @@ func writeIntIntMap(map):
487487
writeInt(map[key])
488488
pass
489489

490-
func readIntIntMap():
490+
func readIntIntMap() -> Dictionary[int, int]:
491491
var map: Dictionary[int, int] = {}
492492
var size = readInt()
493493
if (size > 0):
@@ -507,7 +507,7 @@ func writeIntLongMap(map):
507507
writeLong(map[key])
508508
pass
509509

510-
func readIntLongMap():
510+
func readIntLongMap() -> Dictionary[int, int]:
511511
var map: Dictionary[int, int] = {}
512512
var size = readInt()
513513
if (size > 0):
@@ -527,7 +527,7 @@ func writeIntStringMap(map):
527527
writeString(map[key])
528528
pass
529529

530-
func readIntStringMap():
530+
func readIntStringMap() -> Dictionary[int, String]:
531531
var map: Dictionary[int, String] = {}
532532
var size = readInt()
533533
if (size > 0):
@@ -548,7 +548,7 @@ func writeIntPacketMap(map, protocolId):
548548
protocolRegistration.write(self, map[key])
549549
pass
550550

551-
func readIntPacketMap(protocolId):
551+
func readIntPacketMap(protocolId) -> Dictionary:
552552
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
553553
var protocol = ProtocolManager.getProtocolClass(protocolId)
554554
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
@@ -570,7 +570,7 @@ func writeLongIntMap(map):
570570
writeInt(map[key])
571571
pass
572572

573-
func readLongIntMap():
573+
func readLongIntMap() -> Dictionary[int, int]:
574574
var map: Dictionary[int, int] = {}
575575
var size = readInt()
576576
if (size > 0):
@@ -590,7 +590,7 @@ func writeLongLongMap(map):
590590
writeLong(map[key])
591591
pass
592592

593-
func readLongLongMap():
593+
func readLongLongMap() -> Dictionary[int, int]:
594594
var map: Dictionary[int, int] = {}
595595
var size = readInt()
596596
if (size > 0):
@@ -610,7 +610,7 @@ func writeLongStringMap(map):
610610
writeString(map[key])
611611
pass
612612

613-
func readLongStringMap():
613+
func readLongStringMap() -> Dictionary[int, String]:
614614
var map: Dictionary[int, String] = {}
615615
var size = readInt()
616616
if (size > 0):
@@ -631,7 +631,7 @@ func writeLongPacketMap(map, protocolId):
631631
protocolRegistration.write(self, map[key])
632632
pass
633633

634-
func readLongPacketMap(protocolId):
634+
func readLongPacketMap(protocolId) -> Dictionary:
635635
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
636636
var protocol = ProtocolManager.getProtocolClass(protocolId)
637637
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
@@ -653,7 +653,7 @@ func writeStringIntMap(map):
653653
writeInt(map[key])
654654
pass
655655

656-
func readStringIntMap():
656+
func readStringIntMap() -> Dictionary[String, String]:
657657
var map: Dictionary[String, String] = {}
658658
var size = readInt()
659659
if (size > 0):
@@ -673,7 +673,7 @@ func writeStringLongMap(map):
673673
writeLong(map[key])
674674
pass
675675

676-
func readStringLongMap():
676+
func readStringLongMap() -> Dictionary[String, int]:
677677
var map: Dictionary[String, int] = {}
678678
var size = readInt()
679679
if (size > 0):
@@ -693,7 +693,7 @@ func writeStringStringMap(map):
693693
writeString(map[key])
694694
pass
695695

696-
func readStringStringMap():
696+
func readStringStringMap() -> Dictionary[String, String]:
697697
var map: Dictionary[String, String] = {}
698698
var size = readInt()
699699
if (size > 0):
@@ -714,7 +714,7 @@ func writeStringPacketMap(map, protocolId):
714714
protocolRegistration.write(self, map[key])
715715
pass
716716

717-
func readStringPacketMap(protocolId):
717+
func readStringPacketMap(protocolId) -> Dictionary:
718718
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
719719
var protocol = ProtocolManager.getProtocolClass(protocolId)
720720
var map = Dictionary({}, TYPE_STRING, "", null, typeof(protocol), StringName("RefCounted"), protocol)

0 commit comments

Comments
 (0)