/* * Created by yuuta on 7/19/22. */ #ifndef LIBAC_SERIALIZER_H #define LIBAC_SERIALIZER_H #include /* An internal error code indicating that more data is required. * Should not conflict with other error codes. */ #define AC_E_SERIALIZER_CONTINUE -1 /** * Deserialize an event or a response into ac_obj_t. * @param string The partial or complete response. * @param len The length to the string, excluding tailing NULL. * @param out The final object. Not NULL if the return value is AC_E_OK. * @return AC_E_OK or an error code. When failed, the *out is untouched. * MT-Safe config */ int deserialize(const char *string, unsigned int len, ac_obj_t **out); /** * Force a deserializer reset. * @return AC_E_OK or an error code. * MT-Safe */ int serializer_finalize(void); /** * Serialize a request to a JSON object. * @param req The request. Must be a valid ac_request. * @param out The output json_object. Will not be NULL if the return value is AC_E_OK. * @return AC_E_OK or an error code. When failed, the *out is untouched. * MT-Safe */ int serialize_request(const ac_request_t *req, json_object **out); #endif /* LIBAC_SERIALIZER_H */