Skip to content

Commit

Permalink
ref[python]: python protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 16, 2024
1 parent 8d343b3 commit 6cf26c1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions protocol/src/main/resources/python/ByteBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@ def adjustPadding(self, predictionLength, beforeWriteIndex):
def compatibleRead(self, beforeReadIndex, length):
return length != -1 and self.getReadOffset() < length + beforeReadIndex

def getBuffer(self):
return self.buffer

def getWriteOffset(self):
return self.writeOffset

def setWriteOffset(self, writeOffset):
if writeOffset > len(self.buffer):
raise ValueError("index out of bounds exception:readerIndex:" + str(self.readOffset) +
", writerIndex:" + str(self.writeOffset) +
"(expected:0 <= readerIndex <= writerIndex <= capacity:" + str(len(self.buffer)))
self.writeOffset = writeOffset
def setWriteOffset(self, writeIndex):
if writeIndex > len(self.buffer):
raise ValueError("writeIndex out of bounds exception:readOffset:" + str(self.readOffset) +
", writeOffset:" + str(self.writeOffset) +
"(expected:0 <= readOffset <= writeOffset <= capacity:" + str(len(self.buffer)))
self.writeOffset = writeIndex
pass

def getReadOffset(self):
return self.readOffset

def setReadOffset(self, readOffset):
if readOffset > self.writeOffset:
raise ValueError("index out of bounds exception:readerIndex:" + str(self.readOffset) +
", writerIndex:" + str(self.writeOffset) +
"(expected:0 <= readerIndex <= writerIndex <= capacity:" + str(len(self.buffer)))
self.readOffset = readOffset
def setReadOffset(self, readIndex):
if readIndex > self.writeOffset:
raise ValueError("readIndex out of bounds exception:readOffset:" + str(self.readOffset) +
", writeOffset:" + str(self.writeOffset) +
"(expected:0 <= readOffset <= writeOffset <= capacity:" + str(len(self.buffer)))
self.readOffset = readIndex
pass

def isReadable(self):
Expand Down Expand Up @@ -362,7 +365,7 @@ def readPacket(self, protocolId):
protocolRegistration = ProtocolManager.getProtocol(protocolId)
return protocolRegistration.read(self)

def writeBooleanArray(self, array):
def writeBoolArray(self, array):
if array is None:
self.writeInt(0)
else:
Expand All @@ -371,7 +374,7 @@ def writeBooleanArray(self, array):
self.writeBool(element)
pass

def readBooleanArray(self):
def readBoolArray(self):
array = []
size = self.readInt()
if size > 0:
Expand Down Expand Up @@ -755,7 +758,7 @@ def readStringPacketMap(self, protocolId):
map[key] = value
return map

def writeBooleanSet(self, value):
def writeBoolSet(self, value):
if value is None:
self.writeInt(0)
else:
Expand All @@ -764,7 +767,7 @@ def writeBooleanSet(self, value):
self.writeBool(element)
pass

def readBooleanSet(self):
def readBoolSet(self):
value = set()
size = self.readInt()
if size > 0:
Expand Down

0 comments on commit 6cf26c1

Please sign in to comment.