MessageAdapter.h revision 5ce80a78
1/*
2 * Copyright 2007-2015, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Michael Lotz <mmlr@mlotz.ch>
7 */
8#ifndef _MESSAGE_ADAPTER_H_
9#define _MESSAGE_ADAPTER_H_
10
11
12#include <Message.h>
13#include <util/KMessage.h>
14
15
16// message formats
17#define MESSAGE_FORMAT_R5				'FOB1'
18#define MESSAGE_FORMAT_R5_SWAPPED		'1BOF'
19#define MESSAGE_FORMAT_DANO				'FOB2'
20#define MESSAGE_FORMAT_DANO_SWAPPED		'2BOF'
21#define MESSAGE_FORMAT_HAIKU			'1FMH'
22#define MESSAGE_FORMAT_HAIKU_SWAPPED	'HMF1'
23
24
25namespace BPrivate {
26
27
28class MessageAdapter {
29public:
30	static	ssize_t				FlattenedSize(uint32 format,
31									const BMessage* from);
32
33	static	status_t			Flatten(uint32 format, const BMessage* from,
34									char* buffer, ssize_t* size);
35	static	status_t			Flatten(uint32 format, const BMessage* from,
36									BDataIO* stream, ssize_t* size);
37
38	static	status_t			Unflatten(uint32 format, BMessage* into,
39									const char* buffer);
40	static	status_t			Unflatten(uint32 format, BMessage* into,
41									BDataIO* stream);
42
43	static	status_t			ConvertToKMessage(const BMessage* from,
44									KMessage& to);
45
46private:
47	static	status_t			_ConvertFromKMessage(const KMessage* from,
48									BMessage* to);
49
50	static	ssize_t				_R5FlattenedSize(const BMessage* from);
51
52	static	status_t			_FlattenR5Message(uint32 format,
53									const BMessage* from, char* buffer,
54									ssize_t* size);
55
56	static	status_t			_UnflattenR5Message(uint32 format,
57									BMessage* into, BDataIO* stream);
58	static	status_t			_UnflattenDanoMessage(uint32 format,
59									BMessage* into, BDataIO* stream);
60};
61
62
63} // namespace BPrivate
64
65
66#endif // _MESSAGE_ADAPTER_H_
67