memcache/command.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 03:12:11 +0300
changeset 46 8a832c0e01ee
parent 43 e5b714190dee
child 48 1c67f512779b
permissions -rw-r--r--
bugfixed, enum->string mappings, test does requests
#ifndef MEMCACHE_COMMAND_H
#define MEMCACHE_COMMAND_H

#include <event2/util.h>
#include <event2/buffer.h>

#include "../memcache.h"

struct memcache_cmd {
    struct evbuffer *req_header;
};

int memcache_cmd_init (struct memcache_cmd *cmd, enum memcache_command cmd_type, struct memcache_key *key, struct memcache_obj *obj);

/*
 * Write the request header corresponding to the given command/key/obj to the given evbuffer.
 *
 * This must be atomic, so if it fails, it must not modify buf.
 */
int memcache_cmd_format_header (struct evbuffer *buf, enum memcache_command cmd_type, struct memcache_key *key, struct memcache_obj *obj);

/*
 * Attempt to parse a response line from the given buf. *header_data will be set to NULL if no complete response line
 * was found, or a pointer to the line received (which may contain NULs between tokens), which must be freed by the
 * caller. *reply_type will be set to the parsed `enum memcache_reply` type. If the reply is of type
 * MEMCACHE_RPL_VALUE, then key and obj will be updated to correspond to what was returned (key.buf will point into
 * *header_data). has_data will be set to true if the response also contains cache data.
 *
 * Empty lines will be skipped based on the assumption that they are, in fact, the newline between the data and the
 * MEMCACHE_RPL_END line of a MEMCACHE_RPL_VALUE reply.
 */
int memcache_cmd_parse_header (struct evbuffer *buf, char **header_data, enum memcache_reply *reply_type, struct memcache_key *key, struct memcache_obj *obj, int *has_data);

#endif /* MEMCACHE_COMMAND_H */