penguin-wwy commented on code in PR #1942:
URL: https://github.com/apache/fury/pull/1942#discussion_r1841681685
##########
python/pyfury/_serialization.pyx:
##########
@@ -1644,29 +1656,143 @@ cdef class CollectionSerializer(Serializer):
cpdef int16_t get_xtype_id(self):
return -FuryType.LIST.value
+ cpdef int8_t write_header(self, Buffer buffer, value):
+ cdef int8_t collect_flag = COLLECTION_DEFAULT_FLAG
+ elem_type = type(next(iter(value)))
+ for s in value:
+ if type(s) is not elem_type:
+ collect_flag |= COLLECTION_NOT_SAME_TYPE
+ break
+ if self.fury.ref_tracking:
+ collect_flag |= COLLECTION_TRACKING_REF
+ buffer.write_varint64((len(value) << 4) | collect_flag)
+ return collect_flag
+
cpdef write(self, Buffer buffer, value):
- buffer.write_varint32(len(value))
+ if len(value) == 0:
+ buffer.write_varint64(0)
+ return
+ cdef int8_t collect_flag = self.write_header(buffer, value)
cdef MapRefResolver ref_resolver = self.ref_resolver
cdef ClassResolver class_resolver = self.class_resolver
+ if (collect_flag & COLLECTION_NOT_SAME_TYPE) == 0:
+ elem_type = type(next(iter(value)))
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]