mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 14:20:24 +08:00
Add length param
This commit is contained in:
parent
db4954bae1
commit
c378dcb0f4
@ -754,8 +754,8 @@ class Jce private constructor(private val charset: JceCharset, context: SerialMo
|
||||
return dumpAsPacket(serializer, obj).readBytes()
|
||||
}
|
||||
|
||||
fun <T> load(deserializer: DeserializationStrategy<T>, packet: ByteReadPacket): T {
|
||||
packet.readIoBuffer().withUse {
|
||||
fun <T> load(deserializer: DeserializationStrategy<T>, packet: ByteReadPacket, length: Int = packet.remaining.toInt()): T {
|
||||
packet.readIoBuffer(n = length).withUse {
|
||||
val decoder = JceDecoder(JceInput(this))
|
||||
return decoder.decode(deserializer)
|
||||
}
|
||||
|
@ -22,8 +22,12 @@ fun <T : JceStruct> BytePacketBuilder.writeJceStruct(serializer: SerializationSt
|
||||
this.writePacket(Jce.byCharSet(charset).dumpAsPacket(serializer, struct))
|
||||
}
|
||||
|
||||
fun <T : JceStruct> ByteReadPacket.readRemainingAsJceStruct(serializer: DeserializationStrategy<T>, charset: JceCharset = JceCharset.UTF8): T {
|
||||
return Jce.byCharSet(charset).load(serializer, this)
|
||||
fun <T : JceStruct> ByteReadPacket.readRemainingAsJceStruct(
|
||||
serializer: DeserializationStrategy<T>,
|
||||
charset: JceCharset = JceCharset.UTF8,
|
||||
length: Int = this.remaining.toInt()
|
||||
): T {
|
||||
return Jce.byCharSet(charset).load(serializer, this, length)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +37,7 @@ fun <T : JceStruct> ByteReadPacket.decodeUniPacket(deserializer: Deserialization
|
||||
return decodeUniRequestPacketAndDeserialize(name) {
|
||||
it.read {
|
||||
discardExact(1)
|
||||
this.readRemainingAsJceStruct(deserializer)
|
||||
this.readRemainingAsJceStruct(deserializer, length = (this.remaining - 1).toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,7 +49,7 @@ fun <T : ProtoBuf> ByteReadPacket.decodeUniPacket(deserializer: DeserializationS
|
||||
return decodeUniRequestPacketAndDeserialize(name) {
|
||||
it.read {
|
||||
discardExact(1)
|
||||
this.readRemainingAsProtoBuf(deserializer)
|
||||
this.readRemainingAsProtoBuf(deserializer, (this.remaining - 1).toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,8 +93,8 @@ fun <T : ProtoBuf> ByteArray.loadAs(deserializer: DeserializationStrategy<T>): T
|
||||
/**
|
||||
* load
|
||||
*/
|
||||
fun <T : ProtoBuf> Input.readRemainingAsProtoBuf(serializer: DeserializationStrategy<T>): T {
|
||||
return ProtoBufWithNullableSupport.load(serializer, this.readBytes())
|
||||
fun <T : ProtoBuf> ByteReadPacket.readRemainingAsProtoBuf(serializer: DeserializationStrategy<T>, length: Int = this.remaining.toInt()): T {
|
||||
return ProtoBufWithNullableSupport.load(serializer, this.readBytes(length))
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user