/* Generated by Cython 0.11.2 on Sat Jun 13 13:17:33 2009 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
       void *buf;
       PyObject *obj;
       Py_ssize_t len;
       Py_ssize_t itemsize;
       int readonly;
       int ndim;
       char *format;
       Py_ssize_t *shape;
       Py_ssize_t *strides;
       Py_ssize_t *suboffsets;
       void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyBytes_Type
  #define PyString_CheckExact          PyBytes_CheckExact
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define PyBytes_Type                 PyString_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__cpyamf__util
#include "stdlib.h"
#include "stdio.h"
#define __PYX_USE_C99_COMPLEX defined(_Complex_I)


#ifdef __GNUC__
#define INLINE __inline__
#elif _WIN32
#define INLINE __inline
#else
#define INLINE 
#endif

typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/



static int __pyx_skip_dispatch = 0;


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;

static char __pyx_mdoc[] = "\nC-extension for L{pyamf.util} Python module in L{PyAMF<pyamf>}.\n\n@since: 0.4\n";


#ifdef CYTHON_REFNANNY
typedef struct {
  void (*INCREF)(void*, PyObject*, int);
  void (*DECREF)(void*, PyObject*, int);
  void (*GOTREF)(void*, PyObject*, int);
  void (*GIVEREF)(void*, PyObject*, int);
  void* (*NewContext)(const char*, int, const char*);
  void (*FinishContext)(void**);
} __Pyx_RefnannyAPIStruct;
static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL;
#define __Pyx_ImportRefcountAPI(name)   (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI")
#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r)
#define __Pyx_SetupRefcountContext(name)   void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__)
#define __Pyx_FinishRefcountContext()   __Pyx_Refnanny->FinishContext(&__pyx_refchk)
#else
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_SetupRefcountContext(name)
#define __Pyx_FinishRefcountContext()
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r)
#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r)

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
    const char* function_name, int kw_allowed); /*proto*/

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/

static int __Pyx_Print(PyObject *, int); /*proto*/
#if PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

static int __Pyx_PrintOne(PyObject *o); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static INLINE char __Pyx_PyInt_AsChar(PyObject *);

static INLINE short __Pyx_PyInt_AsShort(PyObject *);

static INLINE int __Pyx_PyInt_AsInt(PyObject *);

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static INLINE long __Pyx_PyInt_AsLong(PyObject *);

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

/* Type declarations */

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pxd":26
 *     cdef int at_eof(self) except? -1
 *     cdef inline Py_ssize_t remaining(self) except? -1
 *     cdef int seek(self, Py_ssize_t pos, int mode=*) except? -1             # <<<<<<<<<<<<<<
 *     cdef object getvalue(self)
 *     cdef int peek(self, char **buf, Py_ssize_t size) except? -1
 */

struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek {
  int __pyx_n;
  int mode;
};

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pxd":9
 * 
 * 
 * cdef class cBufferedByteStream:             # <<<<<<<<<<<<<<
 *     cdef char _endian
 *     cdef char *buffer
 */

struct __pyx_obj_6cpyamf_4util_cBufferedByteStream {
  PyObject_HEAD
  struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *__pyx_vtab;
  char _endian;
  char *buffer;
  int closed;
  Py_ssize_t pos;
  Py_ssize_t size;
  Py_ssize_t length;
};

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1022
 * 
 * 
 * cdef class BufferedByteStream(cBufferedByteStream):             # <<<<<<<<<<<<<<
 *     """
 *     An extension of C{StringIO}.
 */

struct __pyx_obj_6cpyamf_4util_BufferedByteStream {
  struct __pyx_obj_6cpyamf_4util_cBufferedByteStream __pyx_base;
};


/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":255
 * 
 * 
 * cdef class cBufferedByteStream:             # <<<<<<<<<<<<<<
 *     def __cinit__(self):
 *         if complete_init == 0:
 */

struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream {
  Py_ssize_t (*tell)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*close)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*write)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char *, Py_ssize_t);
  int (*complain_if_closed)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*_increase_buffer)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t);
  int (*has_available)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t);
  int (*read)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char **, Py_ssize_t);
  int (*at_eof)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  Py_ssize_t (*remaining)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*seek)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t, struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek *__pyx_optional_args);
  PyObject *(*getvalue)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*peek)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char **, Py_ssize_t);
  int (*truncate)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t);
  int (*consume)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *);
  int (*unpack_int)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, long *);
  int (*unpack_uint)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, unsigned long *);
  int (*pack_int)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, long);
  int (*pack_uint)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, unsigned long);
  int (*read_uchar)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned char *);
  int (*read_char)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char *);
  int (*read_ushort)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned short *);
  int (*read_short)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, short *);
  int (*read_ulong)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long *);
  int (*read_long)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long *);
  int (*read_24bit_uint)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long *);
  int (*read_24bit_int)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long *);
  int (*write_uchar)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned char);
  int (*write_char)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char);
  int (*write_ushort)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned short);
  int (*write_short)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, short);
  int (*write_ulong)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long);
  int (*write_long)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long);
  int (*write_24bit_uint)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long);
  int (*write_24bit_int)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long);
  PyObject *(*read_utf8_string)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned int);
  int (*write_utf8_string)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, PyObject *);
  int (*read_double)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, double *);
  int (*write_double)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, double);
  int (*read_float)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, float *);
  int (*write_float)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, float);
  int (*append)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, PyObject *);
};
static struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *__pyx_vtabptr_6cpyamf_4util_cBufferedByteStream;


/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1022
 * 
 * 
 * cdef class BufferedByteStream(cBufferedByteStream):             # <<<<<<<<<<<<<<
 *     """
 *     An extension of C{StringIO}.
 */

struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream {
  struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream __pyx_base;
};
static struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *__pyx_vtabptr_6cpyamf_4util_BufferedByteStream;
/* Module declarations from cpyamf.util */

static PyTypeObject *__pyx_ptype_6cpyamf_4util_cBufferedByteStream = 0;
static PyTypeObject *__pyx_ptype_6cpyamf_4util_BufferedByteStream = 0;
static char __pyx_v_6cpyamf_4util_SYSTEM_ENDIAN;
static int __pyx_v_6cpyamf_4util_float_broken;
static int __pyx_v_6cpyamf_4util_complete_init;
static unsigned char *__pyx_v_6cpyamf_4util_NaN;
static unsigned char *__pyx_v_6cpyamf_4util_NegInf;
static unsigned char *__pyx_v_6cpyamf_4util_PosInf;
static double __pyx_v_6cpyamf_4util_system_nan;
static double __pyx_v_6cpyamf_4util_system_posinf;
static double __pyx_v_6cpyamf_4util_system_neginf;
static double __pyx_v_6cpyamf_4util_platform_nan;
static double __pyx_v_6cpyamf_4util_platform_posinf;
static double __pyx_v_6cpyamf_4util_platform_neginf;
static PyObject *__pyx_v_6cpyamf_4util_pyamf_NaN = 0;
static PyObject *__pyx_v_6cpyamf_4util_pyamf_NegInf = 0;
static PyObject *__pyx_v_6cpyamf_4util_pyamf_PosInf = 0;
static int __pyx_f_6cpyamf_4util_dump(void *, int); /*proto*/
static int __pyx_f_6cpyamf_4util_build_platform_exceptional_floats(void); /*proto*/
static int __pyx_f_6cpyamf_4util_complete_import(void); /*proto*/
static char __pyx_f_6cpyamf_4util_get_native_endian(void); /*proto*/
static INLINE int __pyx_f_6cpyamf_4util_is_big_endian(char); /*proto*/
static INLINE int __pyx_f_6cpyamf_4util_is_native_endian(char); /*proto*/
static INLINE int __pyx_f_6cpyamf_4util_swap_bytes(unsigned char *, Py_ssize_t); /*proto*/
static int __pyx_f_6cpyamf_4util_is_broken_float(void); /*proto*/
#define __Pyx_MODULE_NAME "cpyamf.util"
int __pyx_module_is_main_cpyamf__util = 0;

/* Implementation of cpyamf.util */
static char __pyx_k_9[] = "\377\370\000\000\000\000\000\000";
static char __pyx_k_10[] = "\377\360\000\000\000\000\000\000";
static char __pyx_k_11[] = "\360\000\000\000\000\000\000";
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_4294967295L;
static PyObject *__pyx_int_2;
static char __pyx_k___main__[] = "__main__";
static PyObject *__pyx_kp___main__;
static char __pyx_k___cinit__[] = "__cinit__";
static PyObject *__pyx_kp___cinit__;
static char __pyx_k___dealloc__[] = "__dealloc__";
static PyObject *__pyx_kp___dealloc__;
static char __pyx_k___init__[] = "__init__";
static PyObject *__pyx_kp___init__;
static char __pyx_k_read[] = "read";
static PyObject *__pyx_kp_read;
static char __pyx_k_write[] = "write";
static PyObject *__pyx_kp_write;
static char __pyx_k_close[] = "close";
static PyObject *__pyx_kp_close;
static char __pyx_k_flush[] = "flush";
static PyObject *__pyx_kp_flush;
static char __pyx_k_tell[] = "tell";
static PyObject *__pyx_kp_tell;
static char __pyx_k_remaining[] = "remaining";
static PyObject *__pyx_kp_remaining;
static char __pyx_k___len__[] = "__len__";
static PyObject *__pyx_kp___len__;
static char __pyx_k_getvalue[] = "getvalue";
static PyObject *__pyx_kp_getvalue;
static char __pyx_k_at_eof[] = "at_eof";
static PyObject *__pyx_kp_at_eof;
static char __pyx_k_seek[] = "seek";
static PyObject *__pyx_kp_seek;
static char __pyx_k_peek[] = "peek";
static PyObject *__pyx_kp_peek;
static char __pyx_k_truncate[] = "truncate";
static PyObject *__pyx_kp_truncate;
static char __pyx_k_consume[] = "consume";
static PyObject *__pyx_kp_consume;
static char __pyx_k_read_uchar[] = "read_uchar";
static PyObject *__pyx_kp_read_uchar;
static char __pyx_k_read_char[] = "read_char";
static PyObject *__pyx_kp_read_char;
static char __pyx_k_read_ushort[] = "read_ushort";
static PyObject *__pyx_kp_read_ushort;
static char __pyx_k_read_short[] = "read_short";
static PyObject *__pyx_kp_read_short;
static char __pyx_k_read_ulong[] = "read_ulong";
static PyObject *__pyx_kp_read_ulong;
static char __pyx_k_read_long[] = "read_long";
static PyObject *__pyx_kp_read_long;
static char __pyx_k_3[] = "read_24bit_uint";
static PyObject *__pyx_kp_3;
static char __pyx_k_4[] = "read_24bit_int";
static PyObject *__pyx_kp_4;
static char __pyx_k_write_uchar[] = "write_uchar";
static PyObject *__pyx_kp_write_uchar;
static char __pyx_k_write_char[] = "write_char";
static PyObject *__pyx_kp_write_char;
static char __pyx_k_write_ushort[] = "write_ushort";
static PyObject *__pyx_kp_write_ushort;
static char __pyx_k_write_short[] = "write_short";
static PyObject *__pyx_kp_write_short;
static char __pyx_k_write_ulong[] = "write_ulong";
static PyObject *__pyx_kp_write_ulong;
static char __pyx_k_write_long[] = "write_long";
static PyObject *__pyx_kp_write_long;
static char __pyx_k_5[] = "write_24bit_uint";
static PyObject *__pyx_kp_5;
static char __pyx_k_6[] = "write_24bit_int";
static PyObject *__pyx_kp_6;
static char __pyx_k_7[] = "read_utf8_string";
static PyObject *__pyx_kp_7;
static char __pyx_k_8[] = "write_utf8_string";
static PyObject *__pyx_kp_8;
static char __pyx_k_read_double[] = "read_double";
static PyObject *__pyx_kp_read_double;
static char __pyx_k_write_double[] = "write_double";
static PyObject *__pyx_kp_write_double;
static char __pyx_k_read_float[] = "read_float";
static PyObject *__pyx_kp_read_float;
static char __pyx_k_write_float[] = "write_float";
static PyObject *__pyx_kp_write_float;
static char __pyx_k_append[] = "append";
static PyObject *__pyx_kp_append;
static char __pyx_k___add__[] = "__add__";
static PyObject *__pyx_kp___add__;
static char __pyx_k___str__[] = "__str__";
static PyObject *__pyx_kp___str__;
static char __pyx_k_buf[] = "buf";
static PyObject *__pyx_kp_buf;
static char __pyx_k_value[] = "value";
static PyObject *__pyx_kp_value;
static char __pyx_k_size[] = "size";
static PyObject *__pyx_kp_size;
static char __pyx_k_x[] = "x";
static PyObject *__pyx_kp_x;
static char __pyx_k_pos[] = "pos";
static PyObject *__pyx_kp_pos;
static char __pyx_k_mode[] = "mode";
static PyObject *__pyx_kp_mode;
static char __pyx_k_obj[] = "obj";
static PyObject *__pyx_kp_obj;
static char __pyx_k_val[] = "val";
static PyObject *__pyx_kp_val;
static char __pyx_k_data[] = "data";
static PyObject *__pyx_kp_data;
static char __pyx_k_self[] = "self";
static PyObject *__pyx_kp_self;
static char __pyx_k_other[] = "other";
static PyObject *__pyx_kp_other;
static char __pyx_k_MemoryError[] = "MemoryError";
static PyObject *__pyx_kp_MemoryError;
static char __pyx_k_pyamf[] = "pyamf";
static PyObject *__pyx_kp_pyamf;
static char __pyx_k_util[] = "util";
static PyObject *__pyx_kp_util;
static char __pyx_k_NaN[] = "NaN";
static PyObject *__pyx_kp_NaN;
static char __pyx_k_NegInf[] = "NegInf";
static PyObject *__pyx_kp_NegInf;
static char __pyx_k_PosInf[] = "PosInf";
static PyObject *__pyx_kp_PosInf;
static char __pyx_k_IOError[] = "IOError";
static PyObject *__pyx_kp_IOError;
static char __pyx_k_ValueError[] = "ValueError";
static PyObject *__pyx_kp_ValueError;
static char __pyx_k_OverflowError[] = "OverflowError";
static PyObject *__pyx_kp_OverflowError;
static char __pyx_k_TypeError[] = "TypeError";
static PyObject *__pyx_kp_TypeError;
static char __pyx_k_29[] = "getvalue";
static PyObject *__pyx_kp_29;
static char __pyx_k_30[] = "getvalue";
static PyObject *__pyx_kp_30;
static char __pyx_k_31[] = "read";
static PyObject *__pyx_kp_31;
static char __pyx_k_32[] = "seek";
static PyObject *__pyx_kp_32;
static char __pyx_k_33[] = "tell";
static PyObject *__pyx_kp_33;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_builtin_TypeError;
static char __pyx_k_12[] = ">";
static char __pyx_k_13[] = "<";
static char __pyx_k_14[] = "@";
static char __pyx_k_15[] = ">";
static char __pyx_k_16[] = "!";
static char __pyx_k_17[] = ">";
static char __pyx_k_18[] = "@";
static char __pyx_k_19[] = "!";
static char __pyx_k_20[] = ">";
static char __pyx_k_21[] = "!";
static PyObject *__pyx_kp_22;
static char __pyx_k_22[] = "Buffer closed";
static PyObject *__pyx_kp_23;
static char __pyx_k_23[] = "Bad value for mode";
static PyObject *__pyx_kp_24;
static char __pyx_k_24[] = "integer out of range";
static PyObject *__pyx_kp_25;
static char __pyx_k_25[] = "integer out of range";
static PyObject *__pyx_kp_26;
static char __pyx_k_26[] = "";
static char __pyx_k_27[] = "strict";
static PyObject *__pyx_kp_28;
static char __pyx_k_28[] = "value must be Unicode or str";
static PyObject *__pyx_kp_34;
static char __pyx_k_34[] = "Unable to coerce buf->StringIO";
static PyObject *__pyx_kp_35;
static PyObject *__pyx_kp_36;
static PyObject *__pyx_kp_37;
static PyObject *__pyx_kp_38;
static PyObject *__pyx_kp_39;
static PyObject *__pyx_kp_40;
static char __pyx_k_35[] = "String value expected";
static char __pyx_k_36[] = "!";
static char __pyx_k_37[] = "@";
static char __pyx_k_38[] = "<";
static char __pyx_k_39[] = ">";
static char __pyx_k_40[] = "Not a valid endian type";
static PyObject *__pyx_kp_41;
static char __pyx_k_41[] = "expected int for x";
static PyObject *__pyx_kp_42;
static char __pyx_k_42[] = "expected int for x";
static PyObject *__pyx_kp_43;
static char __pyx_k_43[] = "expected int for x";
static PyObject *__pyx_kp_44;
static char __pyx_k_44[] = "expected int for x";
static PyObject *__pyx_kp_45;
static char __pyx_k_45[] = "expected int for x";
static PyObject *__pyx_kp_46;
static char __pyx_k_46[] = "Expecting float for val";
static PyObject *__pyx_kp_47;
static char __pyx_k_47[] = "Expecting float for val";

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":98
 * 
 * 
 * cdef int dump(void *p, int size):             # <<<<<<<<<<<<<<
 *     cdef int i
 *     cdef unsigned char *buf
 */

static  int __pyx_f_6cpyamf_4util_dump(void *__pyx_v_p, int __pyx_v_size) {
  int __pyx_v_i;
  unsigned char *__pyx_v_buf;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_SetupRefcountContext("dump");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":102
 *     cdef unsigned char *buf
 * 
 *     buf = <unsigned char *>p             # <<<<<<<<<<<<<<
 * 
 *     for i from 0 <= i < size:
 */
  __pyx_v_buf = ((unsigned char *)__pyx_v_p);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":104
 *     buf = <unsigned char *>p
 * 
 *     for i from 0 <= i < size:             # <<<<<<<<<<<<<<
 *         print buf[i]
 * 
 */
  __pyx_t_1 = __pyx_v_size;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":105
 * 
 *     for i from 0 <= i < size:
 *         print buf[i]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = PyInt_FromLong((__pyx_v_buf[__pyx_v_i])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_PrintOne(__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("cpyamf.util.dump");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":108
 * 
 * 
 * cdef int build_platform_exceptional_floats() except? -1:             # <<<<<<<<<<<<<<
 *     global platform_nan, platform_posinf, platform_neginf
 *     global system_nan, system_posinf, system_neginf
 */

static  int __pyx_f_6cpyamf_4util_build_platform_exceptional_floats(void) {
  unsigned char *__pyx_v_buf;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("build_platform_exceptional_floats");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":112
 *     global system_nan, system_posinf, system_neginf
 * 
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * sizeof(double))             # <<<<<<<<<<<<<<
 * 
 *     if buf == NULL:
 */
  __pyx_v_buf = ((unsigned char *)PyMem_Malloc(((sizeof(unsigned char *)) * (sizeof(double)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":114
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * sizeof(double))
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_buf == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":115
 * 
 *     if buf == NULL:
 *         raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *     memcpy(buf, NaN, 8)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":117
 *         raise MemoryError
 * 
 *     memcpy(buf, NaN, 8)             # <<<<<<<<<<<<<<
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 */
  memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_NaN, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":119
 *     memcpy(buf, NaN, 8)
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *         swap_bytes(buf, 8)
 * 
 */
  __pyx_t_1 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN));
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":120
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 *         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     memcpy(&system_nan, buf, 8)
 */
    __pyx_t_2 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":122
 *         swap_bytes(buf, 8)
 * 
 *     memcpy(&system_nan, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     memcpy(buf, NegInf, 8)
 */
  memcpy((&__pyx_v_6cpyamf_4util_system_nan), __pyx_v_buf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":124
 *     memcpy(&system_nan, buf, 8)
 * 
 *     memcpy(buf, NegInf, 8)             # <<<<<<<<<<<<<<
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 */
  memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_NegInf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":126
 *     memcpy(buf, NegInf, 8)
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *         swap_bytes(buf, 8)
 * 
 */
  __pyx_t_1 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN));
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":127
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 *         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     memcpy(&system_neginf, buf, 8)
 */
    __pyx_t_2 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":129
 *         swap_bytes(buf, 8)
 * 
 *     memcpy(&system_neginf, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     memcpy(buf, PosInf, 8)
 */
  memcpy((&__pyx_v_6cpyamf_4util_system_neginf), __pyx_v_buf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":131
 *     memcpy(&system_neginf, buf, 8)
 * 
 *     memcpy(buf, PosInf, 8)             # <<<<<<<<<<<<<<
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 */
  memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_PosInf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":133
 *     memcpy(buf, PosInf, 8)
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *         swap_bytes(buf, 8)
 * 
 */
  __pyx_t_1 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN));
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":134
 * 
 *     if not is_big_endian(SYSTEM_ENDIAN):
 *         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     memcpy(&system_posinf, buf, 8)
 */
    __pyx_t_2 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":136
 *         swap_bytes(buf, 8)
 * 
 *     memcpy(&system_posinf, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     if float_broken == 1:
 */
  memcpy((&__pyx_v_6cpyamf_4util_system_posinf), __pyx_v_buf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":138
 *     memcpy(&system_posinf, buf, 8)
 * 
 *     if float_broken == 1:             # <<<<<<<<<<<<<<
 *         if _PyFloat_Unpack8(<unsigned char *>&NaN, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 *             PyMem_Free(buf)
 */
  __pyx_t_1 = (__pyx_v_6cpyamf_4util_float_broken == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":139
 * 
 *     if float_broken == 1:
 *         if _PyFloat_Unpack8(<unsigned char *>&NaN, not is_big_endian(SYSTEM_ENDIAN)) == -1:             # <<<<<<<<<<<<<<
 *             PyMem_Free(buf)
 * 
 */
    __pyx_t_1 = (_PyFloat_Unpack8(((unsigned char *)(&__pyx_v_6cpyamf_4util_NaN)), (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN))) == -1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":140
 *     if float_broken == 1:
 *         if _PyFloat_Unpack8(<unsigned char *>&NaN, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
      PyMem_Free(__pyx_v_buf);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":142
 *             PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         memcpy(&platform_nan, buf, 8)
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":144
 *             return -1
 * 
 *         memcpy(&platform_nan, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&PosInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 */
    memcpy((&__pyx_v_6cpyamf_4util_platform_nan), __pyx_v_buf, 8);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":146
 *         memcpy(&platform_nan, buf, 8)
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&PosInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:             # <<<<<<<<<<<<<<
 *             PyMem_Free(buf)
 * 
 */
    __pyx_t_1 = (_PyFloat_Unpack8(((unsigned char *)(&__pyx_v_6cpyamf_4util_PosInf)), (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN))) == -1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":147
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&PosInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
      PyMem_Free(__pyx_v_buf);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":149
 *             PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         memcpy(&platform_posinf, buf, 8)
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":151
 *             return -1
 * 
 *         memcpy(&platform_posinf, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&NegInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 */
    memcpy((&__pyx_v_6cpyamf_4util_platform_posinf), __pyx_v_buf, 8);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":153
 *         memcpy(&platform_posinf, buf, 8)
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&NegInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:             # <<<<<<<<<<<<<<
 *             PyMem_Free(buf)
 * 
 */
    __pyx_t_1 = (_PyFloat_Unpack8(((unsigned char *)(&__pyx_v_6cpyamf_4util_NegInf)), (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN))) == -1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":154
 * 
 *         if _PyFloat_Unpack8(<unsigned char *>&NegInf, not is_big_endian(SYSTEM_ENDIAN)) == -1:
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
      PyMem_Free(__pyx_v_buf);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":156
 *             PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         memcpy(&platform_neginf, buf, 8)
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":158
 *             return -1
 * 
 *         memcpy(&platform_neginf, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     PyMem_Free(buf)
 */
    memcpy((&__pyx_v_6cpyamf_4util_platform_neginf), __pyx_v_buf, 8);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":160
 *         memcpy(&platform_neginf, buf, 8)
 * 
 *     PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  PyMem_Free(__pyx_v_buf);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.build_platform_exceptional_floats");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":163
 * 
 * 
 * cdef int complete_import() except? -1:             # <<<<<<<<<<<<<<
 *     """
 *     This function is internal - do not call it yourself. It is used to
 */

static  int __pyx_f_6cpyamf_4util_complete_import(void) {
  PyObject *__pyx_v_SYSTEM_ENDIAN;
  PyObject *__pyx_v_util;
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("complete_import");
  __pyx_v_SYSTEM_ENDIAN = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_util = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":171
 *     global pyamf_NaN, pyamf_NegInf, pyamf_PosInf
 * 
 *     complete_init = 1             # <<<<<<<<<<<<<<
 * 
 *     SYSTEM_ENDIAN = get_native_endian()
 */
  __pyx_v_6cpyamf_4util_complete_init = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":173
 *     complete_init = 1
 * 
 *     SYSTEM_ENDIAN = get_native_endian()             # <<<<<<<<<<<<<<
 * 
 *     if is_broken_float():
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_f_6cpyamf_4util_get_native_endian()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_SYSTEM_ENDIAN);
  __pyx_v_SYSTEM_ENDIAN = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":175
 *     SYSTEM_ENDIAN = get_native_endian()
 * 
 *     if is_broken_float():             # <<<<<<<<<<<<<<
 *         float_broken = 1
 * 
 */
  __pyx_t_2 = __pyx_f_6cpyamf_4util_is_broken_float(); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":176
 * 
 *     if is_broken_float():
 *         float_broken = 1             # <<<<<<<<<<<<<<
 * 
 *     build_platform_exceptional_floats()
 */
    __pyx_v_6cpyamf_4util_float_broken = 1;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":178
 *         float_broken = 1
 * 
 *     build_platform_exceptional_floats()             # <<<<<<<<<<<<<<
 * 
 *     from pyamf import util
 */
  __pyx_t_2 = __pyx_f_6cpyamf_4util_build_platform_exceptional_floats(); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":180
 *     build_platform_exceptional_floats()
 * 
 *     from pyamf import util             # <<<<<<<<<<<<<<
 * 
 *     pyamf_NaN = util.NaN
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_kp_util);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_util);
  __Pyx_GIVEREF(__pyx_kp_util);
  __pyx_1 = __Pyx_Import(__pyx_kp_pyamf, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_util); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_2);
  __Pyx_DECREF(__pyx_v_util);
  __pyx_v_util = __pyx_2;
  __pyx_2 = 0;
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":182
 *     from pyamf import util
 * 
 *     pyamf_NaN = util.NaN             # <<<<<<<<<<<<<<
 *     pyamf_NegInf = util.NegInf
 *     pyamf_PosInf = util.PosInf
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_util, __pyx_kp_NaN); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_6cpyamf_4util_pyamf_NaN);
  __Pyx_DECREF(__pyx_v_6cpyamf_4util_pyamf_NaN);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_v_6cpyamf_4util_pyamf_NaN = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":183
 * 
 *     pyamf_NaN = util.NaN
 *     pyamf_NegInf = util.NegInf             # <<<<<<<<<<<<<<
 *     pyamf_PosInf = util.PosInf
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_util, __pyx_kp_NegInf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_6cpyamf_4util_pyamf_NegInf);
  __Pyx_DECREF(__pyx_v_6cpyamf_4util_pyamf_NegInf);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_v_6cpyamf_4util_pyamf_NegInf = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":184
 *     pyamf_NaN = util.NaN
 *     pyamf_NegInf = util.NegInf
 *     pyamf_PosInf = util.PosInf             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_util, __pyx_kp_PosInf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_6cpyamf_4util_pyamf_PosInf);
  __Pyx_DECREF(__pyx_v_6cpyamf_4util_pyamf_PosInf);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_v_6cpyamf_4util_pyamf_PosInf = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":186
 *     pyamf_PosInf = util.PosInf
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_2);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.complete_import");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_SYSTEM_ENDIAN);
  __Pyx_DECREF(__pyx_v_util);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":189
 * 
 * 
 * cdef char get_native_endian():             # <<<<<<<<<<<<<<
 *     """
 *     A quick hack to determine the system's endian-ness ...
 */

static  char __pyx_f_6cpyamf_4util_get_native_endian(void) {
  unsigned int __pyx_v_one;
  int __pyx_v_big_endian;
  char __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("get_native_endian");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":195
 *     @return: Either L{ENDIAN_LITTLE} or L{ENDIAN_BIG}
 *     """
 *     cdef unsigned int one = 1             # <<<<<<<<<<<<<<
 *     cdef int big_endian = (<char*>&one)[0] != 1
 * 
 */
  __pyx_v_one = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":196
 *     """
 *     cdef unsigned int one = 1
 *     cdef int big_endian = (<char*>&one)[0] != 1             # <<<<<<<<<<<<<<
 * 
 *     if big_endian == 1:
 */
  __pyx_v_big_endian = ((((char *)(&__pyx_v_one))[0]) != 1);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":198
 *     cdef int big_endian = (<char*>&one)[0] != 1
 * 
 *     if big_endian == 1:             # <<<<<<<<<<<<<<
 *         return ENDIAN_BIG
 *     else:
 */
  __pyx_t_1 = (__pyx_v_big_endian == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":199
 * 
 *     if big_endian == 1:
 *         return ENDIAN_BIG             # <<<<<<<<<<<<<<
 *     else:
 *         return ENDIAN_LITTLE
 */
    __pyx_r = '>';
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":201
 *         return ENDIAN_BIG
 *     else:
 *         return ENDIAN_LITTLE             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_r = '<';
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":204
 * 
 * 
 * cdef inline int is_big_endian(char endian):             # <<<<<<<<<<<<<<
 *     """
 *     Returns a boolean value whether the supplied C{endian} is big.
 */

static INLINE int __pyx_f_6cpyamf_4util_is_big_endian(char __pyx_v_endian) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("is_big_endian");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":208
 *     Returns a boolean value whether the supplied C{endian} is big.
 *     """
 *     if endian == ENDIAN_NATIVE:             # <<<<<<<<<<<<<<
 *         return SYSTEM_ENDIAN == ENDIAN_BIG
 * 
 */
  __pyx_t_1 = (__pyx_v_endian == '@');
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":209
 *     """
 *     if endian == ENDIAN_NATIVE:
 *         return SYSTEM_ENDIAN == ENDIAN_BIG             # <<<<<<<<<<<<<<
 * 
 *     return endian == ENDIAN_NETWORK or endian == ENDIAN_BIG
 */
    __pyx_r = (__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN == '>');
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":211
 *         return SYSTEM_ENDIAN == ENDIAN_BIG
 * 
 *     return endian == ENDIAN_NETWORK or endian == ENDIAN_BIG             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (!(__pyx_v_endian == '!')) {
    __pyx_t_1 = (__pyx_v_endian == '>');
  } else {
    __pyx_t_1 = (__pyx_v_endian == '!');
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":214
 * 
 * 
 * cdef inline int is_native_endian(char endian):             # <<<<<<<<<<<<<<
 *     if endian == ENDIAN_NATIVE:
 *         return 1
 */

static INLINE int __pyx_f_6cpyamf_4util_is_native_endian(char __pyx_v_endian) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("is_native_endian");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":215
 * 
 * cdef inline int is_native_endian(char endian):
 *     if endian == ENDIAN_NATIVE:             # <<<<<<<<<<<<<<
 *         return 1
 * 
 */
  __pyx_t_1 = (__pyx_v_endian == '@');
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":216
 * cdef inline int is_native_endian(char endian):
 *     if endian == ENDIAN_NATIVE:
 *         return 1             # <<<<<<<<<<<<<<
 * 
 *     if endian == ENDIAN_NETWORK:
 */
    __pyx_r = 1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":218
 *         return 1
 * 
 *     if endian == ENDIAN_NETWORK:             # <<<<<<<<<<<<<<
 *         endian = ENDIAN_BIG
 * 
 */
  __pyx_t_1 = (__pyx_v_endian == '!');
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":219
 * 
 *     if endian == ENDIAN_NETWORK:
 *         endian = ENDIAN_BIG             # <<<<<<<<<<<<<<
 * 
 *     return endian == SYSTEM_ENDIAN
 */
    __pyx_v_endian = '>';
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":221
 *         endian = ENDIAN_BIG
 * 
 *     return endian == SYSTEM_ENDIAN             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (__pyx_v_endian == __pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":224
 * 
 * 
 * cdef inline int swap_bytes(unsigned char *buffer, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * size)
 * 
 */

static INLINE int __pyx_f_6cpyamf_4util_swap_bytes(unsigned char *__pyx_v_buffer, Py_ssize_t __pyx_v_size) {
  unsigned char *__pyx_v_buf;
  Py_ssize_t __pyx_v_i;
  int __pyx_r;
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  __Pyx_SetupRefcountContext("swap_bytes");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":225
 * 
 * cdef inline int swap_bytes(unsigned char *buffer, Py_ssize_t size) except? -1:
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * size)             # <<<<<<<<<<<<<<
 * 
 *     if buf == NULL:
 */
  __pyx_v_buf = ((unsigned char *)PyMem_Malloc(((sizeof(unsigned char *)) * __pyx_v_size)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":227
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * size)
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_buf == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":228
 * 
 *     if buf == NULL:
 *         raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *     cdef Py_ssize_t i
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":232
 *     cdef Py_ssize_t i
 * 
 *     for i from 0 <= i < size:             # <<<<<<<<<<<<<<
 *         buf[i] = buffer[size - i - 1]
 * 
 */
  __pyx_t_2 = __pyx_v_size;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":233
 * 
 *     for i from 0 <= i < size:
 *         buf[i] = buffer[size - i - 1]             # <<<<<<<<<<<<<<
 * 
 *     memcpy(buffer, buf, size)
 */
    (__pyx_v_buf[__pyx_v_i]) = (__pyx_v_buffer[((__pyx_v_size - __pyx_v_i) - 1)]);
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":235
 *         buf[i] = buffer[size - i - 1]
 * 
 *     memcpy(buffer, buf, size)             # <<<<<<<<<<<<<<
 *     PyMem_Free(buf)
 * 
 */
  memcpy(__pyx_v_buffer, __pyx_v_buf, __pyx_v_size);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":236
 * 
 *     memcpy(buffer, buf, size)
 *     PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":238
 *     PyMem_Free(buf)
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.swap_bytes");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":241
 * 
 * 
 * cdef int is_broken_float() except? -1:             # <<<<<<<<<<<<<<
 *     cdef double test = _PyFloat_Unpack8(NaN, 0)
 * 
 */

static  int __pyx_f_6cpyamf_4util_is_broken_float(void) {
  double __pyx_v_test;
  int __pyx_v_result;
  unsigned char *__pyx_v_buf;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("is_broken_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":242
 * 
 * cdef int is_broken_float() except? -1:
 *     cdef double test = _PyFloat_Unpack8(NaN, 0)             # <<<<<<<<<<<<<<
 * 
 *     cdef int result
 */
  __pyx_v_test = _PyFloat_Unpack8(__pyx_v_6cpyamf_4util_NaN, 0);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":245
 * 
 *     cdef int result
 *     cdef unsigned char *buf = <unsigned char *>&test             # <<<<<<<<<<<<<<
 * 
 *     if is_big_endian(SYSTEM_ENDIAN):
 */
  __pyx_v_buf = ((unsigned char *)(&__pyx_v_test));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":247
 *     cdef unsigned char *buf = <unsigned char *>&test
 * 
 *     if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *         swap_bytes(buf, 8)
 * 
 */
  __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":248
 * 
 *     if is_big_endian(SYSTEM_ENDIAN):
 *         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     result = memcmp(NaN, buf, 8)
 */
    __pyx_t_1 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":250
 *         swap_bytes(buf, 8)
 * 
 *     result = memcmp(NaN, buf, 8)             # <<<<<<<<<<<<<<
 * 
 *     return result != 0
 */
  __pyx_v_result = memcmp(__pyx_v_6cpyamf_4util_NaN, __pyx_v_buf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":252
 *     result = memcmp(NaN, buf, 8)
 * 
 *     return result != 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (__pyx_v_result != 0);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.is_broken_float");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":256
 * 
 * cdef class cBufferedByteStream:
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         if complete_init == 0:
 *             complete_import()
 */

static int __pyx_pf_6cpyamf_4util_19cBufferedByteStream___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6cpyamf_4util_19cBufferedByteStream___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("__cinit__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":257
 * cdef class cBufferedByteStream:
 *     def __cinit__(self):
 *         if complete_init == 0:             # <<<<<<<<<<<<<<
 *             complete_import()
 * 
 */
  __pyx_t_1 = (__pyx_v_6cpyamf_4util_complete_init == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":258
 *     def __cinit__(self):
 *         if complete_init == 0:
 *             complete_import()             # <<<<<<<<<<<<<<
 * 
 *         self._endian = ENDIAN_NETWORK
 */
    __pyx_t_2 = __pyx_f_6cpyamf_4util_complete_import(); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":260
 *             complete_import()
 * 
 *         self._endian = ENDIAN_NETWORK             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.length = 0
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->_endian = '!';

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":261
 * 
 *         self._endian = ENDIAN_NETWORK
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.length = 0
 *         self.size = 1024
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->pos = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":262
 *         self._endian = ENDIAN_NETWORK
 *         self.pos = 0
 *         self.length = 0             # <<<<<<<<<<<<<<
 *         self.size = 1024
 *         self.closed = 0
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->length = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":263
 *         self.pos = 0
 *         self.length = 0
 *         self.size = 1024             # <<<<<<<<<<<<<<
 *         self.closed = 0
 * 
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->size = 1024;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":264
 *         self.length = 0
 *         self.size = 1024
 *         self.closed = 0             # <<<<<<<<<<<<<<
 * 
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->closed = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":266
 *         self.closed = 0
 * 
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)             # <<<<<<<<<<<<<<
 * 
 *         if self.buffer == NULL:
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->buffer = ((char *)PyMem_Malloc(((sizeof(char *)) * ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->size)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":268
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 * 
 *         if self.buffer == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->buffer == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":269
 * 
 *         if self.buffer == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":271
 *             raise MemoryError
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.buffer != NULL:
 *             PyMem_Free(self.buffer)
 */

static void __pyx_pf_6cpyamf_4util_19cBufferedByteStream___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_6cpyamf_4util_19cBufferedByteStream___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("__dealloc__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":272
 * 
 *     def __dealloc__(self):
 *         if self.buffer != NULL:             # <<<<<<<<<<<<<<
 *             PyMem_Free(self.buffer)
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->buffer != NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":273
 *     def __dealloc__(self):
 *         if self.buffer != NULL:
 *             PyMem_Free(self.buffer)             # <<<<<<<<<<<<<<
 * 
 *         self.buffer = NULL
 */
    PyMem_Free(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->buffer);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":275
 *             PyMem_Free(self.buffer)
 * 
 *         self.buffer = NULL             # <<<<<<<<<<<<<<
 * 
 *     cdef int close(self) except? -1:
 */
  ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)->buffer = NULL;

  __Pyx_FinishRefcountContext();
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":277
 *         self.buffer = NULL
 * 
 *     cdef int close(self) except? -1:             # <<<<<<<<<<<<<<
 *         self.closed = 1
 * 
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_close(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  int __pyx_r;
  __Pyx_SetupRefcountContext("close");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":278
 * 
 *     cdef int close(self) except? -1:
 *         self.closed = 1             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  __pyx_v_self->closed = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":280
 *         self.closed = 1
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef inline int complain_if_closed(self) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":282
 *         return 0
 * 
 *     cdef inline int complain_if_closed(self) except? -1:             # <<<<<<<<<<<<<<
 *         if self.closed == 1:
 *             raise IOError('Buffer closed')
 */

static INLINE int __pyx_f_6cpyamf_4util_19cBufferedByteStream_complain_if_closed(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("complain_if_closed");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":283
 * 
 *     cdef inline int complain_if_closed(self) except? -1:
 *         if self.closed == 1:             # <<<<<<<<<<<<<<
 *             raise IOError('Buffer closed')
 * 
 */
  __pyx_t_1 = (__pyx_v_self->closed == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":284
 *     cdef inline int complain_if_closed(self) except? -1:
 *         if self.closed == 1:
 *             raise IOError('Buffer closed')             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_22);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_22);
    __Pyx_GIVEREF(__pyx_kp_22);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":286
 *             raise IOError('Buffer closed')
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef inline Py_ssize_t tell(self) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.complain_if_closed");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":288
 *         return 0
 * 
 *     cdef inline Py_ssize_t tell(self) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Returns the position of the stream pointer.
 */

static INLINE Py_ssize_t __pyx_f_6cpyamf_4util_19cBufferedByteStream_tell(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_SetupRefcountContext("tell");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":292
 *         Returns the position of the stream pointer.
 *         """
 *         return self.pos             # <<<<<<<<<<<<<<
 * 
 *     cdef int _increase_buffer(self, Py_ssize_t size) except? -1:
 */
  __pyx_r = __pyx_v_self->pos;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":294
 *         return self.pos
 * 
 *     cdef int _increase_buffer(self, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         cdef unsigned long new_len = self.length + size
 *         cdef unsigned long current_size = self.size
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream__increase_buffer(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, Py_ssize_t __pyx_v_size) {
  unsigned long __pyx_v_new_len;
  unsigned long __pyx_v_current_size;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("_increase_buffer");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":295
 * 
 *     cdef int _increase_buffer(self, Py_ssize_t size) except? -1:
 *         cdef unsigned long new_len = self.length + size             # <<<<<<<<<<<<<<
 *         cdef unsigned long current_size = self.size
 * 
 */
  __pyx_v_new_len = (__pyx_v_self->length + __pyx_v_size);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":296
 *     cdef int _increase_buffer(self, Py_ssize_t size) except? -1:
 *         cdef unsigned long new_len = self.length + size
 *         cdef unsigned long current_size = self.size             # <<<<<<<<<<<<<<
 * 
 *         while new_len > current_size:
 */
  __pyx_v_current_size = __pyx_v_self->size;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":298
 *         cdef unsigned long current_size = self.size
 * 
 *         while new_len > current_size:             # <<<<<<<<<<<<<<
 *             current_size *= 2
 * 
 */
  while (1) {
    __pyx_t_1 = (__pyx_v_new_len > __pyx_v_current_size);
    if (!__pyx_t_1) break;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":299
 * 
 *         while new_len > current_size:
 *             current_size *= 2             # <<<<<<<<<<<<<<
 * 
 *         if current_size != self.size:
 */
    __pyx_v_current_size *= 2;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":301
 *             current_size *= 2
 * 
 *         if current_size != self.size:             # <<<<<<<<<<<<<<
 *             self.size = current_size
 * 
 */
  __pyx_t_1 = (__pyx_v_current_size != __pyx_v_self->size);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":302
 * 
 *         if current_size != self.size:
 *             self.size = current_size             # <<<<<<<<<<<<<<
 * 
 *             self.buffer = <char *>PyMem_Realloc(self.buffer, sizeof(char *) * self.size)
 */
    __pyx_v_self->size = __pyx_v_current_size;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":304
 *             self.size = current_size
 * 
 *             self.buffer = <char *>PyMem_Realloc(self.buffer, sizeof(char *) * self.size)             # <<<<<<<<<<<<<<
 * 
 *             if self.buffer == NULL:
 */
    __pyx_v_self->buffer = ((char *)PyMem_Realloc(__pyx_v_self->buffer, ((sizeof(char *)) * __pyx_v_self->size)));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":306
 *             self.buffer = <char *>PyMem_Realloc(self.buffer, sizeof(char *) * self.size)
 * 
 *             if self.buffer == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 * 
 */
    __pyx_t_1 = (__pyx_v_self->buffer == NULL);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":307
 * 
 *             if self.buffer == NULL:
 *                 raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
      __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":309
 *                 raise MemoryError
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int write(self, char *buf, Py_ssize_t size) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream._increase_buffer");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":311
 *         return 0
 * 
 *     cdef int write(self, char *buf, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes the content of the specified C{buf} into this buffer.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, char *__pyx_v_buf, Py_ssize_t __pyx_v_size) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("write");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":315
 *         Writes the content of the specified C{buf} into this buffer.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":316
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if size == 0:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":318
 *             return -1
 * 
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = (__pyx_v_size == 0);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":319
 * 
 *         if size == 0:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if self._increase_buffer(size) == -1:
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":321
 *             return 0
 * 
 *         if self._increase_buffer(size) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->_increase_buffer(__pyx_v_self, __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":322
 * 
 *         if self._increase_buffer(size) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         memcpy(self.buffer + self.pos, buf, size)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":324
 *             return -1
 * 
 *         memcpy(self.buffer + self.pos, buf, size)             # <<<<<<<<<<<<<<
 * 
 *         if self.pos + size > self.length:
 */
  memcpy((__pyx_v_self->buffer + __pyx_v_self->pos), __pyx_v_buf, __pyx_v_size);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":326
 *         memcpy(self.buffer + self.pos, buf, size)
 * 
 *         if self.pos + size > self.length:             # <<<<<<<<<<<<<<
 *             self.length = self.pos + size
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->pos + __pyx_v_size) > __pyx_v_self->length);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":327
 * 
 *         if self.pos + size > self.length:
 *             self.length = self.pos + size             # <<<<<<<<<<<<<<
 * 
 *         self.pos += size
 */
    __pyx_v_self->length = (__pyx_v_self->pos + __pyx_v_size);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":329
 *             self.length = self.pos + size
 * 
 *         self.pos += size             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  __pyx_v_self->pos += __pyx_v_size;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":331
 *         self.pos += size
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef inline int has_available(self, Py_ssize_t size) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":333
 *         return 0
 * 
 *     cdef inline int has_available(self, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         if size == 0:
 *             return 0
 */

static INLINE int __pyx_f_6cpyamf_4util_19cBufferedByteStream_has_available(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, Py_ssize_t __pyx_v_size) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("has_available");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":334
 * 
 *     cdef inline int has_available(self, Py_ssize_t size) except? -1:
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = (__pyx_v_size == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":335
 *     cdef inline int has_available(self, Py_ssize_t size) except? -1:
 *         if size == 0:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if self.length == self.pos:
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":337
 *             return 0
 * 
 *         if self.length == self.pos:             # <<<<<<<<<<<<<<
 *             raise IOError
 * 
 */
  __pyx_t_1 = (__pyx_v_self->length == __pyx_v_self->pos);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":338
 * 
 *         if self.length == self.pos:
 *             raise IOError             # <<<<<<<<<<<<<<
 * 
 *         if self.pos + size > self.length:
 */
    __Pyx_Raise(__pyx_builtin_IOError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":340
 *             raise IOError
 * 
 *         if self.pos + size > self.length:             # <<<<<<<<<<<<<<
 *             if size == 1:
 *                 raise IOError
 */
  __pyx_t_1 = ((__pyx_v_self->pos + __pyx_v_size) > __pyx_v_self->length);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":341
 * 
 *         if self.pos + size > self.length:
 *             if size == 1:             # <<<<<<<<<<<<<<
 *                 raise IOError
 * 
 */
    __pyx_t_1 = (__pyx_v_size == 1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":342
 *         if self.pos + size > self.length:
 *             if size == 1:
 *                 raise IOError             # <<<<<<<<<<<<<<
 * 
 *             raise IOError
 */
      __Pyx_Raise(__pyx_builtin_IOError, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":344
 *                 raise IOError
 * 
 *             raise IOError             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __Pyx_Raise(__pyx_builtin_IOError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":346
 *             raise IOError
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int read(self, char **buf, Py_ssize_t size) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.has_available");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":348
 *         return 0
 * 
 *     cdef int read(self, char **buf, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads up to the specified number of bytes from the stream into
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, char **__pyx_v_buf, Py_ssize_t __pyx_v_size) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  __Pyx_SetupRefcountContext("read");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":353
 *         the specified byte array of specified length.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":354
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if size == -1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":356
 *             return -1
 * 
 *         if size == -1:             # <<<<<<<<<<<<<<
 *             size = self.remaining()
 * 
 */
  __pyx_t_2 = (__pyx_v_size == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":357
 * 
 *         if size == -1:
 *             size = self.remaining()             # <<<<<<<<<<<<<<
 * 
 *             if size == 0:
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->remaining(__pyx_v_self); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_size = __pyx_t_3;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":359
 *             size = self.remaining()
 * 
 *             if size == 0:             # <<<<<<<<<<<<<<
 *                 size = 1
 * 
 */
    __pyx_t_2 = (__pyx_v_size == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":360
 * 
 *             if size == 0:
 *                 size = 1             # <<<<<<<<<<<<<<
 * 
 *         if self.has_available(size) == -1:
 */
      __pyx_v_size = 1;
      goto __pyx_L5;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":362
 *                 size = 1
 * 
 *         if self.has_available(size) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->has_available(__pyx_v_self, __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":363
 * 
 *         if self.has_available(size) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         buf[0] = <char *>PyMem_Malloc(sizeof(char *) * size)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":365
 *             return -1
 * 
 *         buf[0] = <char *>PyMem_Malloc(sizeof(char *) * size)             # <<<<<<<<<<<<<<
 * 
 *         if buf[0] == NULL:
 */
  (__pyx_v_buf[0]) = ((char *)PyMem_Malloc(((sizeof(char *)) * __pyx_v_size)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":367
 *         buf[0] = <char *>PyMem_Malloc(sizeof(char *) * size)
 * 
 *         if buf[0] == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_2 = ((__pyx_v_buf[0]) == NULL);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":368
 * 
 *         if buf[0] == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":370
 *             raise MemoryError
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         memcpy(buf[0], self.buffer + self.pos, size)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":372
 *             return -1
 * 
 *         memcpy(buf[0], self.buffer + self.pos, size)             # <<<<<<<<<<<<<<
 *         self.pos += size
 * 
 */
  memcpy((__pyx_v_buf[0]), (__pyx_v_self->buffer + __pyx_v_self->pos), __pyx_v_size);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":373
 * 
 *         memcpy(buf[0], self.buffer + self.pos, size)
 *         self.pos += size             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  __pyx_v_self->pos += __pyx_v_size;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":375
 *         self.pos += size
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef inline int at_eof(self) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":377
 *         return 0
 * 
 *     cdef inline int at_eof(self) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Returns C{True} if the internal pointer is at the end of the stream.
 */

static INLINE int __pyx_f_6cpyamf_4util_19cBufferedByteStream_at_eof(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("at_eof");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":383
 *         @rtype: C{bool}
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":384
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         return self.length == self.pos
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":386
 *             return -1
 * 
 *         return self.length == self.pos             # <<<<<<<<<<<<<<
 * 
 *     cdef inline Py_ssize_t remaining(self) except? -1:
 */
  __pyx_r = (__pyx_v_self->length == __pyx_v_self->pos);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.at_eof");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":388
 *         return self.length == self.pos
 * 
 *     cdef inline Py_ssize_t remaining(self) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Returns number of remaining bytes.
 */

static INLINE Py_ssize_t __pyx_f_6cpyamf_4util_19cBufferedByteStream_remaining(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("remaining");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":392
 *         Returns number of remaining bytes.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":393
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         return self.length - self.pos
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":395
 *             return -1
 * 
 *         return self.length - self.pos             # <<<<<<<<<<<<<<
 * 
 *     cdef int seek(self, Py_ssize_t pos, int mode=0) except? -1:
 */
  __pyx_r = (__pyx_v_self->length - __pyx_v_self->pos);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.remaining");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":397
 *         return self.length - self.pos
 * 
 *     cdef int seek(self, Py_ssize_t pos, int mode=0) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Sets the file-pointer offset, measured from the beginning of this stream,
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_seek(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, Py_ssize_t __pyx_v_pos, struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek *__pyx_optional_args) {
  int __pyx_v_mode = 0;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("seek");
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_mode = __pyx_optional_args->mode;
    }
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":407
 *         @type mode: C{int}
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":408
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if mode == 0:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":410
 *             return -1
 * 
 *         if mode == 0:             # <<<<<<<<<<<<<<
 *             if pos < 0 or pos > self.length:
 *                 raise IOError()
 */
  switch (__pyx_v_mode) {
    case 0:

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":411
 * 
 *         if mode == 0:
 *             if pos < 0 or pos > self.length:             # <<<<<<<<<<<<<<
 *                 raise IOError()
 * 
 */
    if (!(__pyx_v_pos < 0)) {
      __pyx_t_2 = (__pyx_v_pos > __pyx_v_self->length);
    } else {
      __pyx_t_2 = (__pyx_v_pos < 0);
    }
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":412
 *         if mode == 0:
 *             if pos < 0 or pos > self.length:
 *                 raise IOError()             # <<<<<<<<<<<<<<
 * 
 *             self.pos = pos
 */
      __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":414
 *                 raise IOError()
 * 
 *             self.pos = pos             # <<<<<<<<<<<<<<
 *         elif mode == 1:
 *             if pos + self.pos < 0 or pos + self.pos > self.length:
 */
    __pyx_v_self->pos = __pyx_v_pos;
    break;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":415
 * 
 *             self.pos = pos
 *         elif mode == 1:             # <<<<<<<<<<<<<<
 *             if pos + self.pos < 0 or pos + self.pos > self.length:
 *                 raise IOError()
 */
    case 1:

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":416
 *             self.pos = pos
 *         elif mode == 1:
 *             if pos + self.pos < 0 or pos + self.pos > self.length:             # <<<<<<<<<<<<<<
 *                 raise IOError()
 * 
 */
    if (!((__pyx_v_pos + __pyx_v_self->pos) < 0)) {
      __pyx_t_2 = ((__pyx_v_pos + __pyx_v_self->pos) > __pyx_v_self->length);
    } else {
      __pyx_t_2 = ((__pyx_v_pos + __pyx_v_self->pos) < 0);
    }
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":417
 *         elif mode == 1:
 *             if pos + self.pos < 0 or pos + self.pos > self.length:
 *                 raise IOError()             # <<<<<<<<<<<<<<
 * 
 *             self.pos += pos
 */
      __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":419
 *                 raise IOError()
 * 
 *             self.pos += pos             # <<<<<<<<<<<<<<
 *         elif mode == 2:
 *             if pos + self.length < 0 or pos + self.length > self.length:
 */
    __pyx_v_self->pos += __pyx_v_pos;
    break;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":420
 * 
 *             self.pos += pos
 *         elif mode == 2:             # <<<<<<<<<<<<<<
 *             if pos + self.length < 0 or pos + self.length > self.length:
 *                 raise IOError()
 */
    case 2:

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":421
 *             self.pos += pos
 *         elif mode == 2:
 *             if pos + self.length < 0 or pos + self.length > self.length:             # <<<<<<<<<<<<<<
 *                 raise IOError()
 * 
 */
    if (!((__pyx_v_pos + __pyx_v_self->length) < 0)) {
      __pyx_t_2 = ((__pyx_v_pos + __pyx_v_self->length) > __pyx_v_self->length);
    } else {
      __pyx_t_2 = ((__pyx_v_pos + __pyx_v_self->length) < 0);
    }
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":422
 *         elif mode == 2:
 *             if pos + self.length < 0 or pos + self.length > self.length:
 *                 raise IOError()             # <<<<<<<<<<<<<<
 * 
 *             self.pos = self.length + pos
 */
      __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":424
 *                 raise IOError()
 * 
 *             self.pos = self.length + pos             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('Bad value for mode')
 */
    __pyx_v_self->pos = (__pyx_v_self->length + __pyx_v_pos);
    break;
    default:

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":426
 *             self.pos = self.length + pos
 *         else:
 *             raise ValueError('Bad value for mode')             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_23);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_23);
    __Pyx_GIVEREF(__pyx_kp_23);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":428
 *             raise ValueError('Bad value for mode')
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef object getvalue(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.seek");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":430
 *         return 0
 * 
 *     cdef object getvalue(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get raw data from buffer.
 */

static  PyObject *__pyx_f_6cpyamf_4util_19cBufferedByteStream_getvalue(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("getvalue");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":434
 *         Get raw data from buffer.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":435
 *         """
 *         if self.complain_if_closed() == -1:
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         return PyString_FromStringAndSize(self.buffer, self.length)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":437
 *             return None
 * 
 *         return PyString_FromStringAndSize(self.buffer, self.length)             # <<<<<<<<<<<<<<
 * 
 *     cdef int peek(self, char **buf, Py_ssize_t size) except? -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_self->buffer, __pyx_v_self->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.getvalue");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":439
 *         return PyString_FromStringAndSize(self.buffer, self.length)
 * 
 *     cdef int peek(self, char **buf, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Looks C{size} bytes ahead in the stream, returning what it finds,
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_peek(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, char **__pyx_v_buf, Py_ssize_t __pyx_v_size) {
  Py_ssize_t __pyx_v_cur_pos;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("peek");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":444
 *         returning the stream pointer to its initial position.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":445
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef Py_ssize_t cur_pos = self.pos
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":447
 *             return -1
 * 
 *         cdef Py_ssize_t cur_pos = self.pos             # <<<<<<<<<<<<<<
 * 
 *         if self.read(buf, size) == -1:
 */
  __pyx_v_cur_pos = __pyx_v_self->pos;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":449
 *         cdef Py_ssize_t cur_pos = self.pos
 * 
 *         if self.read(buf, size) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->read(__pyx_v_self, __pyx_v_buf, __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":450
 * 
 *         if self.read(buf, size) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         self.pos = cur_pos
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":452
 *             return -1
 * 
 *         self.pos = cur_pos             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  __pyx_v_self->pos = __pyx_v_cur_pos;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":454
 *         self.pos = cur_pos
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int truncate(self, Py_ssize_t size) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.peek");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":456
 *         return 0
 * 
 *     cdef int truncate(self, Py_ssize_t size) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Truncates the stream to the specified length.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_truncate(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, Py_ssize_t __pyx_v_size) {
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_cur_pos;
  int __pyx_r;
  struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek __pyx_1;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("truncate");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":463
 *         @type size: C{int}
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":464
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if size > self.length:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":466
 *             return -1
 * 
 *         if size > self.length:             # <<<<<<<<<<<<<<
 *             raise IOError()
 * 
 */
  __pyx_t_2 = (__pyx_v_size > __pyx_v_self->length);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":467
 * 
 *         if size > self.length:
 *             raise IOError()             # <<<<<<<<<<<<<<
 * 
 *         if size == 0:
 */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":469
 *             raise IOError()
 * 
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             PyMem_Free(self.buffer)
 * 
 */
  __pyx_t_2 = (__pyx_v_size == 0);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":470
 * 
 *         if size == 0:
 *             PyMem_Free(self.buffer)             # <<<<<<<<<<<<<<
 * 
 *             self.pos = 0
 */
    PyMem_Free(__pyx_v_self->buffer);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":472
 *             PyMem_Free(self.buffer)
 * 
 *             self.pos = 0             # <<<<<<<<<<<<<<
 *             self.length = 0
 *             self.size = 1024
 */
    __pyx_v_self->pos = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":473
 * 
 *             self.pos = 0
 *             self.length = 0             # <<<<<<<<<<<<<<
 *             self.size = 1024
 * 
 */
    __pyx_v_self->length = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":474
 *             self.pos = 0
 *             self.length = 0
 *             self.size = 1024             # <<<<<<<<<<<<<<
 * 
 *             self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 */
    __pyx_v_self->size = 1024;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":476
 *             self.size = 1024
 * 
 *             self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)             # <<<<<<<<<<<<<<
 * 
 *             if self.buffer == NULL:
 */
    __pyx_v_self->buffer = ((char *)PyMem_Malloc(((sizeof(char *)) * __pyx_v_self->size)));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":478
 *             self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 * 
 *             if self.buffer == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 * 
 */
    __pyx_t_2 = (__pyx_v_self->buffer == NULL);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":479
 * 
 *             if self.buffer == NULL:
 *                 raise MemoryError()             # <<<<<<<<<<<<<<
 * 
 *             return 0
 */
      __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":481
 *                 raise MemoryError()
 * 
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":483
 *             return 0
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t cur_pos = self.pos
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":484
 * 
 *         cdef char *buf = NULL
 *         cdef Py_ssize_t cur_pos = self.pos             # <<<<<<<<<<<<<<
 * 
 *         if self.seek(0) == -1:
 */
  __pyx_v_cur_pos = __pyx_v_self->pos;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":486
 *         cdef Py_ssize_t cur_pos = self.pos
 * 
 *         if self.seek(0) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->seek(__pyx_v_self, 0, NULL); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":487
 * 
 *         if self.seek(0) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if self.peek(&buf, size) == -1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":489
 *             return -1
 * 
 *         if self.peek(&buf, size) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->peek(__pyx_v_self, (&__pyx_v_buf), __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":490
 * 
 *         if self.peek(&buf, size) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(self.buffer)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":492
 *             return -1
 * 
 *         PyMem_Free(self.buffer)             # <<<<<<<<<<<<<<
 *         self.size = 1024
 *         self.length = 0
 */
  PyMem_Free(__pyx_v_self->buffer);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":493
 * 
 *         PyMem_Free(self.buffer)
 *         self.size = 1024             # <<<<<<<<<<<<<<
 *         self.length = 0
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 */
  __pyx_v_self->size = 1024;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":494
 *         PyMem_Free(self.buffer)
 *         self.size = 1024
 *         self.length = 0             # <<<<<<<<<<<<<<
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 * 
 */
  __pyx_v_self->length = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":495
 *         self.size = 1024
 *         self.length = 0
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)             # <<<<<<<<<<<<<<
 * 
 *         if self.buffer == NULL:
 */
  __pyx_v_self->buffer = ((char *)PyMem_Malloc(((sizeof(char *)) * __pyx_v_self->size)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":497
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 * 
 *         if self.buffer == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_2 = (__pyx_v_self->buffer == NULL);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":498
 * 
 *         if self.buffer == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         if self.write(buf, size) == -1:
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":500
 *             raise MemoryError
 * 
 *         if self.write(buf, size) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_buf, __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":501
 * 
 *         if self.write(buf, size) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(buf)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":503
 *             return -1
 * 
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         if self.length > cur_pos:
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":505
 *         PyMem_Free(buf)
 * 
 *         if self.length > cur_pos:             # <<<<<<<<<<<<<<
 *             self.pos = self.length
 *         else:
 */
  __pyx_t_2 = (__pyx_v_self->length > __pyx_v_cur_pos);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":506
 * 
 *         if self.length > cur_pos:
 *             self.pos = self.length             # <<<<<<<<<<<<<<
 *         else:
 *             if self.seek(cur_pos, 0) == -1:
 */
    __pyx_v_self->pos = __pyx_v_self->length;
    goto __pyx_L11;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":508
 *             self.pos = self.length
 *         else:
 *             if self.seek(cur_pos, 0) == -1:             # <<<<<<<<<<<<<<
 *                 return -1
 * 
 */
    __pyx_1.__pyx_n = 1;
    __pyx_1.mode = 0;
    __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->seek(__pyx_v_self, __pyx_v_cur_pos, &__pyx_1); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = (__pyx_t_1 == -1);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":509
 *         else:
 *             if self.seek(cur_pos, 0) == -1:
 *                 return -1             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L12;
    }
    __pyx_L12:;
  }
  __pyx_L11:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":511
 *                 return -1
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int consume(self) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.truncate");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":513
 *         return 0
 * 
 *     cdef int consume(self) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Chops the tail off the stream starting at 0 and ending at C{tell()}.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_consume(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self) {
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_size;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  __Pyx_SetupRefcountContext("consume");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":518
 *         The stream pointer is set to 0 at the end of this function.
 *         """
 *         if self.complain_if_closed() == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->complain_if_closed(__pyx_v_self); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":519
 *         """
 *         if self.complain_if_closed() == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":521
 *             return -1
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t size = self.remaining()
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":522
 * 
 *         cdef char *buf = NULL
 *         cdef Py_ssize_t size = self.remaining()             # <<<<<<<<<<<<<<
 * 
 *         if size > 0:
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->remaining(__pyx_v_self); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_size = __pyx_t_3;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":524
 *         cdef Py_ssize_t size = self.remaining()
 * 
 *         if size > 0:             # <<<<<<<<<<<<<<
 *             if self.peek(&buf, size) == -1:
 *                 return -1
 */
  __pyx_t_2 = (__pyx_v_size > 0);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":525
 * 
 *         if size > 0:
 *             if self.peek(&buf, size) == -1:             # <<<<<<<<<<<<<<
 *                 return -1
 * 
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->peek(__pyx_v_self, (&__pyx_v_buf), __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = (__pyx_t_1 == -1);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":526
 *         if size > 0:
 *             if self.peek(&buf, size) == -1:
 *                 return -1             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(self.buffer)
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L5;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":528
 *                 return -1
 * 
 *         PyMem_Free(self.buffer)             # <<<<<<<<<<<<<<
 *         self.size = 1024
 *         self.length = 0
 */
  PyMem_Free(__pyx_v_self->buffer);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":529
 * 
 *         PyMem_Free(self.buffer)
 *         self.size = 1024             # <<<<<<<<<<<<<<
 *         self.length = 0
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 */
  __pyx_v_self->size = 1024;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":530
 *         PyMem_Free(self.buffer)
 *         self.size = 1024
 *         self.length = 0             # <<<<<<<<<<<<<<
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 *         self.pos = 0
 */
  __pyx_v_self->length = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":531
 *         self.size = 1024
 *         self.length = 0
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)             # <<<<<<<<<<<<<<
 *         self.pos = 0
 * 
 */
  __pyx_v_self->buffer = ((char *)PyMem_Malloc(((sizeof(char *)) * __pyx_v_self->size)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":532
 *         self.length = 0
 *         self.buffer = <char *>PyMem_Malloc(sizeof(char *) * self.size)
 *         self.pos = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.buffer == NULL:
 */
  __pyx_v_self->pos = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":534
 *         self.pos = 0
 * 
 *         if self.buffer == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_2 = (__pyx_v_self->buffer == NULL);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":535
 * 
 *         if self.buffer == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         if size > 0:
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":537
 *             raise MemoryError
 * 
 *         if size > 0:             # <<<<<<<<<<<<<<
 *             if self.write(buf, size) == -1:
 *                 return -1
 */
  __pyx_t_2 = (__pyx_v_size > 0);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":538
 * 
 *         if size > 0:
 *             if self.write(buf, size) == -1:             # <<<<<<<<<<<<<<
 *                 return -1
 * 
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_buf, __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = (__pyx_t_1 == -1);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":539
 *         if size > 0:
 *             if self.write(buf, size) == -1:
 *                 return -1             # <<<<<<<<<<<<<<
 * 
 *             PyMem_Free(buf)
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":541
 *                 return -1
 * 
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         self.pos = 0
 */
    PyMem_Free(__pyx_v_buf);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":543
 *             PyMem_Free(buf)
 * 
 *         self.pos = 0             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  __pyx_v_self->pos = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":545
 *         self.pos = 0
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int unpack_int(self, int num_bytes, long *ret) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.consume");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":547
 *         return 0
 * 
 *     cdef int unpack_int(self, int num_bytes, long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Unpacks a long from C{buf}.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_int(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, int __pyx_v_num_bytes, long *__pyx_v_ret) {
  int __pyx_v_nb;
  long __pyx_v_x;
  int __pyx_v_bytes_left;
  unsigned char *__pyx_v_bytes;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("unpack_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":551
 *         Unpacks a long from C{buf}.
 *         """
 *         if self.has_available(num_bytes) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->has_available(__pyx_v_self, __pyx_v_num_bytes); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":552
 *         """
 *         if self.has_available(num_bytes) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef int nb = num_bytes
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":554
 *             return -1
 * 
 *         cdef int nb = num_bytes             # <<<<<<<<<<<<<<
 *         cdef long x = 0
 *         cdef int bytes_left = num_bytes
 */
  __pyx_v_nb = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":555
 * 
 *         cdef int nb = num_bytes
 *         cdef long x = 0             # <<<<<<<<<<<<<<
 *         cdef int bytes_left = num_bytes
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)
 */
  __pyx_v_x = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":556
 *         cdef int nb = num_bytes
 *         cdef long x = 0
 *         cdef int bytes_left = num_bytes             # <<<<<<<<<<<<<<
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)
 * 
 */
  __pyx_v_bytes_left = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":557
 *         cdef long x = 0
 *         cdef int bytes_left = num_bytes
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_bytes = ((unsigned char *)(__pyx_v_self->buffer + __pyx_v_self->pos));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":559
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while bytes_left > 0:
 *                 x = (x << 8) | bytes[0]
 */
  __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":560
 * 
 *         if is_big_endian(self._endian):
 *             while bytes_left > 0:             # <<<<<<<<<<<<<<
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 */
    while (1) {
      __pyx_t_2 = (__pyx_v_bytes_left > 0);
      if (!__pyx_t_2) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":561
 *         if is_big_endian(self._endian):
 *             while bytes_left > 0:
 *                 x = (x << 8) | bytes[0]             # <<<<<<<<<<<<<<
 *                 bytes += 1
 *                 bytes_left -= 1
 */
      __pyx_v_x = ((__pyx_v_x << 8) | (__pyx_v_bytes[0]));

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":562
 *             while bytes_left > 0:
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1             # <<<<<<<<<<<<<<
 *                 bytes_left -= 1
 *         else:
 */
      __pyx_v_bytes += 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":563
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 *                 bytes_left -= 1             # <<<<<<<<<<<<<<
 *         else:
 *             while bytes_left > 0:
 */
      __pyx_v_bytes_left -= 1;
    }
    goto __pyx_L4;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":565
 *                 bytes_left -= 1
 *         else:
 *             while bytes_left > 0:             # <<<<<<<<<<<<<<
 *                 x = (x << 8) | bytes[bytes_left - 1]
 *                 bytes_left -= 1
 */
    while (1) {
      __pyx_t_2 = (__pyx_v_bytes_left > 0);
      if (!__pyx_t_2) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":566
 *         else:
 *             while bytes_left > 0:
 *                 x = (x << 8) | bytes[bytes_left - 1]             # <<<<<<<<<<<<<<
 *                 bytes_left -= 1
 * 
 */
      __pyx_v_x = ((__pyx_v_x << 8) | (__pyx_v_bytes[(__pyx_v_bytes_left - 1)]));

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":567
 *             while bytes_left > 0:
 *                 x = (x << 8) | bytes[bytes_left - 1]
 *                 bytes_left -= 1             # <<<<<<<<<<<<<<
 * 
 *         if SIZEOF_LONG > num_bytes:
 */
      __pyx_v_bytes_left -= 1;
    }
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":569
 *                 bytes_left -= 1
 * 
 *         if SIZEOF_LONG > num_bytes:             # <<<<<<<<<<<<<<
 *             x |= -(x & (1L << ((8 * num_bytes) - 1)))
 * 
 */
  __pyx_t_2 = (SIZEOF_LONG > __pyx_v_num_bytes);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":570
 * 
 *         if SIZEOF_LONG > num_bytes:
 *             x |= -(x & (1L << ((8 * num_bytes) - 1)))             # <<<<<<<<<<<<<<
 * 
 *         self.pos += nb
 */
    __pyx_v_x |= (-(__pyx_v_x & (1L << ((8 * __pyx_v_num_bytes) - 1))));
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":572
 *             x |= -(x & (1L << ((8 * num_bytes) - 1)))
 * 
 *         self.pos += nb             # <<<<<<<<<<<<<<
 * 
 *         ret[0] = x
 */
  __pyx_v_self->pos += __pyx_v_nb;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":574
 *         self.pos += nb
 * 
 *         ret[0] = x             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  (__pyx_v_ret[0]) = __pyx_v_x;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":576
 *         ret[0] = x
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int unpack_uint(self, int num_bytes, unsigned long *ret) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.unpack_int");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":578
 *         return 0
 * 
 *     cdef int unpack_uint(self, int num_bytes, unsigned long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Unpacks an unsigned long from C{buf}.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_uint(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, int __pyx_v_num_bytes, unsigned long *__pyx_v_ret) {
  int __pyx_v_nb;
  unsigned long __pyx_v_x;
  unsigned char *__pyx_v_bytes;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("unpack_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":582
 *         Unpacks an unsigned long from C{buf}.
 *         """
 *         cdef int nb = num_bytes             # <<<<<<<<<<<<<<
 * 
 *         if self.has_available(num_bytes) == -1:
 */
  __pyx_v_nb = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":584
 *         cdef int nb = num_bytes
 * 
 *         if self.has_available(num_bytes) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->has_available(__pyx_v_self, __pyx_v_num_bytes); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":585
 * 
 *         if self.has_available(num_bytes) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef unsigned long x = 0
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":587
 *             return -1
 * 
 *         cdef unsigned long x = 0             # <<<<<<<<<<<<<<
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)
 * 
 */
  __pyx_v_x = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":588
 * 
 *         cdef unsigned long x = 0
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_bytes = ((unsigned char *)(__pyx_v_self->buffer + __pyx_v_self->pos));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":590
 *         cdef unsigned char *bytes = <unsigned char *>(self.buffer + self.pos)
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[0]
 */
  __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":591
 * 
 *         if is_big_endian(self._endian):
 *             while num_bytes > 0:             # <<<<<<<<<<<<<<
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 */
    while (1) {
      __pyx_t_2 = (__pyx_v_num_bytes > 0);
      if (!__pyx_t_2) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":592
 *         if is_big_endian(self._endian):
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[0]             # <<<<<<<<<<<<<<
 *                 bytes += 1
 *                 num_bytes -= 1
 */
      __pyx_v_x = ((__pyx_v_x << 8) | (__pyx_v_bytes[0]));

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":593
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1             # <<<<<<<<<<<<<<
 *                 num_bytes -= 1
 *         else:
 */
      __pyx_v_bytes += 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":594
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 *                 num_bytes -= 1             # <<<<<<<<<<<<<<
 *         else:
 *             while num_bytes > 0:
 */
      __pyx_v_num_bytes -= 1;
    }
    goto __pyx_L4;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":596
 *                 num_bytes -= 1
 *         else:
 *             while num_bytes > 0:             # <<<<<<<<<<<<<<
 *                 x = (x << 8) | bytes[num_bytes - 1]
 *                 num_bytes -= 1
 */
    while (1) {
      __pyx_t_2 = (__pyx_v_num_bytes > 0);
      if (!__pyx_t_2) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":597
 *         else:
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[num_bytes - 1]             # <<<<<<<<<<<<<<
 *                 num_bytes -= 1
 * 
 */
      __pyx_v_x = ((__pyx_v_x << 8) | (__pyx_v_bytes[(__pyx_v_num_bytes - 1)]));

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":598
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[num_bytes - 1]
 *                 num_bytes -= 1             # <<<<<<<<<<<<<<
 * 
 *         self.pos += nb
 */
      __pyx_v_num_bytes -= 1;
    }
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":600
 *                 num_bytes -= 1
 * 
 *         self.pos += nb             # <<<<<<<<<<<<<<
 * 
 *         ret[0] = x
 */
  __pyx_v_self->pos += __pyx_v_nb;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":602
 *         self.pos += nb
 * 
 *         ret[0] = x             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  (__pyx_v_ret[0]) = __pyx_v_x;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":604
 *         ret[0] = x
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int pack_int(self, int num_bytes, long x) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.unpack_uint");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":606
 *         return 0
 * 
 *     cdef int pack_int(self, int num_bytes, long x) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Packs a long.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_int(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, int __pyx_v_num_bytes, long __pyx_v_x) {
  long __pyx_v_maxint;
  long __pyx_v_minint;
  char *__pyx_v_buf;
  long __pyx_v_i;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("pack_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":612
 *         @raise OverflowError: integer out of range
 *         """
 *         cdef long maxint = 1             # <<<<<<<<<<<<<<
 *         cdef long minint = -1
 * 
 */
  __pyx_v_maxint = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":613
 *         """
 *         cdef long maxint = 1
 *         cdef long minint = -1             # <<<<<<<<<<<<<<
 * 
 *         if num_bytes != SIZEOF_LONG:
 */
  __pyx_v_minint = -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":615
 *         cdef long minint = -1
 * 
 *         if num_bytes != SIZEOF_LONG:             # <<<<<<<<<<<<<<
 *             maxint = (maxint << (num_bytes * 8 - 1)) - 1
 *             minint = (-maxint) - 1
 */
  __pyx_t_1 = (__pyx_v_num_bytes != SIZEOF_LONG);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":616
 * 
 *         if num_bytes != SIZEOF_LONG:
 *             maxint = (maxint << (num_bytes * 8 - 1)) - 1             # <<<<<<<<<<<<<<
 *             minint = (-maxint) - 1
 * 
 */
    __pyx_v_maxint = ((__pyx_v_maxint << ((__pyx_v_num_bytes * 8) - 1)) - 1);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":617
 *         if num_bytes != SIZEOF_LONG:
 *             maxint = (maxint << (num_bytes * 8 - 1)) - 1
 *             minint = (-maxint) - 1             # <<<<<<<<<<<<<<
 * 
 *             if x > maxint or x < minint:
 */
    __pyx_v_minint = ((-__pyx_v_maxint) - 1);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":619
 *             minint = (-maxint) - 1
 * 
 *             if x > maxint or x < minint:             # <<<<<<<<<<<<<<
 *                 raise OverflowError('integer out of range')
 * 
 */
    if (!(__pyx_v_x > __pyx_v_maxint)) {
      __pyx_t_1 = (__pyx_v_x < __pyx_v_minint);
    } else {
      __pyx_t_1 = (__pyx_v_x > __pyx_v_maxint);
    }
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":620
 * 
 *             if x > maxint or x < minint:
 *                 raise OverflowError('integer out of range')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(__pyx_kp_24);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_24);
      __Pyx_GIVEREF(__pyx_kp_24);
      __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":622
 *                 raise OverflowError('integer out of range')
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)             # <<<<<<<<<<<<<<
 * 
 *         if buf == NULL:
 */
  __pyx_v_buf = ((char *)PyMem_Malloc(__pyx_v_num_bytes));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":624
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 * 
 *         if buf == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_buf == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":625
 * 
 *         if buf == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cdef long i = num_bytes
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":627
 *             raise MemoryError
 * 
 *         cdef long i = num_bytes             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_i = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":629
 *         cdef long i = num_bytes
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while i > 0:
 *                 i -= 1
 */
  __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_4) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":630
 * 
 *         if is_big_endian(self._endian):
 *             while i > 0:             # <<<<<<<<<<<<<<
 *                 i -= 1
 *                 buf[i] = <char>x
 */
    while (1) {
      __pyx_t_1 = (__pyx_v_i > 0);
      if (!__pyx_t_1) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":631
 *         if is_big_endian(self._endian):
 *             while i > 0:
 *                 i -= 1             # <<<<<<<<<<<<<<
 *                 buf[i] = <char>x
 *                 x >>= 8
 */
      __pyx_v_i -= 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":632
 *             while i > 0:
 *                 i -= 1
 *                 buf[i] = <char>x             # <<<<<<<<<<<<<<
 *                 x >>= 8
 *         else:
 */
      (__pyx_v_buf[__pyx_v_i]) = ((char)__pyx_v_x);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":633
 *                 i -= 1
 *                 buf[i] = <char>x
 *                 x >>= 8             # <<<<<<<<<<<<<<
 *         else:
 *             while i > 0:
 */
      __pyx_v_x >>= 8;
    }
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":635
 *                 x >>= 8
 *         else:
 *             while i > 0:             # <<<<<<<<<<<<<<
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 */
    while (1) {
      __pyx_t_1 = (__pyx_v_i > 0);
      if (!__pyx_t_1) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":636
 *         else:
 *             while i > 0:
 *                 buf[num_bytes - i] = <char>x             # <<<<<<<<<<<<<<
 *                 i -= 1
 *                 x >>= 8
 */
      (__pyx_v_buf[(__pyx_v_num_bytes - __pyx_v_i)]) = ((char)__pyx_v_x);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":637
 *             while i > 0:
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1             # <<<<<<<<<<<<<<
 *                 x >>= 8
 * 
 */
      __pyx_v_i -= 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":638
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 *                 x >>= 8             # <<<<<<<<<<<<<<
 * 
 *         self.write(buf, num_bytes)
 */
      __pyx_v_x >>= 8;
    }
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":640
 *                 x >>= 8
 * 
 *         self.write(buf, num_bytes)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_buf, __pyx_v_num_bytes); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":641
 * 
 *         self.write(buf, num_bytes)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":643
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int pack_uint(self, int num_bytes, unsigned long x) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.pack_int");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":645
 *         return 0
 * 
 *     cdef int pack_uint(self, int num_bytes, unsigned long x) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Packs an unsigned long into a buffer.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_uint(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, int __pyx_v_num_bytes, unsigned long __pyx_v_x) {
  unsigned long __pyx_v_maxint;
  char *__pyx_v_buf;
  long __pyx_v_i;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("pack_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":651
 *         @raise OverflowError: integer out of range
 *         """
 *         cdef unsigned long maxint = 1             # <<<<<<<<<<<<<<
 * 
 *         if num_bytes != SIZEOF_LONG:
 */
  __pyx_v_maxint = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":653
 *         cdef unsigned long maxint = 1
 * 
 *         if num_bytes != SIZEOF_LONG:             # <<<<<<<<<<<<<<
 *             maxint <<= <unsigned long>(num_bytes * 8)
 * 
 */
  __pyx_t_1 = (__pyx_v_num_bytes != SIZEOF_LONG);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":654
 * 
 *         if num_bytes != SIZEOF_LONG:
 *             maxint <<= <unsigned long>(num_bytes * 8)             # <<<<<<<<<<<<<<
 * 
 *             if x >= maxint:
 */
    __pyx_v_maxint <<= ((unsigned long)(__pyx_v_num_bytes * 8));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":656
 *             maxint <<= <unsigned long>(num_bytes * 8)
 * 
 *             if x >= maxint:             # <<<<<<<<<<<<<<
 *                 raise OverflowError('integer out of range')
 * 
 */
    __pyx_t_1 = (__pyx_v_x >= __pyx_v_maxint);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":657
 * 
 *             if x >= maxint:
 *                 raise OverflowError('integer out of range')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(sizeof(char *) * num_bytes)
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(__pyx_kp_25);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_25);
      __Pyx_GIVEREF(__pyx_kp_25);
      __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":659
 *                 raise OverflowError('integer out of range')
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(sizeof(char *) * num_bytes)             # <<<<<<<<<<<<<<
 * 
 *         if not buf:
 */
  __pyx_v_buf = ((char *)PyMem_Malloc(((sizeof(char *)) * __pyx_v_num_bytes)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":661
 *         cdef char *buf = <char *>PyMem_Malloc(sizeof(char *) * num_bytes)
 * 
 *         if not buf:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (!(__pyx_v_buf != 0));
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":662
 * 
 *         if not buf:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cdef long i = num_bytes
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":664
 *             raise MemoryError
 * 
 *         cdef long i = num_bytes             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_i = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":666
 *         cdef long i = num_bytes
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while i > 0:
 *                 i -= 1
 */
  __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_4) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":667
 * 
 *         if is_big_endian(self._endian):
 *             while i > 0:             # <<<<<<<<<<<<<<
 *                 i -= 1
 *                 buf[i] = <char>x
 */
    while (1) {
      __pyx_t_1 = (__pyx_v_i > 0);
      if (!__pyx_t_1) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":668
 *         if is_big_endian(self._endian):
 *             while i > 0:
 *                 i -= 1             # <<<<<<<<<<<<<<
 *                 buf[i] = <char>x
 *                 x >>= 8
 */
      __pyx_v_i -= 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":669
 *             while i > 0:
 *                 i -= 1
 *                 buf[i] = <char>x             # <<<<<<<<<<<<<<
 *                 x >>= 8
 *         else:
 */
      (__pyx_v_buf[__pyx_v_i]) = ((char)__pyx_v_x);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":670
 *                 i -= 1
 *                 buf[i] = <char>x
 *                 x >>= 8             # <<<<<<<<<<<<<<
 *         else:
 *             while i > 0:
 */
      __pyx_v_x >>= 8;
    }
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":672
 *                 x >>= 8
 *         else:
 *             while i > 0:             # <<<<<<<<<<<<<<
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 */
    while (1) {
      __pyx_t_1 = (__pyx_v_i > 0);
      if (!__pyx_t_1) break;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":673
 *         else:
 *             while i > 0:
 *                 buf[num_bytes - i] = <char>x             # <<<<<<<<<<<<<<
 *                 i -= 1
 *                 x >>= 8
 */
      (__pyx_v_buf[(__pyx_v_num_bytes - __pyx_v_i)]) = ((char)__pyx_v_x);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":674
 *             while i > 0:
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1             # <<<<<<<<<<<<<<
 *                 x >>= 8
 * 
 */
      __pyx_v_i -= 1;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":675
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 *                 x >>= 8             # <<<<<<<<<<<<<<
 * 
 *         self.write(buf, num_bytes)
 */
      __pyx_v_x >>= 8;
    }
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":677
 *                 x >>= 8
 * 
 *         self.write(buf, num_bytes)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_buf, __pyx_v_num_bytes); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":678
 * 
 *         self.write(buf, num_bytes)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":680
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_uchar(self, unsigned char *ret) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.pack_uint");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":682
 *         return 0
 * 
 *     cdef int read_uchar(self, unsigned char *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads an C{unsigned char} from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_uchar(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned char *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_uchar");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":686
 *         Reads an C{unsigned char} from the stream.
 *         """
 *         return self.unpack_uint(1, <unsigned long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_char(self, char *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_uint(__pyx_v_self, 1, ((unsigned long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_uchar");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":688
 *         return self.unpack_uint(1, <unsigned long *>ret)
 * 
 *     cdef int read_char(self, char *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a C{char} from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_char(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, char *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_char");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":692
 *         Reads a C{char} from the stream.
 *         """
 *         return self.unpack_int(1, <long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_ushort(self, unsigned short *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_int(__pyx_v_self, 1, ((long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_char");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":694
 *         return self.unpack_int(1, <long *>ret)
 * 
 *     cdef int read_ushort(self, unsigned short *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 2 byte unsigned integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ushort(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned short *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_ushort");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":698
 *         Reads a 2 byte unsigned integer from the stream.
 *         """
 *         return self.unpack_uint(2, <unsigned long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_short(self, short *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_uint(__pyx_v_self, 2, ((unsigned long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_ushort");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":700
 *         return self.unpack_uint(2, <unsigned long *>ret)
 * 
 *     cdef int read_short(self, short *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 2 byte integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_short(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, short *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_short");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":704
 *         Reads a 2 byte integer from the stream.
 *         """
 *         return self.unpack_int(2, <long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_ulong(self, unsigned long *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_int(__pyx_v_self, 2, ((long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_short");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":706
 *         return self.unpack_int(2, <long *>ret)
 * 
 *     cdef int read_ulong(self, unsigned long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte unsigned integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ulong(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned long *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_ulong");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":710
 *         Reads a 4 byte unsigned integer from the stream.
 *         """
 *         return self.unpack_uint(4, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_long(self, long *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_uint(__pyx_v_self, 4, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_ulong");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":712
 *         return self.unpack_uint(4, ret)
 * 
 *     cdef int read_long(self, long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_long(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, long *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_long");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":716
 *         Reads a 4 byte integer from the stream.
 *         """
 *         return self.unpack_int(4, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_24bit_uint(self, unsigned long *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_int(__pyx_v_self, 4, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_long");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":718
 *         return self.unpack_int(4, ret)
 * 
 *     cdef int read_24bit_uint(self, unsigned long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 24 bit unsigned integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_uint(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned long *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_24bit_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":722
 *         Reads a 24 bit unsigned integer from the stream.
 *         """
 *         return self.unpack_uint(3, <unsigned long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_24bit_int(self, long *ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_uint(__pyx_v_self, 3, ((unsigned long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_24bit_uint");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":724
 *         return self.unpack_uint(3, <unsigned long *>ret)
 * 
 *     cdef int read_24bit_int(self, long *ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 24 bit integer from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_int(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, long *__pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("read_24bit_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":728
 *         Reads a 24 bit integer from the stream.
 *         """
 *         return self.unpack_int(3, <long *>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_uchar(self, unsigned char ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->unpack_int(__pyx_v_self, 3, ((long *)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_24bit_int");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":730
 *         return self.unpack_int(3, <long *>ret)
 * 
 *     cdef int write_uchar(self, unsigned char ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes an C{unsigned char} to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_uchar(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned char __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_uchar");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":737
 *         @type ret: C{int}
 *         """
 *         return self.pack_uint(1, <unsigned long>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_char(self, char ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_uint(__pyx_v_self, 1, ((unsigned long)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_uchar");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":739
 *         return self.pack_uint(1, <unsigned long>ret)
 * 
 *     cdef int write_char(self, char ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Write a C{char} to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_char(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, char __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_char");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":746
 *         @type ret: C{int}
 *         """
 *         return self.pack_int(1, <long>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_ushort(self, unsigned short ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_int(__pyx_v_self, 1, ((long)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_char");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":748
 *         return self.pack_int(1, <long>ret)
 * 
 *     cdef int write_ushort(self, unsigned short ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 2 byte unsigned integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ushort(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned short __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_ushort");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":755
 *         @type ret: C{int}
 *         """
 *         return self.pack_uint(2, <unsigned long>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_short(self, short ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_uint(__pyx_v_self, 2, ((unsigned long)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_ushort");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":757
 *         return self.pack_uint(2, <unsigned long>ret)
 * 
 *     cdef int write_short(self, short ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 2 byte integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_short(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, short __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_short");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":764
 *         @type ret: C{int}
 *         """
 *         return self.pack_int(2, <long>ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_ulong(self, unsigned long ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_int(__pyx_v_self, 2, ((long)__pyx_v_ret)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_short");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":766
 *         return self.pack_int(2, <long>ret)
 * 
 *     cdef int write_ulong(self, unsigned long ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte unsigned integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ulong(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned long __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_ulong");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":773
 *         @type ret: C{int}
 *         """
 *         return self.pack_uint(4, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_long(self, long ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_uint(__pyx_v_self, 4, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_ulong");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":775
 *         return self.pack_uint(4, ret)
 * 
 *     cdef int write_long(self, long ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_long(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, long __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_long");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":782
 *         @type ret: C{int}
 *         """
 *         return self.pack_int(4, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_24bit_uint(self, unsigned long ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_int(__pyx_v_self, 4, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_long");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":784
 *         return self.pack_int(4, ret)
 * 
 *     cdef int write_24bit_uint(self, unsigned long ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 24 bit unsigned integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_uint(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned long __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_24bit_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":791
 *         @type ret: C{int}
 *         """
 *         return self.pack_uint(3, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_24bit_int(self, long ret) except? -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_uint(__pyx_v_self, 3, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_24bit_uint");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":793
 *         return self.pack_uint(3, ret)
 * 
 *     cdef int write_24bit_int(self, long ret) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 24 bit integer to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_int(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, long __pyx_v_ret) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_24bit_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":800
 *         @type ret: C{int}
 *         """
 *         return self.pack_int(3, ret)             # <<<<<<<<<<<<<<
 * 
 *     cdef object read_utf8_string(self, unsigned int l):
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->pack_int(__pyx_v_self, 3, __pyx_v_ret); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_24bit_int");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":802
 *         return self.pack_int(3, ret)
 * 
 *     cdef object read_utf8_string(self, unsigned int l):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a UTF-8 string from the stream.
 */

static  PyObject *__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_utf8_string(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, unsigned int __pyx_v_l) {
  char *__pyx_v_buf;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("read_utf8_string");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":808
 *         @rtype: C{unicode}
 *         """
 *         cdef char* buf = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":811
 *         cdef object ret
 * 
 *         if l == 0:             # <<<<<<<<<<<<<<
 *             return unicode('')
 * 
 */
  __pyx_t_1 = (__pyx_v_l == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":812
 * 
 *         if l == 0:
 *             return unicode('')             # <<<<<<<<<<<<<<
 * 
 *         if self.read(&buf, l) == -1:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_26);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_26);
    __Pyx_GIVEREF(__pyx_kp_26);
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyUnicode_Type)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":814
 *             return unicode('')
 * 
 *         if self.read(&buf, l) == -1:             # <<<<<<<<<<<<<<
 *             if buf != NULL:
 *                 PyMem_Free(buf)
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->read(__pyx_v_self, (&__pyx_v_buf), __pyx_v_l); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = (__pyx_t_4 == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":815
 * 
 *         if self.read(&buf, l) == -1:
 *             if buf != NULL:             # <<<<<<<<<<<<<<
 *                 PyMem_Free(buf)
 * 
 */
    __pyx_t_1 = (__pyx_v_buf != NULL);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":816
 *         if self.read(&buf, l) == -1:
 *             if buf != NULL:
 *                 PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return
 */
      PyMem_Free(__pyx_v_buf);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":818
 *                 PyMem_Free(buf)
 * 
 *             return             # <<<<<<<<<<<<<<
 * 
 *         ret = PyUnicode_DecodeUTF8(buf, l, 'strict')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":820
 *             return
 * 
 *         ret = PyUnicode_DecodeUTF8(buf, l, 'strict')             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  __pyx_t_3 = PyUnicode_DecodeUTF8(__pyx_v_buf, __pyx_v_l, __pyx_k_27); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":821
 * 
 *         ret = PyUnicode_DecodeUTF8(buf, l, 'strict')
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":823
 *         PyMem_Free(buf)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_utf8_string(self, object obj) except? -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_utf8_string");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":825
 *         return ret
 * 
 *     cdef int write_utf8_string(self, object obj) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes a unicode object to the stream in UTF-8.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_utf8_string(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_v_encoded_string;
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_l;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("write_utf8_string");
  __pyx_v_encoded_string = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":833
 *         """
 *         cdef object encoded_string
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t l = -1
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":834
 *         cdef object encoded_string
 *         cdef char *buf = NULL
 *         cdef Py_ssize_t l = -1             # <<<<<<<<<<<<<<
 * 
 *         if PyUnicode_Check(obj) == 1:
 */
  __pyx_v_l = -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":836
 *         cdef Py_ssize_t l = -1
 * 
 *         if PyUnicode_Check(obj) == 1:             # <<<<<<<<<<<<<<
 *             encoded_string = PyUnicode_AsUTF8String(obj)
 *         elif PyString_Check(obj) == 1:
 */
  __pyx_t_1 = (PyUnicode_Check(__pyx_v_obj) == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":837
 * 
 *         if PyUnicode_Check(obj) == 1:
 *             encoded_string = PyUnicode_AsUTF8String(obj)             # <<<<<<<<<<<<<<
 *         elif PyString_Check(obj) == 1:
 *             encoded_string = obj
 */
    __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_obj); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_encoded_string);
    __pyx_v_encoded_string = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L3;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":838
 *         if PyUnicode_Check(obj) == 1:
 *             encoded_string = PyUnicode_AsUTF8String(obj)
 *         elif PyString_Check(obj) == 1:             # <<<<<<<<<<<<<<
 *             encoded_string = obj
 *         else:
 */
  __pyx_t_1 = (PyString_Check(__pyx_v_obj) == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":839
 *             encoded_string = PyUnicode_AsUTF8String(obj)
 *         elif PyString_Check(obj) == 1:
 *             encoded_string = obj             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError('value must be Unicode or str')
 */
    __Pyx_INCREF(__pyx_v_obj);
    __Pyx_DECREF(__pyx_v_encoded_string);
    __pyx_v_encoded_string = __pyx_v_obj;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":841
 *             encoded_string = obj
 *         else:
 *             raise TypeError('value must be Unicode or str')             # <<<<<<<<<<<<<<
 * 
 *         if <PyObject *>encoded_string == NULL:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_28);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_28);
    __Pyx_GIVEREF(__pyx_kp_28);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":843
 *             raise TypeError('value must be Unicode or str')
 * 
 *         if <PyObject *>encoded_string == NULL:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_encoded_string) == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":844
 * 
 *         if <PyObject *>encoded_string == NULL:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if PyString_AsStringAndSize(encoded_string, &buf, &l) == -1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":846
 *             return -1
 * 
 *         if PyString_AsStringAndSize(encoded_string, &buf, &l) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = (PyString_AsStringAndSize(__pyx_v_encoded_string, (&__pyx_v_buf), (&__pyx_v_l)) == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":847
 * 
 *         if PyString_AsStringAndSize(encoded_string, &buf, &l) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if self.write(buf, l) == -1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":849
 *             return -1
 * 
 *         if self.write(buf, l) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_buf, __pyx_v_l); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = (__pyx_t_4 == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":850
 * 
 *         if self.write(buf, l) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":852
 *             return -1
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_double(self, double *obj) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_utf8_string");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_encoded_string);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":854
 *         return 0
 * 
 *     cdef int read_double(self, double *obj) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Reads an 8 byte float from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_double(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, double *__pyx_v_obj) {
  unsigned char *__pyx_v_buf;
  int __pyx_v_done;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("read_double");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":858
 *         Reads an 8 byte float from the stream.
 *         """
 *         cdef unsigned char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef int done = 0
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":859
 *         """
 *         cdef unsigned char *buf = NULL
 *         cdef int done = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.read(<char **>&buf, 8) == -1:
 */
  __pyx_v_done = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":861
 *         cdef int done = 0
 * 
 *         if self.read(<char **>&buf, 8) == -1:             # <<<<<<<<<<<<<<
 *             if buf != NULL:
 *                 PyMem_Free(buf)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->read(__pyx_v_self, ((char **)(&__pyx_v_buf)), 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":862
 * 
 *         if self.read(<char **>&buf, 8) == -1:
 *             if buf != NULL:             # <<<<<<<<<<<<<<
 *                 PyMem_Free(buf)
 * 
 */
    __pyx_t_2 = (__pyx_v_buf != NULL);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":863
 *         if self.read(<char **>&buf, 8) == -1:
 *             if buf != NULL:
 *                 PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
      PyMem_Free(__pyx_v_buf);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":865
 *                 PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if float_broken == 1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":867
 *             return -1
 * 
 *         if float_broken == 1:             # <<<<<<<<<<<<<<
 *             if is_big_endian(SYSTEM_ENDIAN):
 *                 if not is_big_endian(self._endian):
 */
  __pyx_t_2 = (__pyx_v_6cpyamf_4util_float_broken == 1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":868
 * 
 *         if float_broken == 1:
 *             if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *                 if not is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)
 */
    __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":869
 *         if float_broken == 1:
 *             if is_big_endian(SYSTEM_ENDIAN):
 *                 if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                     swap_bytes(buf, 8)
 *             else:
 */
      __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian));
      if (__pyx_t_2) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":870
 *             if is_big_endian(SYSTEM_ENDIAN):
 *                 if not is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 *             else:
 *                 if is_big_endian(self._endian):
 */
        __pyx_t_1 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    /*else*/ {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":872
 *                     swap_bytes(buf, 8)
 *             else:
 *                 if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                     swap_bytes(buf, 8)
 * 
 */
      __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
      if (__pyx_t_1) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":873
 *             else:
 *                 if is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *             if memcmp(buf, &system_nan, 8) == 0:
 */
        __pyx_t_1 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L8;
      }
      __pyx_L8:;
    }
    __pyx_L6:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":875
 *                     swap_bytes(buf, 8)
 * 
 *             if memcmp(buf, &system_nan, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(obj, &system_nan, 8)
 * 
 */
    __pyx_t_2 = (memcmp(__pyx_v_buf, (&__pyx_v_6cpyamf_4util_system_nan), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":876
 * 
 *             if memcmp(buf, &system_nan, 8) == 0:
 *                 memcpy(obj, &system_nan, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_obj, (&__pyx_v_6cpyamf_4util_system_nan), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":878
 *                 memcpy(obj, &system_nan, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(buf, &system_posinf, 8) == 0:
 *                 memcpy(obj, &system_posinf, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L9;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":879
 * 
 *                 done = 1
 *             elif memcmp(buf, &system_posinf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(obj, &system_posinf, 8)
 * 
 */
    __pyx_t_2 = (memcmp(__pyx_v_buf, (&__pyx_v_6cpyamf_4util_system_posinf), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":880
 *                 done = 1
 *             elif memcmp(buf, &system_posinf, 8) == 0:
 *                 memcpy(obj, &system_posinf, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_obj, (&__pyx_v_6cpyamf_4util_system_posinf), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":882
 *                 memcpy(obj, &system_posinf, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(buf, &system_neginf, 8) == 0:
 *                 memcpy(obj, &system_neginf, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L9;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":883
 * 
 *                 done = 1
 *             elif memcmp(buf, &system_neginf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(obj, &system_neginf, 8)
 * 
 */
    __pyx_t_2 = (memcmp(__pyx_v_buf, (&__pyx_v_6cpyamf_4util_system_neginf), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":884
 *                 done = 1
 *             elif memcmp(buf, &system_neginf, 8) == 0:
 *                 memcpy(obj, &system_neginf, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_obj, (&__pyx_v_6cpyamf_4util_system_neginf), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":886
 *                 memcpy(obj, &system_neginf, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 * 
 *             if done == 1:
 */
      __pyx_v_done = 1;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":888
 *                 done = 1
 * 
 *             if done == 1:             # <<<<<<<<<<<<<<
 *                 PyMem_Free(buf)
 * 
 */
    __pyx_t_2 = (__pyx_v_done == 1);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":889
 * 
 *             if done == 1:
 *                 PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *                 return 0
 */
      PyMem_Free(__pyx_v_buf);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":891
 *                 PyMem_Free(buf)
 * 
 *                 return 0             # <<<<<<<<<<<<<<
 * 
 *             if is_big_endian(SYSTEM_ENDIAN):
 */
      __pyx_r = 0;
      goto __pyx_L0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":893
 *                 return 0
 * 
 *             if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *                 if not is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)
 */
    __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":894
 * 
 *             if is_big_endian(SYSTEM_ENDIAN):
 *                 if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                     swap_bytes(buf, 8)
 *             else:
 */
      __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian));
      if (__pyx_t_2) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":895
 *             if is_big_endian(SYSTEM_ENDIAN):
 *                 if not is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 *             else:
 *                 if is_big_endian(self._endian):
 */
        __pyx_t_1 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L12;
      }
      __pyx_L12:;
      goto __pyx_L11;
    }
    /*else*/ {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":897
 *                     swap_bytes(buf, 8)
 *             else:
 *                 if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                     swap_bytes(buf, 8)
 * 
 */
      __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
      if (__pyx_t_1) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":898
 *             else:
 *                 if is_big_endian(self._endian):
 *                     swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *         obj[0] = _PyFloat_Unpack8(buf, not is_big_endian(self._endian))
 */
        __pyx_t_1 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L13;
      }
      __pyx_L13:;
    }
    __pyx_L11:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":900
 *                     swap_bytes(buf, 8)
 * 
 *         obj[0] = _PyFloat_Unpack8(buf, not is_big_endian(self._endian))             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  (__pyx_v_obj[0]) = _PyFloat_Unpack8(__pyx_v_buf, (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":901
 * 
 *         obj[0] = _PyFloat_Unpack8(buf, not is_big_endian(self._endian))
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":903
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_double(self, double val) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_double");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":905
 *         return 0
 * 
 *     cdef int write_double(self, double val) except? -1:             # <<<<<<<<<<<<<<
 *         """
 *         Writes an 8 byte float to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_double(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, double __pyx_v_val) {
  unsigned char *__pyx_v_buf;
  int __pyx_v_done;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("write_double");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":914
 *         cdef unsigned char *buf
 *         cdef unsigned char *foo
 *         cdef int done = 0             # <<<<<<<<<<<<<<
 * 
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 8)
 */
  __pyx_v_done = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":916
 *         cdef int done = 0
 * 
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 8)             # <<<<<<<<<<<<<<
 * 
 *         if buf == NULL:
 */
  __pyx_v_buf = ((unsigned char *)PyMem_Malloc(((sizeof(unsigned char *)) * 8)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":918
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 8)
 * 
 *         if buf == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_buf == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":919
 * 
 *         if buf == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         if float_broken == 1:
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":921
 *             raise MemoryError
 * 
 *         if float_broken == 1:             # <<<<<<<<<<<<<<
 *             if memcmp(&val, &system_nan, 8) == 0:
 *                 memcpy(buf, &val, 8)
 */
  __pyx_t_1 = (__pyx_v_6cpyamf_4util_float_broken == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":922
 * 
 *         if float_broken == 1:
 *             if memcmp(&val, &system_nan, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(buf, &val, 8)
 * 
 */
    __pyx_t_1 = (memcmp((&__pyx_v_val), (&__pyx_v_6cpyamf_4util_system_nan), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":923
 *         if float_broken == 1:
 *             if memcmp(&val, &system_nan, 8) == 0:
 *                 memcpy(buf, &val, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_buf, (&__pyx_v_val), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":925
 *                 memcpy(buf, &val, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(&val, &system_posinf, 8) == 0:
 *                 memcpy(buf, &val, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L5;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":926
 * 
 *                 done = 1
 *             elif memcmp(&val, &system_posinf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(buf, &val, 8)
 * 
 */
    __pyx_t_1 = (memcmp((&__pyx_v_val), (&__pyx_v_6cpyamf_4util_system_posinf), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":927
 *                 done = 1
 *             elif memcmp(&val, &system_posinf, 8) == 0:
 *                 memcpy(buf, &val, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_buf, (&__pyx_v_val), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":929
 *                 memcpy(buf, &val, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(&val, &system_neginf, 8) == 0:
 *                 memcpy(buf, &val, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L5;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":930
 * 
 *                 done = 1
 *             elif memcmp(&val, &system_neginf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 memcpy(buf, &val, 8)
 * 
 */
    __pyx_t_1 = (memcmp((&__pyx_v_val), (&__pyx_v_6cpyamf_4util_system_neginf), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":931
 *                 done = 1
 *             elif memcmp(&val, &system_neginf, 8) == 0:
 *                 memcpy(buf, &val, 8)             # <<<<<<<<<<<<<<
 * 
 *                 done = 1
 */
      memcpy(__pyx_v_buf, (&__pyx_v_val), 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":933
 *                 memcpy(buf, &val, 8)
 * 
 *                 done = 1             # <<<<<<<<<<<<<<
 * 
 *             if done == 1:
 */
      __pyx_v_done = 1;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":935
 *                 done = 1
 * 
 *             if done == 1:             # <<<<<<<<<<<<<<
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):
 */
    __pyx_t_1 = (__pyx_v_done == 1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":936
 * 
 *             if done == 1:
 *                 if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *                     if not is_big_endian(self._endian):
 *                         swap_bytes(buf, 8)
 */
      __pyx_t_2 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
      if (__pyx_t_2) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":937
 *             if done == 1:
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                         swap_bytes(buf, 8)
 *                 else:
 */
        __pyx_t_1 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian));
        if (__pyx_t_1) {

          /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":938
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):
 *                         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 *                 else:
 *                     if is_big_endian(self._endian):
 */
          __pyx_t_2 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L8;
        }
        __pyx_L8:;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":940
 *                         swap_bytes(buf, 8)
 *                 else:
 *                     if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                         swap_bytes(buf, 8)
 * 
 */
        __pyx_t_2 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
        if (__pyx_t_2) {

          /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":941
 *                 else:
 *                     if is_big_endian(self._endian):
 *                         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 * 
 *         if done == 0:
 */
          __pyx_t_2 = __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L9;
        }
        __pyx_L9:;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":943
 *                         swap_bytes(buf, 8)
 * 
 *         if done == 0:             # <<<<<<<<<<<<<<
 *             if _PyFloat_Pack8(val, <unsigned char *>buf, not is_big_endian(self._endian)) == -1:
 *                 PyMem_Free(buf)
 */
  __pyx_t_1 = (__pyx_v_done == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":944
 * 
 *         if done == 0:
 *             if _PyFloat_Pack8(val, <unsigned char *>buf, not is_big_endian(self._endian)) == -1:             # <<<<<<<<<<<<<<
 *                 PyMem_Free(buf)
 * 
 */
    __pyx_t_1 = (_PyFloat_Pack8(__pyx_v_val, ((unsigned char *)__pyx_v_buf), (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian))) == -1);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":945
 *         if done == 0:
 *             if _PyFloat_Pack8(val, <unsigned char *>buf, not is_big_endian(self._endian)) == -1:
 *                 PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *                 return -1
 */
      PyMem_Free(__pyx_v_buf);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":947
 *                 PyMem_Free(buf)
 * 
 *                 return -1             # <<<<<<<<<<<<<<
 * 
 *         if self.write(<char *>buf, 8) == -1:
 */
      __pyx_r = -1;
      goto __pyx_L0;
      goto __pyx_L11;
    }
    __pyx_L11:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":949
 *                 return -1
 * 
 *         if self.write(<char *>buf, 8) == -1:             # <<<<<<<<<<<<<<
 *             PyMem_Free(buf)
 * 
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, ((char *)__pyx_v_buf), 8); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = (__pyx_t_2 == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":950
 * 
 *         if self.write(<char *>buf, 8) == -1:
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
    PyMem_Free(__pyx_v_buf);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":952
 *             PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(buf)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":954
 *             return -1
 * 
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":956
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int read_float(self, float *x):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_double");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":958
 *         return 0
 * 
 *     cdef int read_float(self, float *x):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte float from the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_read_float(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, float *__pyx_v_x) {
  char *__pyx_v_buf;
  unsigned char __pyx_v_le;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("read_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":962
 *         Reads a 4 byte float from the stream.
 *         """
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef unsigned char le = 0
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":963
 *         """
 *         cdef char *buf = NULL
 *         cdef unsigned char le = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.read(&buf, 4) == -1:
 */
  __pyx_v_le = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":965
 *         cdef unsigned char le = 0
 * 
 *         if self.read(&buf, 4) == -1:             # <<<<<<<<<<<<<<
 *             if buf != NULL:
 *                 PyMem_Free(buf)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->read(__pyx_v_self, (&__pyx_v_buf), 4); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":966
 * 
 *         if self.read(&buf, 4) == -1:
 *             if buf != NULL:             # <<<<<<<<<<<<<<
 *                 PyMem_Free(buf)
 * 
 */
    __pyx_t_2 = (__pyx_v_buf != NULL);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":967
 *         if self.read(&buf, 4) == -1:
 *             if buf != NULL:
 *                 PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
      PyMem_Free(__pyx_v_buf);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":969
 *                 PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if not is_big_endian(self._endian):
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":971
 *             return -1
 * 
 *         if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             le = 1
 * 
 */
  __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian));
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":972
 * 
 *         if not is_big_endian(self._endian):
 *             le = 1             # <<<<<<<<<<<<<<
 * 
 *         x[0] = _PyFloat_Unpack4(<unsigned char *>buf, le)
 */
    __pyx_v_le = 1;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":974
 *             le = 1
 * 
 *         x[0] = _PyFloat_Unpack4(<unsigned char *>buf, le)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  (__pyx_v_x[0]) = _PyFloat_Unpack4(((unsigned char *)__pyx_v_buf), __pyx_v_le);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":975
 * 
 *         x[0] = _PyFloat_Unpack4(<unsigned char *>buf, le)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":977
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int write_float(self, float c):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.read_float");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":979
 *         return 0
 * 
 *     cdef int write_float(self, float c):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte float to the stream.
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_write_float(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, float __pyx_v_c) {
  unsigned char *__pyx_v_buf;
  unsigned char __pyx_v_le;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_SetupRefcountContext("write_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":987
 *         """
 *         cdef unsigned char *buf
 *         cdef unsigned char le = 1             # <<<<<<<<<<<<<<
 * 
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 4)
 */
  __pyx_v_le = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":989
 *         cdef unsigned char le = 1
 * 
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 4)             # <<<<<<<<<<<<<<
 * 
 *         if buf == NULL:
 */
  __pyx_v_buf = ((unsigned char *)PyMem_Malloc(((sizeof(unsigned char *)) * 4)));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":991
 *         buf = <unsigned char *>PyMem_Malloc(sizeof(unsigned char *) * 4)
 * 
 *         if buf == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError()
 * 
 */
  __pyx_t_1 = (__pyx_v_buf == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":992
 * 
 *         if buf == NULL:
 *             raise MemoryError()             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":994
 *             raise MemoryError()
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             le = 0
 * 
 */
  __pyx_t_3 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_3) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":995
 * 
 *         if is_big_endian(self._endian):
 *             le = 0             # <<<<<<<<<<<<<<
 * 
 *         if _PyFloat_Pack4(c, <unsigned char *>buf, le) == -1:
 */
    __pyx_v_le = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":997
 *             le = 0
 * 
 *         if _PyFloat_Pack4(c, <unsigned char *>buf, le) == -1:             # <<<<<<<<<<<<<<
 *             PyMem_Free(buf)
 * 
 */
  __pyx_t_1 = (_PyFloat_Pack4(__pyx_v_c, ((unsigned char *)__pyx_v_buf), __pyx_v_le) == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":998
 * 
 *         if _PyFloat_Pack4(c, <unsigned char *>buf, le) == -1:
 *             PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *             return -1
 */
    PyMem_Free(__pyx_v_buf);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1000
 *             PyMem_Free(buf)
 * 
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         if self.write(<char *>buf, 4) == -1:
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1002
 *             return -1
 * 
 *         if self.write(<char *>buf, 4) == -1:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, ((char *)__pyx_v_buf), 4); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = (__pyx_t_3 == -1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1003
 * 
 *         if self.write(<char *>buf, 4) == -1:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(buf)
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1005
 *             return -1
 * 
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1007
 *         PyMem_Free(buf)
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int append(self, object obj) except? -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.write_float");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1009
 *         return 0
 * 
 *     cdef int append(self, object obj) except? -1:             # <<<<<<<<<<<<<<
 *         cdef int i = self.pos
 * 
 */

static  int __pyx_f_6cpyamf_4util_19cBufferedByteStream_append(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_self, PyObject *__pyx_v_obj) {
  int __pyx_v_i;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("append");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1010
 * 
 *     cdef int append(self, object obj) except? -1:
 *         cdef int i = self.pos             # <<<<<<<<<<<<<<
 * 
 *         self.pos = self.length
 */
  __pyx_v_i = __pyx_v_self->pos;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1012
 *         cdef int i = self.pos
 * 
 *         self.pos = self.length             # <<<<<<<<<<<<<<
 * 
 *         if hasattr(obj, 'getvalue'):
 */
  __pyx_v_self->pos = __pyx_v_self->length;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1014
 *         self.pos = self.length
 * 
 *         if hasattr(obj, 'getvalue'):             # <<<<<<<<<<<<<<
 *             self.write_utf8_string(obj.getvalue())
 *         else:
 */
  __pyx_t_1 = PyObject_HasAttr(__pyx_v_obj, __pyx_kp_29); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1015
 * 
 *         if hasattr(obj, 'getvalue'):
 *             self.write_utf8_string(obj.getvalue())             # <<<<<<<<<<<<<<
 *         else:
 *             self.write_utf8_string(obj)
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_obj, __pyx_kp_getvalue); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write_utf8_string(__pyx_v_self, __pyx_t_3); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1017
 *             self.write_utf8_string(obj.getvalue())
 *         else:
 *             self.write_utf8_string(obj)             # <<<<<<<<<<<<<<
 * 
 *         self.pos = i
 */
    __pyx_t_4 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self->__pyx_vtab)->write_utf8_string(__pyx_v_self, __pyx_v_obj); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1019
 *             self.write_utf8_string(obj)
 * 
 *         self.pos = i             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_self->pos = __pyx_v_i;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.cBufferedByteStream.append");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1029
 *     """
 * 
 *     def __init__(self, buf=None):             # <<<<<<<<<<<<<<
 *         """
 *         @raise TypeError: Unable to coerce buf -> StringIO
 */

static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream___init__[] = "\n        @raise TypeError: Unable to coerce buf -> StringIO\n        ";
static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_buf = 0;
  struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *__pyx_v_x;
  PyObject *__pyx_v_old_pos;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_buf,0};
  __Pyx_SetupRefcountContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = Py_None;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_buf);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_buf = values[0];
  } else {
    __pyx_v_buf = Py_None;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_buf = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_x = ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_old_pos = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1036
 *         cdef cBufferedByteStream x
 * 
 *         if isinstance(buf, cBufferedByteStream):             # <<<<<<<<<<<<<<
 *             x = <cBufferedByteStream>buf
 *             self.write(x.getvalue())
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_buf, ((PyTypeObject *)((PyObject*)__pyx_ptype_6cpyamf_4util_cBufferedByteStream))); 
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1037
 * 
 *         if isinstance(buf, cBufferedByteStream):
 *             x = <cBufferedByteStream>buf             # <<<<<<<<<<<<<<
 *             self.write(x.getvalue())
 *         elif isinstance(buf, (str, unicode)):
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_buf)));
    __Pyx_DECREF(((PyObject *)__pyx_v_x));
    __pyx_v_x = ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_buf);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1038
 *         if isinstance(buf, cBufferedByteStream):
 *             x = <cBufferedByteStream>buf
 *             self.write(x.getvalue())             # <<<<<<<<<<<<<<
 *         elif isinstance(buf, (str, unicode)):
 *             self.write(buf)
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = ((struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream *)__pyx_v_x->__pyx_vtab)->getvalue(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L6;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1039
 *             x = <cBufferedByteStream>buf
 *             self.write(x.getvalue())
 *         elif isinstance(buf, (str, unicode)):             # <<<<<<<<<<<<<<
 *             self.write(buf)
 *         elif hasattr(buf, 'getvalue'):
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)((PyObject*)&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyUnicode_Type)));
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_buf, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1040
 *             self.write(x.getvalue())
 *         elif isinstance(buf, (str, unicode)):
 *             self.write(buf)             # <<<<<<<<<<<<<<
 *         elif hasattr(buf, 'getvalue'):
 *             self.write(buf.getvalue())
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_v_buf);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_buf);
    __Pyx_GIVEREF(__pyx_v_buf);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1041
 *         elif isinstance(buf, (str, unicode)):
 *             self.write(buf)
 *         elif hasattr(buf, 'getvalue'):             # <<<<<<<<<<<<<<
 *             self.write(buf.getvalue())
 *         elif hasattr(buf, 'read') and hasattr(buf, 'seek') and hasattr(buf, 'tell'):
 */
  __pyx_t_1 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_30); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1042
 *             self.write(buf)
 *         elif hasattr(buf, 'getvalue'):
 *             self.write(buf.getvalue())             # <<<<<<<<<<<<<<
 *         elif hasattr(buf, 'read') and hasattr(buf, 'seek') and hasattr(buf, 'tell'):
 *             old_pos = buf.tell()
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L6;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1043
 *         elif hasattr(buf, 'getvalue'):
 *             self.write(buf.getvalue())
 *         elif hasattr(buf, 'read') and hasattr(buf, 'seek') and hasattr(buf, 'tell'):             # <<<<<<<<<<<<<<
 *             old_pos = buf.tell()
 *             buf.seek(0)
 */
  __pyx_t_1 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_31); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    __pyx_t_5 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_32); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {
      __pyx_t_6 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_33); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = __pyx_t_6;
    } else {
      __pyx_t_7 = __pyx_t_5;
    }
    __pyx_t_5 = __pyx_t_7;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1044
 *             self.write(buf.getvalue())
 *         elif hasattr(buf, 'read') and hasattr(buf, 'seek') and hasattr(buf, 'tell'):
 *             old_pos = buf.tell()             # <<<<<<<<<<<<<<
 *             buf.seek(0)
 *             self.write(buf.read())
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_tell); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_old_pos);
    __pyx_v_old_pos = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1045
 *         elif hasattr(buf, 'read') and hasattr(buf, 'seek') and hasattr(buf, 'tell'):
 *             old_pos = buf.tell()
 *             buf.seek(0)             # <<<<<<<<<<<<<<
 *             self.write(buf.read())
 *             buf.seek(old_pos)
 */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1046
 *             old_pos = buf.tell()
 *             buf.seek(0)
 *             self.write(buf.read())             # <<<<<<<<<<<<<<
 *             buf.seek(old_pos)
 *         elif buf is None:
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_read); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1047
 *             buf.seek(0)
 *             self.write(buf.read())
 *             buf.seek(old_pos)             # <<<<<<<<<<<<<<
 *         elif buf is None:
 *             pass
 */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_old_pos);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_old_pos);
    __Pyx_GIVEREF(__pyx_v_old_pos);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1048
 *             self.write(buf.read())
 *             buf.seek(old_pos)
 *         elif buf is None:             # <<<<<<<<<<<<<<
 *             pass
 *         else:
 */
  __pyx_t_5 = (__pyx_v_buf == Py_None);
  if (__pyx_t_5) {
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1051
 *             pass
 *         else:
 *             raise TypeError("Unable to coerce buf->StringIO")             # <<<<<<<<<<<<<<
 * 
 *         self.seek(0)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_34);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_34);
    __Pyx_GIVEREF(__pyx_kp_34);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1053
 *             raise TypeError("Unable to coerce buf->StringIO")
 * 
 *         self.seek(0)             # <<<<<<<<<<<<<<
 * 
 *     property endian:
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_seek); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_x);
  __Pyx_DECREF(__pyx_v_old_pos);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1056
 * 
 *     property endian:
 *         def __set__(self, value):             # <<<<<<<<<<<<<<
 *             if PyString_Check(value) == 0:
 *                 raise TypeError('String value expected')
 */

static int __pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("__set__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1057
 *     property endian:
 *         def __set__(self, value):
 *             if PyString_Check(value) == 0:             # <<<<<<<<<<<<<<
 *                 raise TypeError('String value expected')
 * 
 */
  __pyx_t_1 = (PyString_Check(__pyx_v_value) == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1058
 *         def __set__(self, value):
 *             if PyString_Check(value) == 0:
 *                 raise TypeError('String value expected')             # <<<<<<<<<<<<<<
 * 
 *             if value not in [ENDIAN_NETWORK, ENDIAN_NATIVE, ENDIAN_LITTLE, ENDIAN_BIG]:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_35);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_35);
    __Pyx_GIVEREF(__pyx_kp_35);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1060
 *                 raise TypeError('String value expected')
 * 
 *             if value not in [ENDIAN_NETWORK, ENDIAN_NATIVE, ENDIAN_LITTLE, ENDIAN_BIG]:             # <<<<<<<<<<<<<<
 *                 raise ValueError('Not a valid endian type')
 * 
 */
  __Pyx_INCREF(__pyx_v_value);
  __pyx_t_3 = __pyx_v_value;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_36, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_37, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((int)__pyx_t_4);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  if (__pyx_t_5) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_38, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = ((int)__pyx_t_1);
  } else {
    __pyx_t_4 = __pyx_t_5;
  }
  if (__pyx_t_4) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_39, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_1 = ((int)__pyx_t_5);
  } else {
    __pyx_t_1 = __pyx_t_4;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_t_1;
  if (__pyx_t_4) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1061
 * 
 *             if value not in [ENDIAN_NETWORK, ENDIAN_NATIVE, ENDIAN_LITTLE, ENDIAN_BIG]:
 *                 raise ValueError('Not a valid endian type')             # <<<<<<<<<<<<<<
 * 
 *             self._endian = PyString_AsString(value)[0]
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_40);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_40);
    __Pyx_GIVEREF(__pyx_kp_40);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1063
 *                 raise ValueError('Not a valid endian type')
 * 
 *             self._endian = PyString_AsString(value)[0]             # <<<<<<<<<<<<<<
 * 
 *         def __get__(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base._endian = (PyString_AsString(__pyx_v_value)[0]);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.endian.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1065
 *             self._endian = PyString_AsString(value)[0]
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return PyString_FromStringAndSize(&self._endian, 1)
 * 
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("__get__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1066
 * 
 *         def __get__(self):
 *             return PyString_FromStringAndSize(&self._endian, 1)             # <<<<<<<<<<<<<<
 * 
 *     def read(self, size=-1):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyString_FromStringAndSize((&((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base._endian), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.endian.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1068
 *             return PyString_FromStringAndSize(&self._endian, 1)
 * 
 *     def read(self, size=-1):             # <<<<<<<<<<<<<<
 *         """
 *         Reads C{size} bytes from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read[] = "\n        Reads C{size} bytes from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_size = 0;
  Py_ssize_t __pyx_v_s;
  char *__pyx_v_buf;
  PyObject *__pyx_v_r;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_size,0};
  __Pyx_SetupRefcountContext("read");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = __pyx_int_neg_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_size = values[0];
  } else {
    __pyx_v_size = __pyx_int_neg_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_r = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1075
 *         cdef object cls
 * 
 *         if size != -1:             # <<<<<<<<<<<<<<
 *             s = <Py_ssize_t>size
 *         else:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_size, __pyx_int_neg_1, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1076
 * 
 *         if size != -1:
 *             s = <Py_ssize_t>size             # <<<<<<<<<<<<<<
 *         else:
 *             s = cBufferedByteStream.remaining(self)
 */
    __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_size); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_s = ((Py_ssize_t)__pyx_t_3);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1078
 *             s = <Py_ssize_t>size
 *         else:
 *             s = cBufferedByteStream.remaining(self)             # <<<<<<<<<<<<<<
 * 
 *             if s == 0:
 */
    __pyx_t_3 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->remaining(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_s = __pyx_t_3;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1080
 *             s = cBufferedByteStream.remaining(self)
 * 
 *             if s == 0:             # <<<<<<<<<<<<<<
 *                 s = 1
 * 
 */
    __pyx_t_2 = (__pyx_v_s == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1081
 * 
 *             if s == 0:
 *                 s = 1             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
      __pyx_v_s = 1;
      goto __pyx_L7;
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1083
 *                 s = 1
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read(self, &buf, s)
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1085
 *         cdef char *buf = NULL
 * 
 *         cBufferedByteStream.read(self, &buf, s)             # <<<<<<<<<<<<<<
 * 
 *         r = PyString_FromStringAndSize(buf, s)
 */
  __pyx_t_4 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), (&__pyx_v_buf), __pyx_v_s); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1087
 *         cBufferedByteStream.read(self, &buf, s)
 * 
 *         r = PyString_FromStringAndSize(buf, s)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  __pyx_t_1 = PyString_FromStringAndSize(__pyx_v_buf, __pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_r);
  __pyx_v_r = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1088
 * 
 *         r = PyString_FromStringAndSize(buf, s)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return r
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1090
 *         PyMem_Free(buf)
 * 
 *         return r             # <<<<<<<<<<<<<<
 * 
 *     def write(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_r);
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_r);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1092
 *         return r
 * 
 *     def write(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes the content of the specified C{x} into this buffer.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write[] = "\n        Writes the content of the specified C{x} into this buffer.\n\n        @param x:\n        @type x:\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1099
 *         @type x:
 *         """
 *         cBufferedByteStream.write_utf8_string(self, x)             # <<<<<<<<<<<<<<
 * 
 *     def close(self):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_utf8_string(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_x); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1101
 *         cBufferedByteStream.write_utf8_string(self, x)
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         """
 *         Close the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_close(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_close[] = "\n        Close the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_close(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("close");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1105
 *         Close the stream.
 *         """
 *         cBufferedByteStream.close(self)             # <<<<<<<<<<<<<<
 * 
 *     def flush(self):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->close(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.close");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1107
 *         cBufferedByteStream.close(self)
 * 
 *     def flush(self):             # <<<<<<<<<<<<<<
 *         # no-op
 *         pass
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_flush(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_flush(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_SetupRefcountContext("flush");

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1111
 *         pass
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         """
 *         Returns the position of the stream pointer.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_tell[] = "\n        Returns the position of the stream pointer.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("tell");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1115
 *         Returns the position of the stream pointer.
 *         """
 *         return self.pos             # <<<<<<<<<<<<<<
 * 
 *     def remaining(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromSsize_t(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.tell");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1117
 *         return self.pos
 * 
 *     def remaining(self):             # <<<<<<<<<<<<<<
 *         """
 *         Returns number of remaining bytes.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_remaining[] = "\n        Returns number of remaining bytes.\n\n        @rtype: C{number}\n        @return: Number of remaining bytes.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_SetupRefcountContext("remaining");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1124
 *         @return: Number of remaining bytes.
 *         """
 *         return cBufferedByteStream.remaining(self)             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->remaining(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.remaining");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1126
 *         return cBufferedByteStream.remaining(self)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.length
 * 
 */

static Py_ssize_t __pyx_pf_6cpyamf_4util_18BufferedByteStream___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pf_6cpyamf_4util_18BufferedByteStream___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_SetupRefcountContext("__len__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1127
 * 
 *     def __len__(self):
 *         return self.length             # <<<<<<<<<<<<<<
 * 
 *     def getvalue(self):
 */
  __pyx_r = ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base.length;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1129
 *         return self.length
 * 
 *     def getvalue(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get raw data from buffer.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_getvalue[] = "\n        Get raw data from buffer.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("getvalue");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1133
 *         Get raw data from buffer.
 *         """
 *         return cBufferedByteStream.getvalue(self)             # <<<<<<<<<<<<<<
 * 
 *     def at_eof(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->getvalue(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.getvalue");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1135
 *         return cBufferedByteStream.getvalue(self)
 * 
 *     def at_eof(self):             # <<<<<<<<<<<<<<
 *         """
 *         Returns C{True} if the internal pointer is at the end of the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_at_eof[] = "\n        Returns C{True} if the internal pointer is at the end of the stream.\n\n        @rtype: C{bool}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof(PyObject *__pyx_v_self, PyObject *unused) {
  int __pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_SetupRefcountContext("at_eof");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1141
 *         @rtype: C{bool}
 *         """
 *         cdef int result = cBufferedByteStream.at_eof(self)             # <<<<<<<<<<<<<<
 * 
 *         return (result == 1)
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->at_eof(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_result = __pyx_t_1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1143
 *         cdef int result = cBufferedByteStream.at_eof(self)
 * 
 *         return (result == 1)             # <<<<<<<<<<<<<<
 * 
 *     def seek(self, pos, mode=0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong((__pyx_v_result == 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.at_eof");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1145
 *         return (result == 1)
 * 
 *     def seek(self, pos, mode=0):             # <<<<<<<<<<<<<<
 *         """
 *         Sets the file-pointer offset, measured from the beginning of this stream,
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_seek[] = "\n        Sets the file-pointer offset, measured from the beginning of this stream,\n        at which the next write operation will occur.\n\n        @param pos:\n        @type pos: C{int}\n        @param mode:\n        @type mode: C{int}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pos = 0;
  PyObject *__pyx_v_mode = 0;
  PyObject *__pyx_r = NULL;
  struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek __pyx_1;
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pos,&__pyx_kp_mode,0};
  __Pyx_SetupRefcountContext("seek");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pos);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_mode);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pos = values[0];
    __pyx_v_mode = values[1];
  } else {
    __pyx_v_mode = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_mode = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_pos = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.seek");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1155
 *         @type mode: C{int}
 *         """
 *         cBufferedByteStream.seek(self, pos, mode)             # <<<<<<<<<<<<<<
 * 
 *     def peek(self, size=1):
 */
  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_pos); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_mode); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_1.__pyx_n = 1;
  __pyx_1.mode = __pyx_t_2;
  __pyx_t_3 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->seek(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_t_1, &__pyx_1); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.seek");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1157
 *         cBufferedByteStream.seek(self, pos, mode)
 * 
 *     def peek(self, size=1):             # <<<<<<<<<<<<<<
 *         """
 *         Looks C{size} bytes ahead in the stream, returning what it finds,
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_peek[] = "\n        Looks C{size} bytes ahead in the stream, returning what it finds,\n        returning the stream pointer to its initial position.\n\n        @param size: Default is 1.\n        @type size: C{int}\n\n        @rtype:\n        @return: Bytes.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_size = 0;
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_l;
  PyObject *__pyx_v_r;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_size,0};
  __Pyx_SetupRefcountContext("peek");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = __pyx_int_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "peek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_size = values[0];
  } else {
    __pyx_v_size = __pyx_int_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("peek", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.peek");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_r = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1168
 *         @return: Bytes.
 *         """
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t l
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1171
 *         cdef Py_ssize_t l
 * 
 *         if size == -1:             # <<<<<<<<<<<<<<
 *             l = cBufferedByteStream.remaining(self)
 *         else:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_size, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1172
 * 
 *         if size == -1:
 *             l = cBufferedByteStream.remaining(self)             # <<<<<<<<<<<<<<
 *         else:
 *             l = <int>size
 */
    __pyx_t_3 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->remaining(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_3 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = __pyx_t_3;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1174
 *             l = cBufferedByteStream.remaining(self)
 *         else:
 *             l = <int>size             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.peek(self, &buf, l)
 */
    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_size); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = ((int)__pyx_t_4);
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1176
 *             l = <int>size
 * 
 *         cBufferedByteStream.peek(self, &buf, l)             # <<<<<<<<<<<<<<
 * 
 *         r = PyString_FromStringAndSize(buf, l)
 */
  __pyx_t_4 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->peek(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), (&__pyx_v_buf), __pyx_v_l); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1178
 *         cBufferedByteStream.peek(self, &buf, l)
 * 
 *         r = PyString_FromStringAndSize(buf, l)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  __pyx_t_1 = PyString_FromStringAndSize(__pyx_v_buf, __pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_r);
  __pyx_v_r = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1179
 * 
 *         r = PyString_FromStringAndSize(buf, l)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *         return r
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1181
 *         PyMem_Free(buf)
 * 
 *         return r             # <<<<<<<<<<<<<<
 * 
 *     def truncate(self, int size=0):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_r);
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.peek");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_r);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1183
 *         return r
 * 
 *     def truncate(self, int size=0):             # <<<<<<<<<<<<<<
 *         """
 *         Truncates the stream to the specified length.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_truncate[] = "\n        Truncates the stream to the specified length.\n\n        @param size: The length of the stream, in bytes.\n        @type size: C{int}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_size;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_size,0};
  __Pyx_SetupRefcountContext("truncate");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "truncate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_size = 0;
    }
  } else {
    __pyx_v_size = 0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("truncate", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.truncate");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1190
 *         @type size: C{int}
 *         """
 *         cBufferedByteStream.truncate(self, size)             # <<<<<<<<<<<<<<
 * 
 *     def consume(self):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->truncate(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_size); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.truncate");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1192
 *         cBufferedByteStream.truncate(self, size)
 * 
 *     def consume(self):             # <<<<<<<<<<<<<<
 *         """
 *         Chops the tail off the stream starting at 0 and ending at C{tell()}.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_consume(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_consume[] = "\n        Chops the tail off the stream starting at 0 and ending at C{tell()}.\n        The stream pointer is set to 0 at the end of this function.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_consume(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("consume");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1197
 *         The stream pointer is set to 0 at the end of this function.
 *         """
 *         cBufferedByteStream.consume(self)             # <<<<<<<<<<<<<<
 * 
 *     def read_uchar(self):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->consume(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.consume");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1199
 *         cBufferedByteStream.consume(self)
 * 
 *     def read_uchar(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads an C{unsigned char} from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_uchar[] = "\n        Reads an C{unsigned char} from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar(PyObject *__pyx_v_self, PyObject *unused) {
  unsigned char *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_uchar");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1203
 *         Reads an C{unsigned char} from the stream.
 *         """
 *         cdef unsigned char *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1206
 *         cdef object ret
 * 
 *         i = <unsigned char *>PyMem_Malloc(1 * sizeof(unsigned char))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((unsigned char *)PyMem_Malloc((1 * (sizeof(unsigned char)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1208
 *         i = <unsigned char *>PyMem_Malloc(1 * sizeof(unsigned char))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1209
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_uchar(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1211
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_uchar(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <unsigned char>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_uchar(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1213
 *         cBufferedByteStream.read_uchar(self, i)
 * 
 *         ret = <unsigned char>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((unsigned char)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1214
 * 
 *         ret = <unsigned char>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1216
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_char(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_uchar");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1218
 *         return ret
 * 
 *     def read_char(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a C{char} from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_char[] = "\n        Reads a C{char} from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_char");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1222
 *         Reads a C{char} from the stream.
 *         """
 *         cdef char *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1225
 *         cdef object ret
 * 
 *         i = <char *>PyMem_Malloc(1 * sizeof(char))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((char *)PyMem_Malloc((1 * (sizeof(char)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1227
 *         i = <char *>PyMem_Malloc(1 * sizeof(char))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1228
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_char(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1230
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_char(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <char>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_char(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1232
 *         cBufferedByteStream.read_char(self, i)
 * 
 *         ret = <char>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((char)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1233
 * 
 *         ret = <char>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1235
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_ushort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_char");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1237
 *         return ret
 * 
 *     def read_ushort(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 2 byte unsigned integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_ushort[] = "\n        Reads a 2 byte unsigned integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort(PyObject *__pyx_v_self, PyObject *unused) {
  unsigned short *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_ushort");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1241
 *         Reads a 2 byte unsigned integer from the stream.
 *         """
 *         cdef unsigned short *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1244
 *         cdef object ret
 * 
 *         i = <unsigned short *>PyMem_Malloc(1 * sizeof(unsigned short))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((unsigned short *)PyMem_Malloc((1 * (sizeof(unsigned short)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1246
 *         i = <unsigned short *>PyMem_Malloc(1 * sizeof(unsigned short))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1247
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_ushort(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1249
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_ushort(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <unsigned short>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_ushort(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1251
 *         cBufferedByteStream.read_ushort(self, i)
 * 
 *         ret = <unsigned short>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((unsigned short)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1252
 * 
 *         ret = <unsigned short>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1254
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_short(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_ushort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1256
 *         return ret
 * 
 *     def read_short(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 2 byte integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_short[] = "\n        Reads a 2 byte integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short(PyObject *__pyx_v_self, PyObject *unused) {
  short *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_short");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1260
 *         Reads a 2 byte integer from the stream.
 *         """
 *         cdef short *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1263
 *         cdef object ret
 * 
 *         i = <short *>PyMem_Malloc(1 * sizeof(short))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((short *)PyMem_Malloc((1 * (sizeof(short)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1265
 *         i = <short *>PyMem_Malloc(1 * sizeof(short))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1266
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_short(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1268
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_short(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <short>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_short(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1270
 *         cBufferedByteStream.read_short(self, i)
 * 
 *         ret = <short>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((short)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1271
 * 
 *         ret = <short>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1273
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_ulong(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_short");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1275
 *         return ret
 * 
 *     def read_ulong(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte unsigned integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_ulong[] = "\n        Reads a 4 byte unsigned integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong(PyObject *__pyx_v_self, PyObject *unused) {
  unsigned long *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_ulong");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1279
 *         Reads a 4 byte unsigned integer from the stream.
 *         """
 *         cdef unsigned long *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1282
 *         cdef object ret
 * 
 *         i = <unsigned long *>PyMem_Malloc(1 * sizeof(unsigned long))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((unsigned long *)PyMem_Malloc((1 * (sizeof(unsigned long)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1284
 *         i = <unsigned long *>PyMem_Malloc(1 * sizeof(unsigned long))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1285
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_ulong(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1287
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_ulong(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <unsigned long>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_ulong(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1289
 *         cBufferedByteStream.read_ulong(self, i)
 * 
 *         ret = <unsigned long>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyLong_FromUnsignedLong(((unsigned long)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1290
 * 
 *         ret = <unsigned long>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1292
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_long(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_ulong");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1294
 *         return ret
 * 
 *     def read_long(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_long[] = "\n        Reads a 4 byte integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long(PyObject *__pyx_v_self, PyObject *unused) {
  long *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_long");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1298
 *         Reads a 4 byte integer from the stream.
 *         """
 *         cdef long *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1301
 *         cdef object ret
 * 
 *         i = <long *>PyMem_Malloc(1 * sizeof(long))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((long *)PyMem_Malloc((1 * (sizeof(long)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1303
 *         i = <long *>PyMem_Malloc(1 * sizeof(long))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1304
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_long(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1306
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_long(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <long>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_long(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1308
 *         cBufferedByteStream.read_long(self, i)
 * 
 *         ret = <long>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((long)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1309
 * 
 *         ret = <long>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1311
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_24bit_uint(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_long");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1313
 *         return ret
 * 
 *     def read_24bit_uint(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 24 bit unsigned integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_uint(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_24bit_uint[] = "\n        Reads a 24 bit unsigned integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_uint(PyObject *__pyx_v_self, PyObject *unused) {
  unsigned long *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_24bit_uint");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1317
 *         Reads a 24 bit unsigned integer from the stream.
 *         """
 *         cdef unsigned long *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1320
 *         cdef object ret
 * 
 *         i = <unsigned long *>PyMem_Malloc(1 * sizeof(unsigned long))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((unsigned long *)PyMem_Malloc((1 * (sizeof(unsigned long)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1322
 *         i = <unsigned long *>PyMem_Malloc(1 * sizeof(unsigned long))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1323
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_24bit_uint(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1325
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_24bit_uint(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <long>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_24bit_uint(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1327
 *         cBufferedByteStream.read_24bit_uint(self, i)
 * 
 *         ret = <long>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((long)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1328
 * 
 *         ret = <long>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1330
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def read_24bit_int(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_24bit_uint");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1332
 *         return ret
 * 
 *     def read_24bit_int(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 24 bit integer from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_int(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_24bit_int[] = "\n        Reads a 24 bit integer from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_int(PyObject *__pyx_v_self, PyObject *unused) {
  long *__pyx_v_i;
  PyObject *__pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_24bit_int");
  __pyx_v_ret = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1336
 *         Reads a 24 bit integer from the stream.
 *         """
 *         cdef long *i = NULL             # <<<<<<<<<<<<<<
 *         cdef object ret
 * 
 */
  __pyx_v_i = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1339
 *         cdef object ret
 * 
 *         i = <long *>PyMem_Malloc(1 * sizeof(long))             # <<<<<<<<<<<<<<
 * 
 *         if i == NULL:
 */
  __pyx_v_i = ((long *)PyMem_Malloc((1 * (sizeof(long)))));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1341
 *         i = <long *>PyMem_Malloc(1 * sizeof(long))
 * 
 *         if i == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError
 * 
 */
  __pyx_t_1 = (__pyx_v_i == NULL);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1342
 * 
 *         if i == NULL:
 *             raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.read_24bit_int(self, i)
 */
    __Pyx_Raise(__pyx_builtin_MemoryError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1344
 *             raise MemoryError
 * 
 *         cBufferedByteStream.read_24bit_int(self, i)             # <<<<<<<<<<<<<<
 * 
 *         ret = <long>(i[0])
 */
  __pyx_t_2 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_24bit_int(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_i); if (unlikely(__pyx_t_2 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1346
 *         cBufferedByteStream.read_24bit_int(self, i)
 * 
 *         ret = <long>(i[0])             # <<<<<<<<<<<<<<
 *         PyMem_Free(i)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((long)(__pyx_v_i[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_ret);
  __pyx_v_ret = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1347
 * 
 *         ret = <long>(i[0])
 *         PyMem_Free(i)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  PyMem_Free(__pyx_v_i);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1349
 *         PyMem_Free(i)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def write_uchar(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_24bit_int");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1351
 *         return ret
 * 
 *     def write_uchar(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes an C{unsigned char} to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_uchar[] = "\n        Writes an C{unsigned char} to the stream.\n\n        @param x: Unsigned char\n        @type x: C{int}\n        @raise TypeError: Unexpected type for int C{x}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned char __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write_uchar");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1359
 *         @raise TypeError: Unexpected type for int C{x}.
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('expected int for x')
 * 
 */
  if ((PyInt_Check(__pyx_v_x) == 0)) {
    __pyx_t_1 = (PyLong_Check(__pyx_v_x) == 0);
  } else {
    __pyx_t_1 = (PyInt_Check(__pyx_v_x) == 0);
  }
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1360
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:
 *             raise TypeError('expected int for x')             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_uchar(self, <unsigned char>x)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_41);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_41);
    __Pyx_GIVEREF(__pyx_kp_41);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1362
 *             raise TypeError('expected int for x')
 * 
 *         cBufferedByteStream.write_uchar(self, <unsigned char>x)             # <<<<<<<<<<<<<<
 * 
 *     def write_char(self, x):
 */
  __pyx_t_4 = __Pyx_PyInt_AsUnsignedChar(__pyx_v_x); if (unlikely((__pyx_t_4 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_uchar(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((unsigned char)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_uchar");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1364
 *         cBufferedByteStream.write_uchar(self, <unsigned char>x)
 * 
 *     def write_char(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Write a C{char} to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_char[] = "\n        Write a C{char} to the stream.\n\n        @param x: char\n        @type x: C{int}\n        @raise TypeError: Unexpected type for int C{x}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write_char");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1372
 *         @raise TypeError: Unexpected type for int C{x}.
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('expected int for x')
 * 
 */
  if ((PyInt_Check(__pyx_v_x) == 0)) {
    __pyx_t_1 = (PyLong_Check(__pyx_v_x) == 0);
  } else {
    __pyx_t_1 = (PyInt_Check(__pyx_v_x) == 0);
  }
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1373
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:
 *             raise TypeError('expected int for x')             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_char(self, <char>x)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_42);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_42);
    __Pyx_GIVEREF(__pyx_kp_42);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1375
 *             raise TypeError('expected int for x')
 * 
 *         cBufferedByteStream.write_char(self, <char>x)             # <<<<<<<<<<<<<<
 * 
 *     def write_ushort(self, x):
 */
  __pyx_t_4 = __Pyx_PyInt_AsChar(__pyx_v_x); if (unlikely((__pyx_t_4 == (char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_char(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((char)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_char");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1377
 *         cBufferedByteStream.write_char(self, <char>x)
 * 
 *     def write_ushort(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 2 byte unsigned integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_ushort[] = "\n        Writes a 2 byte unsigned integer to the stream.\n\n        @param x: 2 byte unsigned integer\n        @type x: C{int}\n        @raise TypeError: Unexpected type for int C{x}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned short __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write_ushort");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1385
 *         @raise TypeError: Unexpected type for int C{x}.
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('expected int for x')
 * 
 */
  if ((PyInt_Check(__pyx_v_x) == 0)) {
    __pyx_t_1 = (PyLong_Check(__pyx_v_x) == 0);
  } else {
    __pyx_t_1 = (PyInt_Check(__pyx_v_x) == 0);
  }
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1386
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:
 *             raise TypeError('expected int for x')             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_ushort(self, <unsigned short>x)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_43);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_43);
    __Pyx_GIVEREF(__pyx_kp_43);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1388
 *             raise TypeError('expected int for x')
 * 
 *         cBufferedByteStream.write_ushort(self, <unsigned short>x)             # <<<<<<<<<<<<<<
 * 
 *     def write_short(self, x):
 */
  __pyx_t_4 = __Pyx_PyInt_AsUnsignedShort(__pyx_v_x); if (unlikely((__pyx_t_4 == (unsigned short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_ushort(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((unsigned short)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_ushort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1390
 *         cBufferedByteStream.write_ushort(self, <unsigned short>x)
 * 
 *     def write_short(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 2 byte integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_short[] = "\n        Writes a 2 byte integer to the stream.\n\n        @param x: 2 byte integer\n        @type x: C{int}\n        @raise TypeError: Unexpected type for int C{x}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  short __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write_short");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1398
 *         @raise TypeError: Unexpected type for int C{x}.
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('expected int for x')
 * 
 */
  if ((PyInt_Check(__pyx_v_x) == 0)) {
    __pyx_t_1 = (PyLong_Check(__pyx_v_x) == 0);
  } else {
    __pyx_t_1 = (PyInt_Check(__pyx_v_x) == 0);
  }
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1399
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:
 *             raise TypeError('expected int for x')             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_short(self, <short>x)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_44);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_44);
    __Pyx_GIVEREF(__pyx_kp_44);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1401
 *             raise TypeError('expected int for x')
 * 
 *         cBufferedByteStream.write_short(self, <short>x)             # <<<<<<<<<<<<<<
 * 
 *     def write_ulong(self, x):
 */
  __pyx_t_4 = __Pyx_PyInt_AsShort(__pyx_v_x); if (unlikely((__pyx_t_4 == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_short(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((short)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_short");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1403
 *         cBufferedByteStream.write_short(self, <short>x)
 * 
 *     def write_ulong(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte unsigned integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_ulong[] = "\n        Writes a 4 byte unsigned integer to the stream.\n\n        @param x: 4 byte unsigned integer\n        @type x: C{int}\n        @raise TypeError: Unexpected type for int C{x}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  unsigned long __pyx_t_6;
  int __pyx_t_7;
  __Pyx_SetupRefcountContext("write_ulong");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1411
 *         @raise TypeError: Unexpected type for int C{x}.
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('expected int for x')
 * 
 */
  if ((PyInt_Check(__pyx_v_x) == 0)) {
    __pyx_t_1 = (PyLong_Check(__pyx_v_x) == 0);
  } else {
    __pyx_t_1 = (PyInt_Check(__pyx_v_x) == 0);
  }
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1412
 *         """
 *         if PyInt_Check(x) == 0 and PyLong_Check(x) == 0:
 *             raise TypeError('expected int for x')             # <<<<<<<<<<<<<<
 * 
 *         if x > 4294967295L or x < 0:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_45);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_45);
    __Pyx_GIVEREF(__pyx_kp_45);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1414
 *             raise TypeError('expected int for x')
 * 
 *         if x > 4294967295L or x < 0:             # <<<<<<<<<<<<<<
 *             raise OverflowError
 * 
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_x, __pyx_int_4294967295L, Py_GT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_1) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1415
 * 
 *         if x > 4294967295L or x < 0:
 *             raise OverflowError             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_ulong(self, <unsigned long>x)
 */
    __Pyx_Raise(__pyx_builtin_OverflowError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1417
 *             raise OverflowError
 * 
 *         cBufferedByteStream.write_ulong(self, <unsigned long>x)             # <<<<<<<<<<<<<<
 * 
 *     def write_long(self, long x):
 */
  __pyx_t_6 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_x); if (unlikely((__pyx_t_6 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_ulong(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((unsigned long)__pyx_t_6)); if (unlikely(__pyx_t_7 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_ulong");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1419
 *         cBufferedByteStream.write_ulong(self, <unsigned long>x)
 * 
 *     def write_long(self, long x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long(PyObject *__pyx_v_self, PyObject *__pyx_arg_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_long[] = "\n        Writes a 4 byte integer to the stream.\n\n        @param x: 4 byte integer\n        @type x: C{int}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long(PyObject *__pyx_v_self, PyObject *__pyx_arg_x) {
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_long");
  assert(__pyx_arg_x); {
    __pyx_v_x = __Pyx_PyInt_AsLong(__pyx_arg_x); if (unlikely((__pyx_v_x == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1419; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_long");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1426
 *         @type x: C{int}
 *         """
 *         cBufferedByteStream.write_long(self, x)             # <<<<<<<<<<<<<<
 * 
 *     def write_24bit_uint(self, unsigned long x):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_long(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_x); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_long");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1428
 *         cBufferedByteStream.write_long(self, x)
 * 
 *     def write_24bit_uint(self, unsigned long x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 24 bit unsigned integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_uint(PyObject *__pyx_v_self, PyObject *__pyx_arg_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_uint[] = "\n        Writes a 24 bit unsigned integer to the stream.\n\n        @param x: 24 bit unsigned integer\n        @type x: C{int}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_uint(PyObject *__pyx_v_self, PyObject *__pyx_arg_x) {
  unsigned long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_24bit_uint");
  assert(__pyx_arg_x); {
    __pyx_v_x = __Pyx_PyInt_AsUnsignedLong(__pyx_arg_x); if (unlikely((__pyx_v_x == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_24bit_uint");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1435
 *         @type x: C{int}
 *         """
 *         cBufferedByteStream.write_24bit_uint(self, x)             # <<<<<<<<<<<<<<
 * 
 *     def write_24bit_int(self, long x):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_24bit_uint(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_x); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_24bit_uint");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1437
 *         cBufferedByteStream.write_24bit_uint(self, x)
 * 
 *     def write_24bit_int(self, long x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 24 bit integer to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_int(PyObject *__pyx_v_self, PyObject *__pyx_arg_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_int[] = "\n        Writes a 24 bit integer to the stream.\n\n        @param x: 24 bit integer\n        @type x: C{int}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_int(PyObject *__pyx_v_self, PyObject *__pyx_arg_x) {
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_24bit_int");
  assert(__pyx_arg_x); {
    __pyx_v_x = __Pyx_PyInt_AsLong(__pyx_arg_x); if (unlikely((__pyx_v_x == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_24bit_int");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1444
 *         @type x: C{int}
 *         """
 *         cBufferedByteStream.write_24bit_int(self, x)             # <<<<<<<<<<<<<<
 * 
 *     def read_utf8_string(self, unsigned int size):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_24bit_int(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_x); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_24bit_int");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1446
 *         cBufferedByteStream.write_24bit_int(self, x)
 * 
 *     def read_utf8_string(self, unsigned int size):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a UTF-8 string from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_arg_size); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_utf8_string[] = "\n        Reads a UTF-8 string from the stream.\n\n        @rtype: C{unicode}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_arg_size) {
  unsigned int __pyx_v_size;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("read_utf8_string");
  assert(__pyx_arg_size); {
    __pyx_v_size = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_size); if (unlikely((__pyx_v_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_utf8_string");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1452
 *         @rtype: C{unicode}
 *         """
 *         return cBufferedByteStream.read_utf8_string(self, size)             # <<<<<<<<<<<<<<
 * 
 *     def write_utf8_string(self, obj):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_utf8_string(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_utf8_string");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1454
 *         return cBufferedByteStream.read_utf8_string(self, size)
 * 
 *     def write_utf8_string(self, obj):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a unicode object to the stream in UTF-8.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_v_obj); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_utf8_string[] = "\n        Writes a unicode object to the stream in UTF-8.\n\n        @param obj: unicode object\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("write_utf8_string");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1460
 *         @param obj: unicode object
 *         """
 *         cBufferedByteStream.write_utf8_string(self, obj)             # <<<<<<<<<<<<<<
 * 
 *     def read_double(self):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_utf8_string(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_obj); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_utf8_string");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1462
 *         cBufferedByteStream.write_utf8_string(self, obj)
 * 
 *     def read_double(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads an 8 byte float from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_double[] = "\n        Reads an 8 byte float from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double(PyObject *__pyx_v_self, PyObject *unused) {
  double __pyx_v_x;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_double");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1468
 *         cdef double x
 * 
 *         if cBufferedByteStream.read_double(self, &x) == -1:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_double(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), (&__pyx_v_x)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1469
 * 
 *         if cBufferedByteStream.read_double(self, &x) == -1:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         if float_broken == 1:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1471
 *             return
 * 
 *         if float_broken == 1:             # <<<<<<<<<<<<<<
 *             if memcmp(&x, &system_nan, 8) == 0:
 *                 return pyamf_NaN
 */
  __pyx_t_2 = (__pyx_v_6cpyamf_4util_float_broken == 1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1472
 * 
 *         if float_broken == 1:
 *             if memcmp(&x, &system_nan, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return pyamf_NaN
 *             elif memcmp(&x, &system_neginf, 8) == 0:
 */
    __pyx_t_2 = (memcmp((&__pyx_v_x), (&__pyx_v_6cpyamf_4util_system_nan), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1473
 *         if float_broken == 1:
 *             if memcmp(&x, &system_nan, 8) == 0:
 *                 return pyamf_NaN             # <<<<<<<<<<<<<<
 *             elif memcmp(&x, &system_neginf, 8) == 0:
 *                 return pyamf_NegInf
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_6cpyamf_4util_pyamf_NaN);
      __pyx_r = __pyx_v_6cpyamf_4util_pyamf_NaN;
      goto __pyx_L0;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1474
 *             if memcmp(&x, &system_nan, 8) == 0:
 *                 return pyamf_NaN
 *             elif memcmp(&x, &system_neginf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return pyamf_NegInf
 *             elif memcmp(&x, &system_posinf, 8) == 0:
 */
    __pyx_t_2 = (memcmp((&__pyx_v_x), (&__pyx_v_6cpyamf_4util_system_neginf), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1475
 *                 return pyamf_NaN
 *             elif memcmp(&x, &system_neginf, 8) == 0:
 *                 return pyamf_NegInf             # <<<<<<<<<<<<<<
 *             elif memcmp(&x, &system_posinf, 8) == 0:
 *                 return pyamf_PosInf
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_6cpyamf_4util_pyamf_NegInf);
      __pyx_r = __pyx_v_6cpyamf_4util_pyamf_NegInf;
      goto __pyx_L0;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1476
 *             elif memcmp(&x, &system_neginf, 8) == 0:
 *                 return pyamf_NegInf
 *             elif memcmp(&x, &system_posinf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return pyamf_PosInf
 * 
 */
    __pyx_t_2 = (memcmp((&__pyx_v_x), (&__pyx_v_6cpyamf_4util_system_posinf), 8) == 0);
    if (__pyx_t_2) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1477
 *                 return pyamf_NegInf
 *             elif memcmp(&x, &system_posinf, 8) == 0:
 *                 return pyamf_PosInf             # <<<<<<<<<<<<<<
 * 
 *         return PyFloat_FromDouble(x)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_6cpyamf_4util_pyamf_PosInf);
      __pyx_r = __pyx_v_6cpyamf_4util_pyamf_PosInf;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1479
 *                 return pyamf_PosInf
 * 
 *         return PyFloat_FromDouble(x)             # <<<<<<<<<<<<<<
 * 
 *     def write_double(self, val):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_double");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1481
 *         return PyFloat_FromDouble(x)
 * 
 *     def write_double(self, val):             # <<<<<<<<<<<<<<
 *         """
 *         Writes an 8 byte float to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_double[] = "\n        Writes an 8 byte float to the stream.\n\n        @param val: 8 byte float\n        @type val: C{float}\n        @raise TypeError: Unexpected type for float C{val}.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  double __pyx_v_d;
  PyObject *__pyx_v_done;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("write_double");
  __pyx_v_done = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1489
 *         @raise TypeError: Unexpected type for float C{val}.
 *         """
 *         if PyFloat_Check(val) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('Expecting float for val')
 * 
 */
  __pyx_t_1 = (PyFloat_Check(__pyx_v_val) == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1490
 *         """
 *         if PyFloat_Check(val) == 0:
 *             raise TypeError('Expecting float for val')             # <<<<<<<<<<<<<<
 * 
 *         cdef double d = PyFloat_AsDouble(val)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_46);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_46);
    __Pyx_GIVEREF(__pyx_kp_46);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1492
 *             raise TypeError('Expecting float for val')
 * 
 *         cdef double d = PyFloat_AsDouble(val)             # <<<<<<<<<<<<<<
 * 
 *         if float_broken == 1:
 */
  __pyx_v_d = PyFloat_AsDouble(__pyx_v_val);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1494
 *         cdef double d = PyFloat_AsDouble(val)
 * 
 *         if float_broken == 1:             # <<<<<<<<<<<<<<
 *             if memcmp(&d, &platform_nan, 8) == 0:
 *                 done = 1
 */
  __pyx_t_1 = (__pyx_v_6cpyamf_4util_float_broken == 1);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1495
 * 
 *         if float_broken == 1:
 *             if memcmp(&d, &platform_nan, 8) == 0:             # <<<<<<<<<<<<<<
 *                 done = 1
 *             elif memcmp(&d, &platform_neginf, 8) == 0:
 */
    __pyx_t_1 = (memcmp((&__pyx_v_d), (&__pyx_v_6cpyamf_4util_platform_nan), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1496
 *         if float_broken == 1:
 *             if memcmp(&d, &platform_nan, 8) == 0:
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(&d, &platform_neginf, 8) == 0:
 *                 done = 1
 */
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_DECREF(__pyx_v_done);
      __pyx_v_done = __pyx_int_1;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1497
 *             if memcmp(&d, &platform_nan, 8) == 0:
 *                 done = 1
 *             elif memcmp(&d, &platform_neginf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 done = 1
 *             elif memcmp(&d, &platform_posinf, 8) == 0:
 */
    __pyx_t_1 = (memcmp((&__pyx_v_d), (&__pyx_v_6cpyamf_4util_platform_neginf), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1498
 *                 done = 1
 *             elif memcmp(&d, &platform_neginf, 8) == 0:
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif memcmp(&d, &platform_posinf, 8) == 0:
 *                 done = 1
 */
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_DECREF(__pyx_v_done);
      __pyx_v_done = __pyx_int_1;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1499
 *             elif memcmp(&d, &platform_neginf, 8) == 0:
 *                 done = 1
 *             elif memcmp(&d, &platform_posinf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 done = 1
 * 
 */
    __pyx_t_1 = (memcmp((&__pyx_v_d), (&__pyx_v_6cpyamf_4util_platform_posinf), 8) == 0);
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1500
 *                 done = 1
 *             elif memcmp(&d, &platform_posinf, 8) == 0:
 *                 done = 1             # <<<<<<<<<<<<<<
 * 
 *             if done == 1:
 */
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_DECREF(__pyx_v_done);
      __pyx_v_done = __pyx_int_1;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1502
 *                 done = 1
 * 
 *             if done == 1:             # <<<<<<<<<<<<<<
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):
 */
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_done, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1503
 * 
 *             if done == 1:
 *                 if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *                     if not is_big_endian(self._endian):
 *                         swap_bytes(<unsigned char *>&d, 8)
 */
      __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
      if (__pyx_t_4) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1504
 *             if done == 1:
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                         swap_bytes(<unsigned char *>&d, 8)
 *                 else:
 */
        __pyx_t_1 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base._endian));
        if (__pyx_t_1) {

          /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1505
 *                 if is_big_endian(SYSTEM_ENDIAN):
 *                     if not is_big_endian(self._endian):
 *                         swap_bytes(<unsigned char *>&d, 8)             # <<<<<<<<<<<<<<
 *                 else:
 *                     if is_big_endian(self._endian):
 */
          __pyx_t_4 = __pyx_f_6cpyamf_4util_swap_bytes(((unsigned char *)(&__pyx_v_d)), 8); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L10;
        }
        __pyx_L10:;
        goto __pyx_L9;
      }
      /*else*/ {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1507
 *                         swap_bytes(<unsigned char *>&d, 8)
 *                 else:
 *                     if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                         swap_bytes(<unsigned char *>&d, 8)
 * 
 */
        __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_base._endian);
        if (__pyx_t_4) {

          /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1508
 *                 else:
 *                     if is_big_endian(self._endian):
 *                         swap_bytes(<unsigned char *>&d, 8)             # <<<<<<<<<<<<<<
 * 
 *                 cBufferedByteStream.write(self, <char *>&d, 8)
 */
          __pyx_t_4 = __pyx_f_6cpyamf_4util_swap_bytes(((unsigned char *)(&__pyx_v_d)), 8); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L11;
        }
        __pyx_L11:;
      }
      __pyx_L9:;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1510
 *                         swap_bytes(<unsigned char *>&d, 8)
 * 
 *                 cBufferedByteStream.write(self, <char *>&d, 8)             # <<<<<<<<<<<<<<
 * 
 *                 return
 */
      __pyx_t_4 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((char *)(&__pyx_v_d)), 8); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1512
 *                 cBufferedByteStream.write(self, <char *>&d, 8)
 * 
 *                 return             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_double(self, d)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      goto __pyx_L8;
    }
    __pyx_L8:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1514
 *                 return
 * 
 *         cBufferedByteStream.write_double(self, d)             # <<<<<<<<<<<<<<
 * 
 *     def read_float(self):
 */
  __pyx_t_4 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_double(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_d); if (unlikely(__pyx_t_4 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_double");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_done);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1516
 *         cBufferedByteStream.write_double(self, d)
 * 
 *     def read_float(self):             # <<<<<<<<<<<<<<
 *         """
 *         Reads a 4 byte float from the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_read_float[] = "\n        Reads a 4 byte float from the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float(PyObject *__pyx_v_self, PyObject *unused) {
  float __pyx_v_x;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("read_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1522
 *         cdef float x
 * 
 *         if cBufferedByteStream.read_float(self, &x) == -1:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->read_float(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), (&__pyx_v_x)); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 == -1);
  if (__pyx_t_2) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1523
 * 
 *         if cBufferedByteStream.read_float(self, &x) == -1:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         return PyFloat_FromDouble(x)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1525
 *             return
 * 
 *         return PyFloat_FromDouble(x)             # <<<<<<<<<<<<<<
 * 
 *     def write_float(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read_float");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1527
 *         return PyFloat_FromDouble(x)
 * 
 *     def write_float(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Writes a 4 byte float to the stream.
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_float[] = "\n        Writes a 4 byte float to the stream.\n\n        @param x: 4 byte float\n        @type x: C{float}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  float __pyx_t_4;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1534
 *         @type x: C{float}
 *         """
 *         if PyFloat_Check(x) == 0:             # <<<<<<<<<<<<<<
 *             raise TypeError('Expecting float for val')
 * 
 */
  __pyx_t_1 = (PyFloat_Check(__pyx_v_x) == 0);
  if (__pyx_t_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1535
 *         """
 *         if PyFloat_Check(x) == 0:
 *             raise TypeError('Expecting float for val')             # <<<<<<<<<<<<<<
 * 
 *         cBufferedByteStream.write_float(self, <float>x)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_47);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_47);
    __Pyx_GIVEREF(__pyx_kp_47);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1537
 *             raise TypeError('Expecting float for val')
 * 
 *         cBufferedByteStream.write_float(self, <float>x)             # <<<<<<<<<<<<<<
 * 
 *     def append(self, data):
 */
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_x); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->write_float(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), ((float)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_float");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1539
 *         cBufferedByteStream.write_float(self, <float>x)
 * 
 *     def append(self, data):             # <<<<<<<<<<<<<<
 *         """
 *         Append data to the end of the stream. The pointer will not move if
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_append(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_append[] = "\n        Append data to the end of the stream. The pointer will not move if\n        this operation is successful.\n\n        @param data: The data to append to the stream.\n        @type data: C{str} or C{unicode}\n        @raise TypeError: data is not C{str} or C{unicode}\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_append(PyObject *__pyx_v_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("append");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1548
 *         @raise TypeError: data is not C{str} or C{unicode}
 *         """
 *         cBufferedByteStream.append(self, data)             # <<<<<<<<<<<<<<
 * 
 *     def __add__(self, other):
 */
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->append(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self), __pyx_v_data); if (unlikely(__pyx_t_1 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.append");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1550
 *         cBufferedByteStream.append(self, data)
 * 
 *     def __add__(self, other):             # <<<<<<<<<<<<<<
 *         cdef long old_pos = <long>self.tell()
 *         cdef long old_other_pos = <long>other.tell()
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream___add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream___add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  long __pyx_v_old_pos;
  long __pyx_v_old_other_pos;
  PyObject *__pyx_v_new;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  long __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("__add__");
  __pyx_v_new = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1551
 * 
 *     def __add__(self, other):
 *         cdef long old_pos = <long>self.tell()             # <<<<<<<<<<<<<<
 *         cdef long old_other_pos = <long>other.tell()
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_tell); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsLong(__pyx_t_2); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_old_pos = ((long)__pyx_t_3);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1552
 *     def __add__(self, other):
 *         cdef long old_pos = <long>self.tell()
 *         cdef long old_other_pos = <long>other.tell()             # <<<<<<<<<<<<<<
 * 
 *         new = BufferedByteStream(self)
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_tell); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsLong(__pyx_t_1); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_old_other_pos = ((long)__pyx_t_3);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1554
 *         cdef long old_other_pos = <long>other.tell()
 * 
 *         new = BufferedByteStream(self)             # <<<<<<<<<<<<<<
 * 
 *         other.seek(0)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6cpyamf_4util_BufferedByteStream)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_new);
  __pyx_v_new = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1556
 *         new = BufferedByteStream(self)
 * 
 *         other.seek(0)             # <<<<<<<<<<<<<<
 *         new.seek(0, 2)
 *         new.write(other.read())
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1557
 * 
 *         other.seek(0)
 *         new.seek(0, 2)             # <<<<<<<<<<<<<<
 *         new.write(other.read())
 * 
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1558
 *         other.seek(0)
 *         new.seek(0, 2)
 *         new.write(other.read())             # <<<<<<<<<<<<<<
 * 
 *         self.seek(old_pos)
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1560
 *         new.write(other.read())
 * 
 *         self.seek(old_pos)             # <<<<<<<<<<<<<<
 *         other.seek(old_other_pos)
 *         new.seek(0)
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_old_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1561
 * 
 *         self.seek(old_pos)
 *         other.seek(old_other_pos)             # <<<<<<<<<<<<<<
 *         new.seek(0)
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_old_other_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1562
 *         self.seek(old_pos)
 *         other.seek(old_other_pos)
 *         new.seek(0)             # <<<<<<<<<<<<<<
 * 
 *         return new
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1564
 *         new.seek(0)
 * 
 *         return new             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_new);
  __pyx_r = __pyx_v_new;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.__add__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_new);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1566
 *         return new
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return cBufferedByteStream.getvalue(self)
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("__str__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":1567
 * 
 *     def __str__(self):
 *         return cBufferedByteStream.getvalue(self)             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream->getvalue(((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream __pyx_vtable_6cpyamf_4util_cBufferedByteStream;

static PyObject *__pyx_tp_new_6cpyamf_4util_cBufferedByteStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *)o);
  p->__pyx_vtab = __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream;
  if (__pyx_pf_6cpyamf_4util_19cBufferedByteStream___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_6cpyamf_4util_cBufferedByteStream(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_6cpyamf_4util_19cBufferedByteStream___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_6cpyamf_4util_cBufferedByteStream[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_cBufferedByteStream = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_cBufferedByteStream = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_cBufferedByteStream = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_cBufferedByteStream = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_6cpyamf_4util_cBufferedByteStream = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("cpyamf.util.cBufferedByteStream"), /*tp_name*/
  sizeof(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6cpyamf_4util_cBufferedByteStream, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_cBufferedByteStream, /*tp_as_number*/
  &__pyx_tp_as_sequence_cBufferedByteStream, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_cBufferedByteStream, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_cBufferedByteStream, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6cpyamf_4util_cBufferedByteStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6cpyamf_4util_cBufferedByteStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};
static struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream __pyx_vtable_6cpyamf_4util_BufferedByteStream;

static PyObject *__pyx_tp_new_6cpyamf_4util_BufferedByteStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6cpyamf_4util_BufferedByteStream *p;
  PyObject *o = __pyx_tp_new_6cpyamf_4util_cBufferedByteStream(t, a, k);
  if (!o) return 0;
  p = ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_6cpyamf_4util_cBufferedByteStream*)__pyx_vtabptr_6cpyamf_4util_BufferedByteStream;
  return o;
}

static PyObject *__pyx_getprop_6cpyamf_4util_18BufferedByteStream_endian(PyObject *o, void *x) {
  return __pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___get__(o);
}

static int __pyx_setprop_6cpyamf_4util_18BufferedByteStream_endian(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6cpyamf_4util_18BufferedByteStream_6endian___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static struct PyMethodDef __pyx_methods_6cpyamf_4util_BufferedByteStream[] = {
  {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_close)},
  {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_flush, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("tell"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_tell)},
  {__Pyx_NAMESTR("remaining"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_remaining)},
  {__Pyx_NAMESTR("getvalue"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_getvalue)},
  {__Pyx_NAMESTR("at_eof"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_at_eof)},
  {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_seek)},
  {__Pyx_NAMESTR("peek"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_peek)},
  {__Pyx_NAMESTR("truncate"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_truncate)},
  {__Pyx_NAMESTR("consume"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_consume, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_consume)},
  {__Pyx_NAMESTR("read_uchar"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_uchar)},
  {__Pyx_NAMESTR("read_char"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_char)},
  {__Pyx_NAMESTR("read_ushort"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_ushort)},
  {__Pyx_NAMESTR("read_short"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_short)},
  {__Pyx_NAMESTR("read_ulong"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_ulong)},
  {__Pyx_NAMESTR("read_long"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_long)},
  {__Pyx_NAMESTR("read_24bit_uint"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_uint, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_24bit_uint)},
  {__Pyx_NAMESTR("read_24bit_int"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_int, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_24bit_int)},
  {__Pyx_NAMESTR("write_uchar"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_uchar)},
  {__Pyx_NAMESTR("write_char"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_char)},
  {__Pyx_NAMESTR("write_ushort"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_ushort)},
  {__Pyx_NAMESTR("write_short"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_short)},
  {__Pyx_NAMESTR("write_ulong"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_ulong)},
  {__Pyx_NAMESTR("write_long"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_long)},
  {__Pyx_NAMESTR("write_24bit_uint"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_uint, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_uint)},
  {__Pyx_NAMESTR("write_24bit_int"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_int, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_int)},
  {__Pyx_NAMESTR("read_utf8_string"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_utf8_string, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_utf8_string)},
  {__Pyx_NAMESTR("write_utf8_string"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_utf8_string)},
  {__Pyx_NAMESTR("read_double"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_double)},
  {__Pyx_NAMESTR("write_double"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_double)},
  {__Pyx_NAMESTR("read_float"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_read_float)},
  {__Pyx_NAMESTR("write_float"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_write_float)},
  {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_append, METH_O, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_append)},
  {__Pyx_NAMESTR("__add__"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream___add__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream___str__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6cpyamf_4util_BufferedByteStream[] = {
  {(char *)"endian", __pyx_getprop_6cpyamf_4util_18BufferedByteStream_endian, __pyx_setprop_6cpyamf_4util_18BufferedByteStream_endian, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_BufferedByteStream = {
  __pyx_pf_6cpyamf_4util_18BufferedByteStream___add__, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_BufferedByteStream = {
  __pyx_pf_6cpyamf_4util_18BufferedByteStream___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_BufferedByteStream = {
  __pyx_pf_6cpyamf_4util_18BufferedByteStream___len__, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_BufferedByteStream = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_6cpyamf_4util_BufferedByteStream = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("cpyamf.util.BufferedByteStream"), /*tp_name*/
  sizeof(struct __pyx_obj_6cpyamf_4util_BufferedByteStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6cpyamf_4util_cBufferedByteStream, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_BufferedByteStream, /*tp_as_number*/
  &__pyx_tp_as_sequence_BufferedByteStream, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_BufferedByteStream, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pf_6cpyamf_4util_18BufferedByteStream___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_BufferedByteStream, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\n    An extension of C{StringIO}.\n\n    @see: L{BufferedByteStream<pyamf.util.BufferedByteStream>}\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6cpyamf_4util_BufferedByteStream, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6cpyamf_4util_BufferedByteStream, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6cpyamf_4util_18BufferedByteStream___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6cpyamf_4util_BufferedByteStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("util"),
    __Pyx_DOCSTR(__pyx_mdoc), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1},
  {&__pyx_kp___cinit__, __pyx_k___cinit__, sizeof(__pyx_k___cinit__), 1, 1, 1},
  {&__pyx_kp___dealloc__, __pyx_k___dealloc__, sizeof(__pyx_k___dealloc__), 1, 1, 1},
  {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1},
  {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1},
  {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1},
  {&__pyx_kp_close, __pyx_k_close, sizeof(__pyx_k_close), 1, 1, 1},
  {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1},
  {&__pyx_kp_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 1, 1, 1},
  {&__pyx_kp_remaining, __pyx_k_remaining, sizeof(__pyx_k_remaining), 1, 1, 1},
  {&__pyx_kp___len__, __pyx_k___len__, sizeof(__pyx_k___len__), 1, 1, 1},
  {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1},
  {&__pyx_kp_at_eof, __pyx_k_at_eof, sizeof(__pyx_k_at_eof), 1, 1, 1},
  {&__pyx_kp_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 1, 1, 1},
  {&__pyx_kp_peek, __pyx_k_peek, sizeof(__pyx_k_peek), 1, 1, 1},
  {&__pyx_kp_truncate, __pyx_k_truncate, sizeof(__pyx_k_truncate), 1, 1, 1},
  {&__pyx_kp_consume, __pyx_k_consume, sizeof(__pyx_k_consume), 1, 1, 1},
  {&__pyx_kp_read_uchar, __pyx_k_read_uchar, sizeof(__pyx_k_read_uchar), 1, 1, 1},
  {&__pyx_kp_read_char, __pyx_k_read_char, sizeof(__pyx_k_read_char), 1, 1, 1},
  {&__pyx_kp_read_ushort, __pyx_k_read_ushort, sizeof(__pyx_k_read_ushort), 1, 1, 1},
  {&__pyx_kp_read_short, __pyx_k_read_short, sizeof(__pyx_k_read_short), 1, 1, 1},
  {&__pyx_kp_read_ulong, __pyx_k_read_ulong, sizeof(__pyx_k_read_ulong), 1, 1, 1},
  {&__pyx_kp_read_long, __pyx_k_read_long, sizeof(__pyx_k_read_long), 1, 1, 1},
  {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 1, 1, 1},
  {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 1, 1, 1},
  {&__pyx_kp_write_uchar, __pyx_k_write_uchar, sizeof(__pyx_k_write_uchar), 1, 1, 1},
  {&__pyx_kp_write_char, __pyx_k_write_char, sizeof(__pyx_k_write_char), 1, 1, 1},
  {&__pyx_kp_write_ushort, __pyx_k_write_ushort, sizeof(__pyx_k_write_ushort), 1, 1, 1},
  {&__pyx_kp_write_short, __pyx_k_write_short, sizeof(__pyx_k_write_short), 1, 1, 1},
  {&__pyx_kp_write_ulong, __pyx_k_write_ulong, sizeof(__pyx_k_write_ulong), 1, 1, 1},
  {&__pyx_kp_write_long, __pyx_k_write_long, sizeof(__pyx_k_write_long), 1, 1, 1},
  {&__pyx_kp_5, __pyx_k_5, sizeof(__pyx_k_5), 1, 1, 1},
  {&__pyx_kp_6, __pyx_k_6, sizeof(__pyx_k_6), 1, 1, 1},
  {&__pyx_kp_7, __pyx_k_7, sizeof(__pyx_k_7), 1, 1, 1},
  {&__pyx_kp_8, __pyx_k_8, sizeof(__pyx_k_8), 1, 1, 1},
  {&__pyx_kp_read_double, __pyx_k_read_double, sizeof(__pyx_k_read_double), 1, 1, 1},
  {&__pyx_kp_write_double, __pyx_k_write_double, sizeof(__pyx_k_write_double), 1, 1, 1},
  {&__pyx_kp_read_float, __pyx_k_read_float, sizeof(__pyx_k_read_float), 1, 1, 1},
  {&__pyx_kp_write_float, __pyx_k_write_float, sizeof(__pyx_k_write_float), 1, 1, 1},
  {&__pyx_kp_append, __pyx_k_append, sizeof(__pyx_k_append), 1, 1, 1},
  {&__pyx_kp___add__, __pyx_k___add__, sizeof(__pyx_k___add__), 1, 1, 1},
  {&__pyx_kp___str__, __pyx_k___str__, sizeof(__pyx_k___str__), 1, 1, 1},
  {&__pyx_kp_buf, __pyx_k_buf, sizeof(__pyx_k_buf), 1, 1, 1},
  {&__pyx_kp_value, __pyx_k_value, sizeof(__pyx_k_value), 1, 1, 1},
  {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1},
  {&__pyx_kp_x, __pyx_k_x, sizeof(__pyx_k_x), 1, 1, 1},
  {&__pyx_kp_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 1, 1, 1},
  {&__pyx_kp_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 1, 1, 1},
  {&__pyx_kp_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 1, 1, 1},
  {&__pyx_kp_val, __pyx_k_val, sizeof(__pyx_k_val), 1, 1, 1},
  {&__pyx_kp_data, __pyx_k_data, sizeof(__pyx_k_data), 1, 1, 1},
  {&__pyx_kp_self, __pyx_k_self, sizeof(__pyx_k_self), 1, 1, 1},
  {&__pyx_kp_other, __pyx_k_other, sizeof(__pyx_k_other), 1, 1, 1},
  {&__pyx_kp_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 1, 1, 1},
  {&__pyx_kp_pyamf, __pyx_k_pyamf, sizeof(__pyx_k_pyamf), 1, 1, 1},
  {&__pyx_kp_util, __pyx_k_util, sizeof(__pyx_k_util), 1, 1, 1},
  {&__pyx_kp_NaN, __pyx_k_NaN, sizeof(__pyx_k_NaN), 1, 1, 1},
  {&__pyx_kp_NegInf, __pyx_k_NegInf, sizeof(__pyx_k_NegInf), 1, 1, 1},
  {&__pyx_kp_PosInf, __pyx_k_PosInf, sizeof(__pyx_k_PosInf), 1, 1, 1},
  {&__pyx_kp_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 1, 1, 1},
  {&__pyx_kp_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 1, 1, 1},
  {&__pyx_kp_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 1, 1, 1},
  {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1},
  {&__pyx_kp_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 1, 0},
  {&__pyx_kp_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 1, 0},
  {&__pyx_kp_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 1, 0},
  {&__pyx_kp_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 1, 0},
  {&__pyx_kp_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 1, 0},
  {&__pyx_kp_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 0},
  {&__pyx_kp_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 0},
  {&__pyx_kp_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 0},
  {&__pyx_kp_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 0},
  {&__pyx_kp_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 0},
  {&__pyx_kp_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 0},
  {&__pyx_kp_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 0},
  {&__pyx_kp_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 0},
  {&__pyx_kp_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 0},
  {&__pyx_kp_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 0},
  {&__pyx_kp_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 0},
  {&__pyx_kp_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 0},
  {&__pyx_kp_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 0},
  {&__pyx_kp_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 0},
  {&__pyx_kp_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 0},
  {&__pyx_kp_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 0},
  {&__pyx_kp_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 0},
  {&__pyx_kp_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 0},
  {&__pyx_kp_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 0},
  {&__pyx_kp_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 0},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_kp_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_kp_IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_kp_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_kp_OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4294967295L = PyLong_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295L)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initutil(void); /*proto*/
PyMODINIT_FUNC initutil(void)
#else
PyMODINIT_FUNC PyInit_util(void); /*proto*/
PyMODINIT_FUNC PyInit_util(void)
#endif
{
  #ifdef CYTHON_REFNANNY
  void* __pyx_refchk = NULL;
  __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny");
  if (!__Pyx_Refnanny) {
      PyErr_Clear();
      __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny");
      if (!__Pyx_Refnanny)
          Py_FatalError("failed to import refnanny module");
  }
  __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_util(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Library function declarations ---*/
  __pyx_init_filenames();
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("util"), __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__pyx_module_is_main_cpyamf__util) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_skip_dispatch = 0;
  /*--- Global init code ---*/
  __pyx_v_6cpyamf_4util_pyamf_NaN = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cpyamf_4util_pyamf_NegInf = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cpyamf_4util_pyamf_PosInf = Py_None; Py_INCREF(Py_None);
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream = &__pyx_vtable_6cpyamf_4util_cBufferedByteStream;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.tell = (Py_ssize_t (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_tell;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.close = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_close;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char *, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.complain_if_closed = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_complain_if_closed;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream._increase_buffer = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream__increase_buffer;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.has_available = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream_has_available;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char **, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.at_eof = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_at_eof;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.remaining = (Py_ssize_t (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_remaining;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.seek = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t, struct __pyx_opt_args_6cpyamf_4util_19cBufferedByteStream_seek *__pyx_optional_args))__pyx_f_6cpyamf_4util_19cBufferedByteStream_seek;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.getvalue = (PyObject *(*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_getvalue;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.peek = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char **, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream_peek;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.truncate = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, Py_ssize_t))__pyx_f_6cpyamf_4util_19cBufferedByteStream_truncate;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.consume = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_consume;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.unpack_int = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_int;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.unpack_uint = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, unsigned long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_uint;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.pack_int = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_int;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.pack_uint = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, int, unsigned long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_uint;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_uchar = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned char *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_uchar;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_char = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_char;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_ushort = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned short *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ushort;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_short = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, short *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_short;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_ulong = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ulong;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_long = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_long;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_24bit_uint = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_uint;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_24bit_int = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_int;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_uchar = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned char))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_uchar;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_char = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, char))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_char;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_ushort = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned short))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ushort;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_short = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, short))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_short;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_ulong = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ulong;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_long = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_long;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_24bit_uint = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_uint;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_24bit_int = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, long))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_int;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_utf8_string = (PyObject *(*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, unsigned int))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_utf8_string;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_utf8_string = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, PyObject *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_utf8_string;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_double = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, double *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_double;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_double = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, double))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_double;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_float = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, float *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_float;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_float = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, float))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_float;
  __pyx_vtable_6cpyamf_4util_cBufferedByteStream.append = (int (*)(struct __pyx_obj_6cpyamf_4util_cBufferedByteStream *, PyObject *))__pyx_f_6cpyamf_4util_19cBufferedByteStream_append;
  #else
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.tell = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_tell;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.close = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_close;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.complain_if_closed = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_complain_if_closed;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream._increase_buffer = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream__increase_buffer;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.has_available = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_has_available;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.at_eof = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_at_eof;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.remaining = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_remaining;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.seek = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_seek;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.getvalue = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_getvalue;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.peek = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_peek;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.truncate = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_truncate;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.consume = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_consume;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.unpack_int = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.unpack_uint = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_unpack_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.pack_int = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.pack_uint = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_pack_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_uchar = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_uchar;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_char = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_char;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_ushort = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ushort;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_short = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_short;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_ulong = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_ulong;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_long = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_long;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_24bit_uint = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_24bit_int = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_24bit_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_uchar = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_uchar;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_char = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_char;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_ushort = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ushort;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_short = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_short;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_ulong = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_ulong;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_long = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_long;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_24bit_uint = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_24bit_int = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_24bit_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_utf8_string = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_utf8_string;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_utf8_string = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_utf8_string;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_double = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_double;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_double = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_double;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.read_float = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_read_float;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.write_float = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_write_float;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_cBufferedByteStream.append = (void(*)(void))__pyx_f_6cpyamf_4util_19cBufferedByteStream_append;
  #endif
  if (PyType_Ready(&__pyx_type_6cpyamf_4util_cBufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6cpyamf_4util_cBufferedByteStream.tp_dict, __pyx_vtabptr_6cpyamf_4util_cBufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "cBufferedByteStream", (PyObject *)&__pyx_type_6cpyamf_4util_cBufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6cpyamf_4util_cBufferedByteStream = &__pyx_type_6cpyamf_4util_cBufferedByteStream;
  __pyx_vtabptr_6cpyamf_4util_BufferedByteStream = &__pyx_vtable_6cpyamf_4util_BufferedByteStream;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.__pyx_base = *__pyx_vtabptr_6cpyamf_4util_cBufferedByteStream;
  __pyx_type_6cpyamf_4util_BufferedByteStream.tp_base = __pyx_ptype_6cpyamf_4util_cBufferedByteStream;
  if (PyType_Ready(&__pyx_type_6cpyamf_4util_BufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6cpyamf_4util_BufferedByteStream.tp_dict, __pyx_vtabptr_6cpyamf_4util_BufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "BufferedByteStream", (PyObject *)&__pyx_type_6cpyamf_4util_BufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6cpyamf_4util_BufferedByteStream = &__pyx_type_6cpyamf_4util_BufferedByteStream;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":78
 * cdef char SYSTEM_ENDIAN
 * 
 * cdef int float_broken = -1             # <<<<<<<<<<<<<<
 * cdef int complete_init = 0
 * 
 */
  __pyx_v_6cpyamf_4util_float_broken = -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":79
 * 
 * cdef int float_broken = -1
 * cdef int complete_init = 0             # <<<<<<<<<<<<<<
 * 
 * cdef unsigned char *NaN = <unsigned char *>'\xff\xf8\x00\x00\x00\x00\x00\x00'
 */
  __pyx_v_6cpyamf_4util_complete_init = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":81
 * cdef int complete_init = 0
 * 
 * cdef unsigned char *NaN = <unsigned char *>'\xff\xf8\x00\x00\x00\x00\x00\x00'             # <<<<<<<<<<<<<<
 * cdef unsigned char *NegInf = <unsigned char *>'\xff\xf0\x00\x00\x00\x00\x00\x00'
 * cdef unsigned char *PosInf = <unsigned char *>'\x7f\xf0\x00\x00\x00\x00\x00\x00'
 */
  __pyx_v_6cpyamf_4util_NaN = ((unsigned char *)__pyx_k_9);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":82
 * 
 * cdef unsigned char *NaN = <unsigned char *>'\xff\xf8\x00\x00\x00\x00\x00\x00'
 * cdef unsigned char *NegInf = <unsigned char *>'\xff\xf0\x00\x00\x00\x00\x00\x00'             # <<<<<<<<<<<<<<
 * cdef unsigned char *PosInf = <unsigned char *>'\x7f\xf0\x00\x00\x00\x00\x00\x00'
 * 
 */
  __pyx_v_6cpyamf_4util_NegInf = ((unsigned char *)__pyx_k_10);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":83
 * cdef unsigned char *NaN = <unsigned char *>'\xff\xf8\x00\x00\x00\x00\x00\x00'
 * cdef unsigned char *NegInf = <unsigned char *>'\xff\xf0\x00\x00\x00\x00\x00\x00'
 * cdef unsigned char *PosInf = <unsigned char *>'\x7f\xf0\x00\x00\x00\x00\x00\x00'             # <<<<<<<<<<<<<<
 * 
 * cdef double system_nan
 */
  __pyx_v_6cpyamf_4util_PosInf = ((unsigned char *)__pyx_k_11);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pxd":1
 * # Copyright (c) 2007-2009 The PyAMF Project.             # <<<<<<<<<<<<<<
 * # See LICENSE for details.
 * 
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpyamf.util");
  Py_DECREF(__pyx_m); __pyx_m = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "util.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #else
        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
        #endif
            goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

#if PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}

static int __Pyx_Print(PyObject *arg_tuple, int newline) {
    PyObject *f;
    PyObject* v;
    int i;

    if (!(f = __Pyx_GetStdout()))
        return -1;
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                return -1;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            return -1;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0 &&
                isspace(Py_CHARMASK(s[len-1])) &&
                s[len-1] != ' ')
                    PyFile_SoftSpace(f, 0);
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            return -1;
        PyFile_SoftSpace(f, 0);
    }
    return 0;
}

#else /* Python 3 has a print function */

static int __Pyx_Print(PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (!__pyx_print) {
        __pyx_print = __Pyx_GetAttrString(__pyx_b, "print");
        if (!__pyx_print)
            return -1;
    }
    if (!newline) {
        if (!__pyx_print_kwargs) {
            __pyx_print_kwargs = PyDict_New();
            if (!__pyx_print_kwargs)
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (!end_string)
                return -1;
            if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
}

#endif

#if PY_MAJOR_VERSION < 3

static int __Pyx_PrintOne(PyObject *o) {
    PyObject *f;
    if (!(f = __Pyx_GetStdout()))
        return -1;
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            return -1;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        return -1;
    if (PyFile_WriteString("\n", f) < 0)
        return -1;
    return 0;
    /* the line below is just to avoid compiler
     * compiler warnings about unused functions */
    return __Pyx_Print(NULL, 0);
}

#else /* Python 3 has a print function */

static int __Pyx_PrintOne(PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_New(1);
    if (unlikely(!arg_tuple))
        return -1;
    Py_INCREF(o);
    PyTuple_SET_ITEM(arg_tuple, 0, o);
    res = __Pyx_Print(arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}

#endif

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

#if PY_MAJOR_VERSION >= 3
    /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */
    if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) {
        tmp_type = tstate->exc_type;
        tmp_value = tstate->exc_value;
        tmp_tb = tstate->exc_traceback;
        PyErr_NormalizeException(&type, &value, &tb);
        PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb);
        tstate->exc_type = 0;
        tstate->exc_value = 0;
        tstate->exc_traceback = 0;
        PyException_SetContext(value, tmp_value);
        Py_DECREF(tmp_type);
        Py_XDECREF(tmp_tb);
    }
#endif

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(__import__,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

static INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
     while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
     return *s1 == *s2;
}

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned char)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned char");
                return (unsigned char)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned char");
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned short)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned short");
                return (unsigned short)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned short");
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned int)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned int");
                return (unsigned int)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned int");
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to char");
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to short");
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to int");
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed char");
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed short");
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed int");
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return PyLong_AsUnsignedLong(x);
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return PyLong_AsUnsignedLongLong(x);
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
    PyObject *pycobj = 0;
    int result;
    
    pycobj = PyCObject_FromVoidPtr(vtable, 0);
    if (!pycobj)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0)
        goto bad;
    result = 0;
    goto done;

bad:
    result = -1;
done:
    Py_XDECREF(pycobj);
    return result;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    #if PY_MAJOR_VERSION < 3
    empty_string = PyString_FromStringAndSize("", 0);
    #else
    empty_string = PyBytes_FromStringAndSize("", 0);
    #endif
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode && (!t->is_identifier)) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_identifier || (t->is_unicode && t->intern)) {
            *t->p = PyUnicode_InternFromString(t->s);
        } else if (t->is_unicode) {
            *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


