#include <Message.h>
#include "DProxy.h"
#include <stdlib.h>
#include <stdio.h>

extern "C" status_t DumpVariable(DProxy& proxy);

// Sorry this will never work and if my mind hadn't been clouded that much
// I wouldn't even have tried. Must be the terrible wheather we have over here...
// 
// Maybe someone else with intimate knowledge of 
// BMessages and related undocumented parts of the
// system can come up with a better approach?

status_t DumpVariable(DProxy& proxy)
{
	ptr_t addr = proxy.VariableAddress();
	
	if (proxy.IsPointer())
	{
		proxy.Dereference();
		addr = proxy.VariableAddress();
	}
	
	size_t size = proxy.VariableSize();
	void *p = malloc(size);
	if (p && proxy.ReadData (addr, p, size) == B_OK)
	{
		static_cast<BMessage*>(p)->PrintToStream();
		free(p);
	}
	else
		puts("Insufficient memory");
} // DumpVariable
