1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "ArchivingUtils.h"
8
9#include <Message.h>
10
11
12/*static*/ status_t
13ArchivingUtils::ArchiveChild(BArchivable* object, BMessage& parentArchive,
14	const char* fieldName)
15{
16	if (object == NULL)
17		return B_BAD_VALUE;
18
19	BMessage archive;
20	status_t error = object->Archive(&archive, true);
21	if (error != B_OK)
22		return error;
23
24	return parentArchive.AddMessage(fieldName, &archive);
25}
26
27
28/*static*/ BArchivable*
29ArchivingUtils::UnarchiveChild(const BMessage& parentArchive,
30	const char* fieldName, int32 index)
31{
32	BMessage archive;
33	if (parentArchive.FindMessage(fieldName, index, &archive) != B_OK)
34		return NULL;
35
36	return instantiate_object(&archive);
37}
38