Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyignite/api/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_binary_type(
if result.status != 0:
return result
result.value = {
'type_exists': response.type_exists
'type_exists': Bool.to_python(response.type_exists)
}
if hasattr(response, 'body'):
result.value.update(body_struct.to_python(response.body))
Expand Down
2 changes: 1 addition & 1 deletion pyignite/datatypes/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class Struct:

def parse(
self, client: 'Client'
) -> Tuple[ctypes.BigEndianStructure, bytes]:
) -> Tuple[ctypes.LittleEndianStructure, bytes]:
buffer = b''
fields = []
values = {}
Expand Down
44 changes: 37 additions & 7 deletions pyignite/datatypes/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# limitations under the License.

import ctypes
import struct
import sys

from pyignite.constants import *
from .base import IgniteDataType
Expand Down Expand Up @@ -48,50 +50,70 @@ class Primitive(IgniteDataType):
def parse(cls, client: 'Client'):
return cls.c_type, client.recv(ctypes.sizeof(cls.c_type))

@staticmethod
def to_python(ctype_object, *args, **kwargs):
return ctype_object

@classmethod
def from_python(cls, value):
return bytes(cls.c_type(value))
def to_python(cls, ctype_object, *args, **kwargs):
return ctype_object


class Byte(Primitive):
_type_name = NAME_BYTE
_type_id = TYPE_BYTE
c_type = ctypes.c_byte

@classmethod
def from_python(cls, value):
return struct.pack("<b", value)


class Short(Primitive):
_type_name = NAME_SHORT
_type_id = TYPE_SHORT
c_type = ctypes.c_short

@classmethod
def from_python(cls, value):
return struct.pack("<h", value)


class Int(Primitive):
_type_name = NAME_INT
_type_id = TYPE_INT
c_type = ctypes.c_int

@classmethod
def from_python(cls, value):
return struct.pack("<i", value)


class Long(Primitive):
_type_name = NAME_LONG
_type_id = TYPE_LONG
c_type = ctypes.c_longlong

@classmethod
def from_python(cls, value):
return struct.pack("<q", value)


class Float(Primitive):
_type_name = NAME_FLOAT
_type_id = TYPE_FLOAT
c_type = ctypes.c_float

@classmethod
def from_python(cls, value):
return struct.pack("<f", value)


class Double(Primitive):
_type_name = NAME_DOUBLE
_type_id = TYPE_DOUBLE
c_type = ctypes.c_double

@classmethod
def from_python(cls, value):
return struct.pack("<d", value)


class Char(Primitive):
_type_name = NAME_CHAR
Expand Down Expand Up @@ -122,4 +144,12 @@ def from_python(cls, value):
class Bool(Primitive):
_type_name = NAME_BOOLEAN
_type_id = TYPE_BOOLEAN
c_type = ctypes.c_bool
c_type = ctypes.c_byte # Use c_byte because c_bool throws endianness conversion error on BE systems.

@classmethod
def to_python(cls, ctype_object, *args, **kwargs):
return ctype_object != 0

@classmethod
def from_python(cls, value):
return struct.pack("<b", 1 if value else 0)
7 changes: 6 additions & 1 deletion pyignite/datatypes/primitive_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,16 @@ def from_python(cls, value):
class BoolObject(DataObject):
_type_name = NAME_BOOLEAN
_type_id = TYPE_BOOLEAN
c_type = ctypes.c_bool
c_type = ctypes.c_byte # Use c_byte because c_bool throws endianness conversion error on BE systems.
type_code = TC_BOOL
pythonic = bool
default = False

@staticmethod
def hashcode(value: bool, *args, **kwargs) -> int:
return 1231 if value else 1237

@classmethod
def to_python(cls, ctype_object, *args, **kwargs):
return ctype_object.value != 0

2 changes: 1 addition & 1 deletion pyignite/queries/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _parse_success(self, conn: Connection, buffer: bytearray, fields: list):
)
fields += body_class._fields_ + [
('data', data_class),
('more', ctypes.c_bool),
('more', ctypes.c_byte),
]

def _create_parse_result(self, conn: Connection, header_class, fields: list, buffer: bytearray):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class OuterType(

def test_add_schema_to_binary_object(client):

migrate_cache = client.create_cache('migrate_binary')
migrate_cache = client.get_or_create_cache('migrate_binary')

class MyBinaryType(
metaclass=GenericObjectMeta,
Expand Down