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