#include "NodeMessage.h"
#include <StorageKit.h>
#include <fs_attr.h>
#include <stdlib.h>
_EXPORT BNode& operator<<(BNode& n, const BMessage& m)
{
#if defined(HAIKU_TARGET_PLATFORM_DANO)
const
#endif
char *name;
type_code type;
ssize_t bytes;
const void *data;
for (int32 i = 0;
m.GetInfo(B_ANY_TYPE, i, &name, &type) == 0;
i++) {
m.FindData (name,type,0,&data,&bytes);
n.WriteAttr(name,type,0, data, bytes);
}
return n;
}
_EXPORT BNode& operator>>(BNode& n, BMessage& m)
{
char name[B_ATTR_NAME_LENGTH];
attr_info info;
char *buf = NULL;
n.RewindAttrs();
while (n.GetNextAttrName(name) == B_OK) {
if (n.GetAttrInfo(name,&info) != B_OK)
continue;
if (char *newBuffer = (char*)realloc(buf, info.size))
buf = newBuffer;
else
continue;
info.size=n.ReadAttr(name,info.type,0,buf,info.size);
if (info.size >= 0)
m.AddData(name,info.type,buf,info.size);
}
n.RewindAttrs();
free(buf);
return n;
}