haiku/headers/private/shared/MessageBuilder.h
Augustin Cavalier e4d2963e01 libshared: Introduce JSON parser and MessageBuilder.
Based on an earlier piece of source code of mine that parsed JSON into
QObjects, this JSON parser creates a BMessage tree.

Will be used by Stephan in HaikuDepot for communication with the web app.
2014-08-24 17:36:20 +02:00

55 lines
1.5 KiB
C++

/*
* Copyright 2014, Augustin Cavalier (waddlesplash)
* Distributed under the terms of the MIT License.
*/
#ifndef MESSAGE_BUILDER_H
#define MESSAGE_BUILDER_H
#include <Message.h>
#include <ObjectList.h>
#include <String.h>
namespace BPrivate {
class BMessageBuilder {
public:
BMessageBuilder(BMessage& message);
status_t PushObject(const char* name);
status_t PushObject(uint32 name);
status_t PopObject();
uint32 What();
void SetWhat(uint32 what);
uint32 CountNames(type_code type = B_ANY_TYPE);
// Copied from Message.h
status_t AddString(const char* name, const char* string);
status_t AddString(const char* name,
const BString& string);
status_t AddInt8(const char* name, int8 value);
status_t AddUInt8(const char* name, uint8 value);
status_t AddInt16(const char* name, int16 value);
status_t AddUInt16(const char* name, uint16 value);
status_t AddInt32(const char* name, int32 value);
status_t AddUInt32(const char* name, uint32 value);
status_t AddInt64(const char* name, int64 value);
status_t AddUInt64(const char* name, uint64 value);
status_t AddBool(const char* name, bool value);
status_t AddFloat(const char* name, float value);
status_t AddDouble(const char* name, double value);
status_t AddPointer(const char* name,
const void* pointer);
private:
BObjectList<BMessage> fStack;
BObjectList<BString> fNameStack;
BMessage* fCurrentMessage;
};
} // namespace BPrivate
#endif // MESSAGE_BUILDER_H