@@ -91,6 +91,11 @@ internal fun ObjectMessage.writeMsgpack(packer: MessagePacker) {
9191 * Read an ObjectMessage from MessageUnpacker
9292 */
9393internal fun readObjectMessage (unpacker : MessageUnpacker ): ObjectMessage {
94+ if (unpacker.nextFormat == MessageFormat .NIL ) {
95+ unpacker.unpackNil()
96+ return ObjectMessage () // default/empty message
97+ }
98+
9499 val fieldCount = unpacker.unpackMapHeader()
95100
96101 var id: String? = null
@@ -105,7 +110,7 @@ internal fun readObjectMessage(unpacker: MessageUnpacker): ObjectMessage {
105110
106111 for (i in 0 until fieldCount) {
107112 val fieldName = unpacker.unpackString().intern()
108- val fieldFormat = unpacker.getNextFormat()
113+ val fieldFormat = unpacker.nextFormat
109114
110115 if (fieldFormat == MessageFormat .NIL ) {
111116 unpacker.unpackNil()
@@ -207,7 +212,7 @@ private fun ObjectOperation.writeMsgpack(packer: MessagePacker) {
207212private fun readObjectOperation (unpacker : MessageUnpacker ): ObjectOperation {
208213 val fieldCount = unpacker.unpackMapHeader()
209214
210- var action: ObjectOperationAction = ObjectOperationAction . MapCreate // Default value
215+ var action: ObjectOperationAction ? = null
211216 var objectId: String = " "
212217 var mapOp: ObjectMapOp ? = null
213218 var counterOp: ObjectCounterOp ? = null
@@ -219,7 +224,7 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
219224
220225 for (i in 0 until fieldCount) {
221226 val fieldName = unpacker.unpackString().intern()
222- val fieldFormat = unpacker.getNextFormat()
227+ val fieldFormat = unpacker.nextFormat
223228
224229 if (fieldFormat == MessageFormat .NIL ) {
225230 unpacker.unpackNil()
@@ -246,6 +251,10 @@ private fun readObjectOperation(unpacker: MessageUnpacker): ObjectOperation {
246251 }
247252 }
248253
254+ if (action == null ) {
255+ throw IllegalArgumentException (" Missing required 'action' field in ObjectOperation" )
256+ }
257+
249258 return ObjectOperation (
250259 action = action,
251260 objectId = objectId,
@@ -315,7 +324,7 @@ private fun readObjectState(unpacker: MessageUnpacker): ObjectState {
315324
316325 for (i in 0 until fieldCount) {
317326 val fieldName = unpacker.unpackString().intern()
318- val fieldFormat = unpacker.getNextFormat()
327+ val fieldFormat = unpacker.nextFormat
319328
320329 if (fieldFormat == MessageFormat .NIL ) {
321330 unpacker.unpackNil()
@@ -382,7 +391,7 @@ private fun readObjectMapOp(unpacker: MessageUnpacker): ObjectMapOp {
382391
383392 for (i in 0 until fieldCount) {
384393 val fieldName = unpacker.unpackString().intern()
385- val fieldFormat = unpacker.getNextFormat()
394+ val fieldFormat = unpacker.nextFormat
386395
387396 if (fieldFormat == MessageFormat .NIL ) {
388397 unpacker.unpackNil()
@@ -425,7 +434,7 @@ private fun readObjectCounterOp(unpacker: MessageUnpacker): ObjectCounterOp {
425434
426435 for (i in 0 until fieldCount) {
427436 val fieldName = unpacker.unpackString().intern()
428- val fieldFormat = unpacker.getNextFormat()
437+ val fieldFormat = unpacker.nextFormat
429438
430439 if (fieldFormat == MessageFormat .NIL ) {
431440 unpacker.unpackNil()
@@ -478,7 +487,7 @@ private fun readObjectMap(unpacker: MessageUnpacker): ObjectMap {
478487
479488 for (i in 0 until fieldCount) {
480489 val fieldName = unpacker.unpackString().intern()
481- val fieldFormat = unpacker.getNextFormat()
490+ val fieldFormat = unpacker.nextFormat
482491
483492 if (fieldFormat == MessageFormat .NIL ) {
484493 unpacker.unpackNil()
@@ -531,7 +540,7 @@ private fun readObjectCounter(unpacker: MessageUnpacker): ObjectCounter {
531540
532541 for (i in 0 until fieldCount) {
533542 val fieldName = unpacker.unpackString().intern()
534- val fieldFormat = unpacker.getNextFormat()
543+ val fieldFormat = unpacker.nextFormat
535544
536545 if (fieldFormat == MessageFormat .NIL ) {
537546 unpacker.unpackNil()
@@ -587,7 +596,7 @@ private fun readObjectMapEntry(unpacker: MessageUnpacker): ObjectMapEntry {
587596
588597 for (i in 0 until fieldCount) {
589598 val fieldName = unpacker.unpackString().intern()
590- val fieldFormat = unpacker.getNextFormat()
599+ val fieldFormat = unpacker.nextFormat
591600
592601 if (fieldFormat == MessageFormat .NIL ) {
593602 unpacker.unpackNil()
@@ -667,7 +676,7 @@ private fun readObjectData(unpacker: MessageUnpacker): ObjectData {
667676
668677 for (i in 0 until fieldCount) {
669678 val fieldName = unpacker.unpackString().intern()
670- val fieldFormat = unpacker.getNextFormat()
679+ val fieldFormat = unpacker.nextFormat
671680
672681 if (fieldFormat == MessageFormat .NIL ) {
673682 unpacker.unpackNil()
0 commit comments