MarshalHelper

MarshalHelper

MarshalHelper は直列化を扱う際に有用な関数を集めたパッケージである。 全ての関数は static 関数として提供されている。

std::string に関する直列化関数

int GetMarshalSize(const std::string& str)
Marshal で str を直列化した時にバッファに書かれるサイズを返す。
bool Marshal(Buffer* pBuf, const std::string& str)
Marshal で str を直列化して書きこむ。文字列は単純なシングルバイト列として扱う。
bool Unmarshal(Buffer* pBuf, std::string* pStr)
pBuf から直列化された文字列を読み込む。文字列は単純なシングルバイト列として扱う。

Message に関する直列化関数

int GetMarshalSize(const nine::Message* pMsg)
Marshal で pMsg を直列化した時にバッファに書かれるサイズを返す。
bool Marshal(Buffer* pBuf, const nine::Message* pMsg)
Marshal で pMsg を直列化して書きこむ。
bool Unmarshal(Buffer* pBuf, nine::Message** ppMsg)
pBuf から直列化されたメッセージを読み込み、新たなオブジェクトを *ppMsg セットする。

JSON に関する直列化関数

汎用的な JSON オブジェクト、JSON 文字列表現、nine Message の直列化関数。 メッセージを HTTP レスポンスで返す場合に使うことを想定している。

API は、第一引数が結果渡し用(out引数)、第二引数が入力用(in引数)となっている。

bool UnmarshalJsonString(nine::Message** ppMsg, const std::string& str)
JSON文字列から Message を復元する。
bool UnmarshalJsonStringArray(std::list< nine::Message* >& ret, const std::string&)
JSON配列文字列から Message を復元する。
bool UnmarshalJsonString(nine::JsonObject* pObj, const std::string& str)
JSON文字列から JsonObject を復元する
bool UnmarshalJsonString(nine::JsonArray* pObj, const std::string& str)
JSON文字列から JsonArray を復元する
bool JsonToMessage(nine::Message** ppMsg, const nine::JsonObject& obj)
JsonObject から Message を復元する。

HTTP QueryString に関する直列化関数

直接 HTTP リクエストを扱う場合の直列化に利用することを想定している。

中間形式として、typedef std::map< std::string, std::string > QueryMap型を用いる。

bool MarshalQueryString(std::string* str, const Message* pMsg)
Message を直列化して QueryString 文字列にする。
bool MessageToQueryMap(QueryMap* tmp, const Message* pMsg)
Message を直列化中間形式の map にする。
bool MarshalQueryString(std::string* str, const QueryMap& tmp)
中間形式の map を文字列表現にする。
bool UnmarshalQueryString(nine::Message** ppMsg, const std::string& str)
QueryString から Message を復元する。
bool UnmarshalQueryString(QueryMap* ret, const std::string& str)
QueryString から map を復元する。
bool QueryMapToMessage(nine::Message** ppMsg, const QueryMap& m)
map から Message を復元する。