# 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
	)
		return {
			'd': serialize_pointer_into_bytes(pointer, length), # serialized data, '' if NULL pointer
			'l': length, # length of serialized data
			'a': ctypes.cast(pointer, ctypes.c_void_p).value, # local pointer address as integer
			'_a': None, # remote pointer has not been initialized
			'w': w # local length of Unicode wchar if required
			}


	def __swap_memory_addresses__(self, memory_d):

		memory_d.update({
			'a': memory_d.get('_a', None),
			'_a': memory_d.get('a', None)
			})


	def __unpack_memory_item_data__(self, memory_d, memsync_d, args_tuple, return_value = None):

		# Swap local and remote memory addresses
		self.__swap_memory_addresses__(memory_d)

		# Search for pointer in passed arguments
		pointer_arg = self.__get_argument_by_memsync_path__(memsync_d['p'][:-1], args_tuple, return_value)

		# Adjust Unicode wchar length
		if memsync_d['w']:
			self.__adjust_wchar_length__(memory_d)

		# Generate pointer to passed data

# 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
	)

		return {
			'd': serialize_pointer_into_bytes(pointer, length), # serialized data, '' if NULL pointer
			'l': length, # length of serialized data
			'a': ctypes.cast(pointer, ctypes.c_void_p).value, # local pointer address as integer
			'_a': None, # remote pointer has not been initialized
			'w': w # local length of Unicode wchar if required
			}


	def __swap_memory_addresses__(self, memory_d):

		memory_d.update({
			'a': memory_d.get('_a', None),
			'_a': memory_d.get('a', None)
			})


	def __unpack_memory_item_data__(self, memory_d, memsync_d, args_tuple, return_value = None):

		# Swap local and remote memory addresses
		self.__swap_memory_addresses__(memory_d)

		# Search for pointer in passed arguments
		pointer_arg = self.__get_argument_by_memsync_path__(memsync_d['p'][:-1], args_tuple, return_value)

		# Adjust Unicode wchar length
		if memsync_d['w']:
			self.__adjust_wchar_length__(memory_d)

		# Generate pointer to passed data

		pointer = generate_pointer_from_bytes(memory_d['d'])