ivandasch commented on a change in pull request #2:
URL:
https://github.com/apache/ignite-python-thin-client/pull/2#discussion_r560805383
##########
File path: pyignite/binary.py
##########
@@ -103,10 +99,98 @@ def __new__(
mcs: Any, name: str, base_classes: tuple, namespace: dict, **kwargs
) -> Any:
""" Sort out class creation arguments. """
- return super().__new__(
- mcs, name, (GenericObjectPropsMixin, )+base_classes, namespace
+
+ result = super().__new__(
+ mcs, name, (GenericObjectProps, )+base_classes, namespace
)
+ def _build(self, client: 'Client' = None) -> int:
+ """
+ Method for building binary representation of the Generic object
+ and calculating a hashcode from it.
+
+ :param self: Generic object instance,
+ :param client: (optional) connection to Ignite cluster,
+ """
+ if client is None:
+ compact_footer = True
+ else:
+ compact_footer = client.compact_footer
+
+ # prepare header
+ header_class = BinaryObject.build_header()
+ header = header_class()
+ header.type_code = int.from_bytes(
+ BinaryObject.type_code,
+ byteorder=PROTOCOL_BYTE_ORDER
+ )
+ header.flags = BinaryObject.USER_TYPE | BinaryObject.HAS_SCHEMA
+ if compact_footer:
+ header.flags |= BinaryObject.COMPACT_FOOTER
+ header.version = self.version
+ header.type_id = self.type_id
+ header.schema_id = self.schema_id
+
+ # create fields and calculate offsets
+ offsets = [ctypes.sizeof(header_class)]
+ field_buffer = bytearray()
+ schema_items = list(self.schema.items())
+ for field_name, field_type in schema_items:
+ partial_buffer = field_type.from_python(
+ getattr(
+ self, field_name, getattr(field_type, 'default', None)
+ )
+ )
+ offsets.append(max(offsets) + len(partial_buffer))
+ field_buffer += partial_buffer
+
+ offsets = offsets[:-1]
+
+ # create footer
+ if max(offsets, default=0) < 255:
+ header.flags |= BinaryObject.OFFSET_ONE_BYTE
+ elif max(offsets) < 65535:
+ header.flags |= BinaryObject.OFFSET_TWO_BYTES
+ schema_class = (
+ BinaryObject.schema_type(header.flags)
Review comment:
Why new lines here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]