diff options
Diffstat (limited to 'facebook/facebook-thrift.h')
-rw-r--r-- | facebook/facebook-thrift.h | 617 |
1 files changed, 522 insertions, 95 deletions
diff --git a/facebook/facebook-thrift.h b/facebook/facebook-thrift.h index 0438e7b..25b43f5 100644 --- a/facebook/facebook-thrift.h +++ b/facebook/facebook-thrift.h @@ -15,155 +15,582 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** @file **/ +#ifndef _FACEBOOK_THRIFT_H_ +#define _FACEBOOK_THRIFT_H_ -#ifndef _FACEBOOK_THRIFT_H -#define _FACEBOOK_THRIFT_H +/** + * SECTION:thrift + * @section_id: facebook-thrift + * @short_description: <filename>facebook-thrift.h</filename> + * @title: Thrift Reader/Writer + * + * The Thrift reader/writer. + */ #include <glib.h> +#include <glib-object.h> +#define FB_TYPE_THRIFT (fb_thrift_get_type()) +#define FB_THRIFT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), FB_TYPE_THRIFT, FbThrift)) +#define FB_THRIFT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), FB_TYPE_THRIFT, FbThriftClass)) +#define FB_IS_THRIFT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), FB_TYPE_THRIFT)) +#define FB_IS_THRIFT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), FB_TYPE_THRIFT)) +#define FB_THRIFT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), FB_TYPE_THRIFT, FbThriftClass)) -/** The flags of a #fb_thrift. **/ -typedef enum fb_thrift_flags fb_thrift_flags_t; - -/** The #fb_thrift data types. **/ -typedef enum fb_thrift_type fb_thrift_type_t; - -/** The main structure for Thrift IO. **/ -typedef struct fb_thrift fb_thrift_t; - +typedef struct _FbThrift FbThrift; +typedef struct _FbThriftClass FbThriftClass; +typedef struct _FbThriftPrivate FbThriftPrivate; /** - * The flags of a #fb_thrift. - **/ -enum fb_thrift_flags + * FbThriftType: + * @FB_THRIFT_TYPE_STOP: A stopper for certain types. + * @FB_THRIFT_TYPE_VOID: A void or empty value. + * @FB_THRIFT_TYPE_BOOL: A boolean (#TRUE or #FALSE). + * @FB_THRIFT_TYPE_BYTE: A signed 8-bit integer. + * @FB_THRIFT_TYPE_DOUBLE: A 64-bit floating point number. + * @FB_THRIFT_TYPE_I16: A signed 16-bit integer. + * @FB_THRIFT_TYPE_I32: A signed 32-bit integer. + * @FB_THRIFT_TYPE_I64: A signed 64-bit integer. + * @FB_THRIFT_TYPE_STRING: A UTF-8 encoded string. + * @FB_THRIFT_TYPE_STRUCT: A set of typed fields. + * @FB_THRIFT_TYPE_MAP: A map of unique keys to values. + * @FB_THRIFT_TYPE_SET: A unique set of values. + * @FB_THRIFT_TYPE_LIST: A ordered list of values. + * @FB_THRIFT_TYPE_ENUM: A 32-bit enumerated list. + * @FB_THRIFT_TYPE_UNKNOWN: An unknown type. + * + * The Thrift data types. + */ +typedef enum { - FB_THRIFT_FLAG_COMPACT = 1 << 0, /** Compact types. **/ - FB_THRIFT_FLAG_INTERNAL = 1 << 1 /** Internal #GByteArray. **/ -}; + FB_THRIFT_TYPE_STOP = 0, + FB_THRIFT_TYPE_VOID = 1, + FB_THRIFT_TYPE_BOOL = 2, + FB_THRIFT_TYPE_BYTE = 3, + FB_THRIFT_TYPE_DOUBLE = 4, + FB_THRIFT_TYPE_I16 = 6, + FB_THRIFT_TYPE_I32 = 8, + FB_THRIFT_TYPE_I64 = 10, + FB_THRIFT_TYPE_STRING = 11, + FB_THRIFT_TYPE_STRUCT = 12, + FB_THRIFT_TYPE_MAP = 13, + FB_THRIFT_TYPE_SET = 14, + FB_THRIFT_TYPE_LIST = 15, + FB_THRIFT_TYPE_ENUM = 16, + + FB_THRIFT_TYPE_UNKNOWN +} FbThriftType; /** - * The #fb_thrift data types. - **/ -enum fb_thrift_type + * FbThrift: + * + * Represents a reader/writer for compact Thrift data. + */ +struct _FbThrift { - FB_THRIFT_TYPE_STOP = 0, /** Stop. **/ - FB_THRIFT_TYPE_VOID = 1, /** Void. **/ - FB_THRIFT_TYPE_BOOL = 2, /** Boolean. **/ - FB_THRIFT_TYPE_BYTE = 3, /** Byte. **/ - FB_THRIFT_TYPE_DOUBLE = 4, /** Double. **/ - FB_THRIFT_TYPE_I16 = 6, /** Integer (16-bit). **/ - FB_THRIFT_TYPE_I32 = 8, /** Integer (32-bit). **/ - FB_THRIFT_TYPE_I64 = 10, /** Integer (64-bit). **/ - FB_THRIFT_TYPE_STRING = 11, /** String. **/ - FB_THRIFT_TYPE_STRUCT = 12, /** Structure. **/ - FB_THRIFT_TYPE_MAP = 13, /** Map. **/ - FB_THRIFT_TYPE_SET = 14, /** Set. **/ - FB_THRIFT_TYPE_LIST = 15, /** List. **/ - FB_THRIFT_TYPE_ENUM = 16, /** Enumerator. **/ - - FB_THRIFT_TYPE_UNKNOWN /** Unknown. **/ - + /*< private >*/ + GObject parent; + FbThriftPrivate *priv; }; /** - * The main structure for Thrift IO. - **/ -struct fb_thrift + * FbThriftClass: + * + * The base class for all #FbThrift's. + */ +struct _FbThriftClass { - fb_thrift_flags_t flags; /** The #fb_thrift_flags. **/ + /*< private >*/ + GObjectClass parent_class; +}; - gint16 lastid; /** The last identifier. **/ - guint lastbool; /** The last boolean value. **/ +/** + * fb_thrift_get_type: + * + * Returns: The #GType for an #FbThrift. + */ +GType +fb_thrift_get_type(void); - GByteArray *bytes; /** The #GByteArray of data. **/ - guint offset; /** The data offset. **/ - guint pos; /** The cursor position. **/ -}; +/** + * fb_thrift_new: + * @bytes: The #GByteArray to read or write. + * @offset: The offset in bytes of the data in @bytes. + * + * Creates a new #FbThrift. The returned #FbThrift should be freed with + * #g_object_unref() when no longer needed. This will optionally use a + * #GByteArray at an offset, rather than a newly created and internal + * #GByteArray. + * + * Returns: The new #FbThrift. + */ +FbThrift * +fb_thrift_new(GByteArray *bytes, guint offset); +/** + * fb_thrift_get_bytes: + * @thft: The #FbThrift. + * + * Gets the underlying #GByteArray of an #FbThrift. + * + * Returns: The #GByteArray. + */ +const GByteArray * +fb_thrift_get_bytes(FbThrift *thft); -fb_thrift_t *fb_thrift_new(GByteArray *bytes, guint offset, gboolean compact); +/** + * fb_thrift_get_pos: + * @thft: The #FbThrift. + * + * Gets the cursor position of an #FbThrift. + * + * Returns: The cursor position. + */ +guint +fb_thrift_get_pos(FbThrift *thft); -void fb_thrift_free(fb_thrift_t *thft); +/** + * fb_thrift_set_pos: + * @thft: The #FbThrift. + * @pos: The position. + * + * Sets the cursor position of an #FbThrift. + * + * Returns: The #GByteArray. + */ +void +fb_thrift_set_pos(FbThrift *thft, guint pos); -void fb_thrift_reset(fb_thrift_t *thft); +/** + * fb_thrift_reset: + * @thft: The #FbThrift. + * + * Resets the cursor position of an #FbThrift. + * + * Returns: The #GByteArray. + */ +void +fb_thrift_reset(FbThrift *thft); -gboolean fb_thrift_read(fb_thrift_t *thft, gpointer data, guint size); +/** + * fb_thrift_read: + * @thft: The #FbThrift. + * @data: The data buffer. + * @size: The size of @buffer. + * + * Reads data from the #FbThrift into a buffer. If @data is #NULL, this + * will simply advance the cursor position. + * + * Returns: #TRUE if the data was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read(FbThrift *thft, gpointer data, guint size); -gboolean fb_thrift_read_bool(fb_thrift_t *thft, gboolean *bln); +/** + * fb_thrift_read_bool: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a boolean value from the #FbThrift. If @value is #NULL, this + * will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_bool(FbThrift *thft, gboolean *value); -gboolean fb_thrift_read_byte(fb_thrift_t *thft, guint8 *byte); +/** + * fb_thrift_read_byte: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads an 8-bit integer value from the #FbThrift. If @value is #NULL, + * this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_byte(FbThrift *thft, guint8 *value); -gboolean fb_thrift_read_dbl(fb_thrift_t *thft, gdouble *dbl); +/** + * fb_thrift_read_dbl: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a 64-bit floating point value from the #FbThrift. If @value + * is #NULL, this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_dbl(FbThrift *thft, gdouble *value); -gboolean fb_thrift_read_i16(fb_thrift_t *thft, gint16 *i16); +/** + * fb_thrift_read_i16: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a signed 16-bit integer value from the #FbThrift. This will + * convert the integer from the zig-zag format. If @value is #NULL, + * this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_i16(FbThrift *thft, gint16 *value); -gboolean fb_thrift_read_vi16(fb_thrift_t *thft, guint16 *u16); +/** + * fb_thrift_read_vi16: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a 16-bit integer value from the #FbThrift. This reads the raw + * integer value without converting it from the zig-zag format. If + * @value is #NULL, this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_vi16(FbThrift *thft, guint16 *value); -gboolean fb_thrift_read_i32(fb_thrift_t *thft, gint32 *i32); +/** + * fb_thrift_read_i32: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a signed 32-bit integer value from the #FbThrift. This will + * convert the integer from the zig-zag format. If @value is #NULL, + * this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_i32(FbThrift *thft, gint32 *value); -gboolean fb_thrift_read_vi32(fb_thrift_t *thft, guint32 *u32); +/** + * fb_thrift_read_vi32: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a 32-bit integer value from the #FbThrift. This reads the raw + * integer value without converting it from the zig-zag format. If + * @value is #NULL, this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_vi32(FbThrift *thft, guint32 *value); -gboolean fb_thrift_read_i64(fb_thrift_t *thft, gint64 *i64); +/** + * fb_thrift_read_i64: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a signed 64-bit integer value from the #FbThrift. This will + * convert the integer from the zig-zag format. If @value is #NULL, + * this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_i64(FbThrift *thft, gint64 *value); -gboolean fb_thrift_read_vi64(fb_thrift_t *thft, guint64 *u64); +/** + * fb_thrift_read_vi64: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a 64-bit integer value from the #FbThrift. This reads the raw + * integer value without converting it from the zig-zag format. If + * @value is #NULL, this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_vi64(FbThrift *thft, guint64 *value); -gboolean fb_thrift_read_str(fb_thrift_t *thft, gchar **str); +/** + * fb_thrift_read_str: + * @thft: The #FbThrift. + * @value: The return location for the value, or #NULL. + * + * Reads a string value from the #FbThrift. The value returned to + * @value should be freed with #g_free() when no longer needed. If + * @value is #NULL, this will simply advance the cursor position. + * + * Returns: #TRUE if the value was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_str(FbThrift *thft, gchar **value); -gboolean fb_thrift_read_field(fb_thrift_t *thft, fb_thrift_type_t *type, - gint16 *id); +/** + * fb_thrift_read_field: + * @thft: The #FbThrift. + * @type: The return location for the #FbThriftType. + * @id: The return location for the identifier, or #NULL. + * + * Reads a field header from the #FbThrift. + * + * Returns: #TRUE if the field header was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_field(FbThrift *thft, FbThriftType *type, gint16 *id); -gboolean fb_thrift_read_stop(fb_thrift_t *thft); +/** + * fb_thrift_read_stop: + * @thft: The #FbThrift. + * + * Reads a field stop from the #FbThrift. + * + * Returns: #TRUE if the field stop was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_stop(FbThrift *thft); -gboolean fb_thrift_read_isstop(fb_thrift_t *thft); +/** + * fb_thrift_read_isstop: + * @thft: The #FbThrift. + * + * Determines if the next byte of the #FbThrift is a field stop. + * + * Returns: #TRUE if the next byte is a field stop, otherwise #FALSE. + */ +gboolean +fb_thrift_read_isstop(FbThrift *thft); -gboolean fb_thrift_read_list(fb_thrift_t *thft, fb_thrift_type_t *type, - guint *size); +/** + * fb_thrift_read_list: + * @thft: The #FbThrift. + * @type: The return location for the #FbThriftType. + * @size: The return location for the size. + * + * Reads a list header from the #FbThrift. + * + * Returns: #TRUE if the list header was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_list(FbThrift *thft, FbThriftType *type, guint *size); -gboolean fb_thrift_read_map(fb_thrift_t *thft, fb_thrift_type_t *ktype, - fb_thrift_type_t *vtype, guint *size); +/** + * fb_thrift_read_map: + * @thft: The #FbThrift. + * @ktype: The return location for the key #FbThriftType. + * @vtype: The return location for the value #FbThriftType. + * @size: The return location for the size. + * + * Reads a map header from the #FbThrift. + * + * Returns: #TRUE if the map header was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_map(FbThrift *thft, FbThriftType *ktype, FbThriftType *vtype, + guint *size); -gboolean fb_thrift_read_set(fb_thrift_t *thft, fb_thrift_type_t *type, - guint *size); +/** + * fb_thrift_read_set: + * @thft: The #FbThrift. + * @type: The return location for the #FbThriftType. + * @size: The return location for the size. + * + * Reads a set header from the #FbThrift. + * + * Returns: #TRUE if the set header was read, otherwise #FALSE. + */ +gboolean +fb_thrift_read_set(FbThrift *thft, FbThriftType *type, guint *size); -void fb_thrift_write(fb_thrift_t *thft, gconstpointer data, guint size); +/** + * fb_thrift_write: + * @thft: The #FbThrift. + * @data: The data buffer. + * @size: The size of @buffer. + * + * Writes data to the #FbThrift. + */ +void +fb_thrift_write(FbThrift *thft, gconstpointer data, guint size); -void fb_thrift_write_bool(fb_thrift_t *thft, gboolean bln); +/** + * fb_thrift_write_bool: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a boolean value to the #FbThrift. + */ +void +fb_thrift_write_bool(FbThrift *thft, gboolean value); -void fb_thrift_write_byte(fb_thrift_t *thft, guint8 byte); +/** + * fb_thrift_write_byte: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes an 8-bit integer value to the #FbThrift. + */ +void +fb_thrift_write_byte(FbThrift *thft, guint8 value); -void fb_thrift_write_dbl(fb_thrift_t *thft, gdouble dbl); +/** + * fb_thrift_write_dbl: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a 64-bit floating point value to the #FbThrift. + */ +void +fb_thrift_write_dbl(FbThrift *thft, gdouble value); -void fb_thrift_write_i16(fb_thrift_t *thft, gint16 i16); +/** + * fb_thrift_write_i16: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a signed 16-bit integer value to the #FbThrift. This will + * convert the integer to the zig-zag format. + */ +void +fb_thrift_write_i16(FbThrift *thft, gint16 value); -void fb_thrift_write_vi16(fb_thrift_t *thft, guint16 u16); +/** + * fb_thrift_write_vi16: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a 16-bit integer value to the #FbThrift. This writes the raw + * integer value without converting it to the zig-zag format. + */ +void +fb_thrift_write_vi16(FbThrift *thft, guint16 value); -void fb_thrift_write_i32(fb_thrift_t *thft, gint32 i32); +/** + * fb_thrift_write_i32: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a signed 32-bit integer value to the #FbThrift. This will + * convert the integer to the zig-zag format. + */ +void +fb_thrift_write_i32(FbThrift *thft, gint32 value); -void fb_thrift_write_vi32(fb_thrift_t *thft, guint32 u32); +/** + * fb_thrift_write_vi32: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a 32-bit integer value to the #FbThrift. This writes the raw + * integer value without converting it to the zig-zag format. + */ +void +fb_thrift_write_vi32(FbThrift *thft, guint32 value); -void fb_thrift_write_i64(fb_thrift_t *thft, gint64 i64); +/** + * fb_thrift_write_i64: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a signed 64-bit integer value to the #FbThrift. This will + * convert the integer to the zig-zag format. + */ +void +fb_thrift_write_i64(FbThrift *thft, gint64 value); -void fb_thrift_write_vi64(fb_thrift_t *thft, guint64 u64); +/** + * fb_thrift_write_vi64: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a 64-bit integer value to the #FbThrift. This writes the raw + * integer value without converting it to the zig-zag format. + */ +void +fb_thrift_write_vi64(FbThrift *thft, guint64 value); -void fb_thrift_write_str(fb_thrift_t *thft, const gchar *str); +/** + * fb_thrift_write_str: + * @thft: The #FbThrift. + * @value: The value. + * + * Writes a string value to the #FbThrift. + */ +void +fb_thrift_write_str(FbThrift *thft, const gchar *value); -void fb_thrift_write_field(fb_thrift_t *thft, fb_thrift_type_t type, - gint16 id); +/** + * fb_thrift_write_field: + * @thft: The #FbThrift. + * @type: The #FbThriftType. + * @id: The identifier. + * + * Writes a field header to the #FbThrift. + */ +void +fb_thrift_write_field(FbThrift *thft, FbThriftType type, gint16 id); -void fb_thrift_write_stop(fb_thrift_t *thft); +/** + * fb_thrift_write_stop: + * @thft: The #FbThrift. + * + * Writes a field stop to the #FbThrift. + */ +void +fb_thrift_write_stop(FbThrift *thft); -void fb_thrift_write_list(fb_thrift_t *thft, fb_thrift_type_t type, - guint size); +/** + * fb_thrift_write_list: + * @thft: The #FbThrift. + * @type: The #FbThriftType. + * @size: The size. + * + * Writes a list header to the #FbThrift. + */ +void +fb_thrift_write_list(FbThrift *thft, FbThriftType type, guint size); -void fb_thrift_write_map(fb_thrift_t *thft, fb_thrift_type_t ktype, - fb_thrift_type_t vtype, guint size); +/** + * fb_thrift_write_map: + * @thft: The #FbThrift. + * @ktype: The key #FbThriftType. + * @vtype: The value #FbThriftType. + * @size: The size. + * + * Writes a map header to the #FbThrift. + */ +void +fb_thrift_write_map(FbThrift *thft, FbThriftType ktype, FbThriftType vtype, + guint size); -void fb_thrift_write_set(fb_thrift_t *thft, fb_thrift_type_t type, - guint size); +/** + * fb_thrift_write_set: + * @thft: The #FbThrift. + * @type: The #FbThriftType. + * @size: The size. + * + * Writes a set header to the #FbThrift. + */ +void +fb_thrift_write_set(FbThrift *thft, FbThriftType type, guint size); -guint8 fb_thrift_t2ct(fb_thrift_type_t type); +/** + * fb_thrift_t2ct: + * @type: The #FbThriftType. + * + * Converts a #FbThriftType to a compact type. + * + * Return: The equivalent compact type. + */ +guint8 +fb_thrift_t2ct(FbThriftType type); -fb_thrift_type_t fb_thrift_ct2t(guint8 type); +/** + * fb_thrift_ct2t: + * @type: The compact type. + * + * Converts a compact type to an #FbThriftType. + * + * Return: The equivalent #FbThriftType. + */ +FbThriftType +fb_thrift_ct2t(guint8 type); -#endif /* _FACEBOOK_THRIFT_H */ +#endif /* _FACEBOOK_THRIFT_H_ */ |