-int msgbuf_unparse(char *buf, struct MsgBuf *head, const char *fmt, ...) AFP(3, 4);
-int msgbuf_vunparse(char *buf, struct MsgBuf *head, const char *fmt, va_list va);
+int msgbuf_unparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, unsigned int capmask, const char *fmt, ...) AFP(5, 6);
+int msgbuf_vunparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, unsigned int capmask, const char *fmt, va_list va);
+
+int msgbuf_unparse_linebuf_tags(char *buf, size_t buflen, void *data);
+int msgbuf_unparse_prefix(char *buf, size_t *buflen, const struct MsgBuf *msgbuf, unsigned int capmask);
+
+void msgbuf_cache_init(struct MsgBuf_cache *cache, const struct MsgBuf *msgbuf, const rb_strf_t *message);
+void msgbuf_cache_initf(struct MsgBuf_cache *cache, const struct MsgBuf *msgbuf, const rb_strf_t *message, const char *format, ...) AFP(4, 5);
+buf_head_t *msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps);
+void msgbuf_cache_free(struct MsgBuf_cache *cache);
+
+static inline void
+msgbuf_init(struct MsgBuf *msgbuf)
+{
+ memset(msgbuf, 0, sizeof(*msgbuf));
+}
+
+static inline void
+msgbuf_append_tag(struct MsgBuf *msgbuf, const char *key, const char *value, unsigned int capmask)
+{
+ if (msgbuf->n_tags < MAXPARA) {
+ msgbuf->tags[msgbuf->n_tags].key = key;
+ msgbuf->tags[msgbuf->n_tags].value = value;
+ msgbuf->tags[msgbuf->n_tags].capmask = capmask;
+ msgbuf->n_tags++;
+ }
+}