# Path: src/zugbruecke/core/const.py
# GROUP_VOID = 1
# 
# Path: src/zugbruecke/core/data/memory.py
# def generate_pointer_from_bytes(in_bytes):
# 
# 	return ctypes.cast(ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), ctypes.c_void_p)
# 
# def is_null_pointer(ctypes_pointer):
# 
# 	try:
# 		return ctypes.cast(ctypes_pointer, ctypes.c_void_p).value is None
# 	except ctypes.ArgumentError: # catch non-pointer arguments
# 		return False
# 
# def overwrite_pointer_with_bytes(ctypes_pointer, in_bytes):
# 
# 	ctypes.memmove(ctypes_pointer, ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), len(in_bytes))
# 
# def serialize_pointer_into_bytes(ctypes_pointer, size_bytes):
# 
# 	return bytes(ctypes.cast(ctypes_pointer, ctypes.POINTER(ctypes.c_ubyte * size_bytes)).contents)


import ctypes
from pprint import pformat as pf
from ..const import GROUP_VOID
from .memory import (
	generate_pointer_from_bytes,
	is_null_pointer,
	overwrite_pointer_with_bytes,
	serialize_pointer_into_bytes
	)
		# Iterate over memory package dicts
		for memory_d, memsync_d in zip(mem_package_list, memsync_d_list):

			# If memory for pointer has been allocated by remote side
			if memory_d['_a'] is None:

				# Unpack one memory section / item
				self.__unpack_memory_item_data__(memory_d, memsync_d, args_list, return_value)

			# If pointer pointed to data
			else:

				# Overwrite pointer
				self.__unpack_memory_item_overwrite__(memory_d, memsync_d, args_list)


	def server_pack_memory_list(self, args_list, return_value, mem_package_list, memsync_d_list):

		# Iterate through pointers and serialize them
		for memory_d, memsync_d in zip(mem_package_list, memsync_d_list):

			# If memory for pointer was allocated here on server side
			if memory_d['a'] is None:

				memory_d.update(self.__pack_memory_item__(memsync_d, args_list, return_value))

			# If pointer pointed to data on client side
			else:

				# Overwrite old data in package with new data from memory

# Path: src/zugbruecke/core/const.py
# GROUP_VOID = 1
# 
# Path: src/zugbruecke/core/data/memory.py
# def generate_pointer_from_bytes(in_bytes):
# 
# 	return ctypes.cast(ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), ctypes.c_void_p)
# 
# def is_null_pointer(ctypes_pointer):
# 
# 	try:
# 		return ctypes.cast(ctypes_pointer, ctypes.c_void_p).value is None
# 	except ctypes.ArgumentError: # catch non-pointer arguments
# 		return False
# 
# def overwrite_pointer_with_bytes(ctypes_pointer, in_bytes):
# 
# 	ctypes.memmove(ctypes_pointer, ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), len(in_bytes))
# 
# def serialize_pointer_into_bytes(ctypes_pointer, size_bytes):
# 
# 	return bytes(ctypes.cast(ctypes_pointer, ctypes.POINTER(ctypes.c_ubyte * size_bytes)).contents)


# Path: src/zugbruecke/core/data/mem_contents.py
import ctypes
from pprint import pformat as pf
from ..const import GROUP_VOID
from .memory import (
	generate_pointer_from_bytes,
	is_null_pointer,
	overwrite_pointer_with_bytes,
	serialize_pointer_into_bytes
	)

		# Iterate over memory package dicts
		for memory_d, memsync_d in zip(mem_package_list, memsync_d_list):

			# If memory for pointer has been allocated by remote side
			if memory_d['_a'] is None:

				# Unpack one memory section / item
				self.__unpack_memory_item_data__(memory_d, memsync_d, args_list, return_value)

			# If pointer pointed to data
			else:

				# Overwrite pointer
				self.__unpack_memory_item_overwrite__(memory_d, memsync_d, args_list)


	def server_pack_memory_list(self, args_list, return_value, mem_package_list, memsync_d_list):

		# Iterate through pointers and serialize them
		for memory_d, memsync_d in zip(mem_package_list, memsync_d_list):

			# If memory for pointer was allocated here on server side
			if memory_d['a'] is None:

				memory_d.update(self.__pack_memory_item__(memsync_d, args_list, return_value))

			# If pointer pointed to data on client side
			else:

				# Overwrite old data in package with new data from memory

				memory_d['d'] = serialize_pointer_into_bytes(