/* Generated by Cython 0.11 on Mon Apr 20 19:55:57 2009 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#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 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
#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 "stdio.h"
#include "cStringIO.h"


#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* x);
static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x);
static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(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* b);
static INLINE PyObject * __pyx_PyInt_FromSize_t(size_t);
static INLINE size_t __pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyInt_AsLong(x) (PyInt_CheckExact(x) ? PyInt_AS_LONG(x) : PyInt_AsLong(x))
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))

static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x);
static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x);
static INLINE char __pyx_PyInt_char(PyObject* x);
static INLINE short __pyx_PyInt_short(PyObject* x);
static INLINE int __pyx_PyInt_int(PyObject* x);
static INLINE long __pyx_PyInt_long(PyObject* x);
static INLINE signed char __pyx_PyInt_signed_char(PyObject* x);
static INLINE signed short __pyx_PyInt_signed_short(PyObject* x);
static INLINE signed int __pyx_PyInt_signed_int(PyObject* x);
static INLINE signed long __pyx_PyInt_signed_long(PyObject* x);
static INLINE long double __pyx_PyInt_long_double(PyObject* 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[] = "\nPython C-extensions for 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 PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*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 INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/

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.pyx":122
 *     return result != 0
 * 
 * cdef class BufferedByteStream:             # <<<<<<<<<<<<<<
 *     cdef char _endian
 *     cdef object buffer
 */

struct __pyx_obj_6cpyamf_4util_BufferedByteStream {
  PyObject_HEAD
  struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *__pyx_vtab;
  char _endian;
  PyObject *buffer;
  unsigned long length;
  unsigned char len_changed;
};


struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream {
  long (*c_length)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *);
  long (*unpack_int)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, char *, long);
  unsigned long (*unpack_uint)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, char *, long);
  void (*pack_int)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, long, long);
  void (*pack_uint)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, unsigned long, long);
  int (*c_at_eof)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *);
  long (*c_remaining)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *);
};
static struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *__pyx_vtabptr_6cpyamf_4util_BufferedByteStream;
/* Module declarations from cpyamf.util */

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 unsigned char *__pyx_v_6cpyamf_4util_NaN;
static unsigned char *__pyx_v_6cpyamf_4util_NegInf;
static unsigned char *__pyx_v_6cpyamf_4util_PosInf;
static INLINE 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 void __pyx_f_6cpyamf_4util_swap_bytes(unsigned char *, Py_ssize_t); /*proto*/
static int __pyx_f_6cpyamf_4util_is_broken_float(void); /*proto*/


/* 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_0;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_4294967295L;
static PyObject *__pyx_int_neg_2147483648;
static PyObject *__pyx_int_2147483647;
static char __pyx_k___cinit__[] = "__cinit__";
static PyObject *__pyx_kp___cinit__;
static char __pyx_k___init__[] = "__init__";
static PyObject *__pyx_kp___init__;
static char __pyx_k_tell[] = "tell";
static PyObject *__pyx_kp_tell;
static char __pyx_k_seek[] = "seek";
static PyObject *__pyx_kp_seek;
static char __pyx_k_at_eof[] = "at_eof";
static PyObject *__pyx_kp_at_eof;
static char __pyx_k_remaining[] = "remaining";
static PyObject *__pyx_kp_remaining;
static char __pyx_k_getvalue[] = "getvalue";
static PyObject *__pyx_kp_getvalue;
static char __pyx_k_read[] = "read";
static PyObject *__pyx_kp_read;
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[] = "write";
static PyObject *__pyx_kp_write;
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___len__[] = "__len__";
static PyObject *__pyx_kp___len__;
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___add__[] = "__add__";
static PyObject *__pyx_kp___add__;
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_readline[] = "readline";
static PyObject *__pyx_kp_readline;
static char __pyx_k_readlines[] = "readlines";
static PyObject *__pyx_kp_readlines;
static char __pyx_k_writelines[] = "writelines";
static PyObject *__pyx_kp_writelines;
static char __pyx_k_consume[] = "consume";
static PyObject *__pyx_kp_consume;
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_pos[] = "pos";
static PyObject *__pyx_kp_pos;
static char __pyx_k_mode[] = "mode";
static PyObject *__pyx_kp_mode;
static char __pyx_k_n[] = "n";
static PyObject *__pyx_kp_n;
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_l[] = "l";
static PyObject *__pyx_kp_l;
static char __pyx_k_s[] = "s";
static PyObject *__pyx_kp_s;
static char __pyx_k_c[] = "c";
static PyObject *__pyx_kp_c;
static char __pyx_k_size[] = "size";
static PyObject *__pyx_kp_size;
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_sizehint[] = "sizehint";
static PyObject *__pyx_kp_sizehint;
static char __pyx_k_iterable[] = "iterable";
static PyObject *__pyx_kp_iterable;
static char __pyx_k_fpconst[] = "fpconst";
static PyObject *__pyx_kp_fpconst;
static char __pyx_k_basestring[] = "basestring";
static PyObject *__pyx_kp_basestring;
static char __pyx_k_20[] = "getvalue";
static PyObject *__pyx_kp_20;
static char __pyx_k_21[] = "read";
static PyObject *__pyx_kp_21;
static char __pyx_k_22[] = "seek";
static PyObject *__pyx_kp_22;
static char __pyx_k_23[] = "tell";
static PyObject *__pyx_kp_23;
static char __pyx_k_TypeError[] = "TypeError";
static PyObject *__pyx_kp_TypeError;
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_IOError[] = "IOError";
static PyObject *__pyx_kp_IOError;
static char __pyx_k_EOFError[] = "EOFError";
static PyObject *__pyx_kp_EOFError;
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_isNaN[] = "isNaN";
static PyObject *__pyx_kp_isNaN;
static char __pyx_k_isNegInf[] = "isNegInf";
static PyObject *__pyx_kp_isNegInf;
static char __pyx_k_isPosInf[] = "isPosInf";
static PyObject *__pyx_kp_isPosInf;
static char __pyx_k_RuntimeError[] = "RuntimeError";
static PyObject *__pyx_kp_RuntimeError;
static PyObject *__pyx_builtin_basestring;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_EOFError;
static PyObject *__pyx_builtin_RuntimeError;
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 PyObject *__pyx_kp_24;
static char __pyx_k_24[] = "Unable to coerce buf->StringIO";
static PyObject *__pyx_kp_25;
static PyObject *__pyx_kp_26;
static PyObject *__pyx_kp_27;
static PyObject *__pyx_kp_28;
static PyObject *__pyx_kp_29;
static PyObject *__pyx_kp_30;
static char __pyx_k_25[] = "String value expected";
static char __pyx_k_26[] = "!";
static char __pyx_k_27[] = "@";
static char __pyx_k_28[] = "<";
static char __pyx_k_29[] = ">";
static char __pyx_k_30[] = "Not a valid endian type";
static PyObject *__pyx_kp_31;
static char __pyx_k_31[] = "integer out of range";
static PyObject *__pyx_kp_32;
static char __pyx_k_32[] = "integer out of range";
static PyObject *__pyx_kp_33;
static char __pyx_k_33[] = "buffer is closed";
static PyObject *__pyx_kp_34;
static char __pyx_k_34[] = "buffer is closed";
static PyObject *__pyx_kp_35;
static char __pyx_k_35[] = "buffer is closed";
static PyObject *__pyx_kp_36;
static char __pyx_k_36[] = "buffer is closed";
static PyObject *__pyx_kp_37;
static char __pyx_k_37[] = "buffer is closed";
static PyObject *__pyx_kp_38;
static char __pyx_k_38[] = "buffer is closed";
static PyObject *__pyx_kp_39;
static char __pyx_k_39[] = "buffer is closed";
static PyObject *__pyx_kp_40;
static char __pyx_k_40[] = "buffer is closed";
static PyObject *__pyx_kp_41;
static char __pyx_k_41[] = "buffer is closed";
static PyObject *__pyx_kp_42;
static char __pyx_k_42[] = "buffer is closed";
static PyObject *__pyx_kp_43;
static char __pyx_k_43[] = "buffer is closed";
static PyObject *__pyx_kp_44;
static char __pyx_k_44[] = "buffer is closed";
static PyObject *__pyx_kp_45;
static char __pyx_k_45[] = "buffer is closed";
static PyObject *__pyx_kp_46;
static char __pyx_k_46[] = "buffer is closed";
static PyObject *__pyx_kp_47;
static char __pyx_k_47[] = "buffer is closed";
static PyObject *__pyx_kp_48;
static char __pyx_k_48[] = "buffer is closed";
static PyObject *__pyx_kp_49;
static char __pyx_k_49[] = "buffer is closed";
static PyObject *__pyx_kp_50;
static PyObject *__pyx_kp_51;
static char __pyx_k_50[] = "buffer is closed";
static char __pyx_k_51[] = "uchar not in range";
static PyObject *__pyx_kp_52;
static PyObject *__pyx_kp_53;
static char __pyx_k_52[] = "buffer is closed";
static char __pyx_k_53[] = "char not in range";
static PyObject *__pyx_kp_54;
static PyObject *__pyx_kp_55;
static char __pyx_k_54[] = "buffer is closed";
static char __pyx_k_55[] = "ushort not in range";
static PyObject *__pyx_kp_56;
static PyObject *__pyx_kp_57;
static char __pyx_k_56[] = "buffer is closed";
static char __pyx_k_57[] = "short not in range";
static PyObject *__pyx_kp_58;
static char __pyx_k_58[] = "buffer is closed";
static PyObject *__pyx_kp_59;
static char __pyx_k_59[] = "buffer is closed";
static PyObject *__pyx_kp_60;
static PyObject *__pyx_kp_61;
static char __pyx_k_60[] = "buffer is closed";
static char __pyx_k_61[] = "n is out of range";
static PyObject *__pyx_kp_62;
static PyObject *__pyx_kp_63;
static char __pyx_k_62[] = "buffer is closed";
static char __pyx_k_63[] = "n is out of range";
static PyObject *__pyx_kp_64;
static char __pyx_k_64[] = "buffer is closed";
static char __pyx_k_65[] = "";
static PyObject *__pyx_kp_66;
static PyObject *__pyx_kp_69;
static char __pyx_k_66[] = "buffer is closed";
static char __pyx_k_67[] = "utf8";
static char __pyx_k_68[] = "strict";
static char __pyx_k_69[] = "value must be Unicode or str";
static PyObject *__pyx_kp_70;
static char __pyx_k_70[] = "buffer is closed";
static PyObject *__pyx_kp_71;
static char __pyx_k_71[] = "buffer is closed";
static PyObject *__pyx_kp_72;
static char __pyx_k_72[] = "buffer is closed";
static PyObject *__pyx_kp_73;
static char __pyx_k_73[] = "buffer is closed";
static PyObject *__pyx_kp_74;
static char __pyx_k_74[] = "Cannot peek backwards";
static PyObject *__pyx_kp_75;
static char __pyx_k_75[] = "buffer is closed";
static PyObject *__pyx_kp_76;
static char __pyx_k_76[] = "buffer is closed";
static PyObject *__pyx_kp_77;
static char __pyx_k_77[] = "buffer is closed";
static PyObject *__pyx_kp_78;
static char __pyx_k_78[] = "buffer is closed";
static PyObject *__pyx_kp_79;
static char __pyx_k_79[] = "buffer is closed";
static PyObject *__pyx_kp_80;
static char __pyx_k_80[] = "buffer is closed";
static PyObject *__pyx_kp_81;
static char __pyx_k_81[] = "buffer is closed";

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":68
 * cdef unsigned char *PosInf = <unsigned char *>'\x7f\xf0\x00\x00\x00\x00\x00\x00'
 * 
 * cdef inline char _get_native_endian():             # <<<<<<<<<<<<<<
 *     """
 *     A quick hack to determine the system's endian-ness ...
 */

static INLINE 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":74
 *     @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":75
 *     """
 *     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":77
 *     cdef int big_endian = (<char*>&one)[0] != 1
 * 
 *     if big_endian == 1:             # <<<<<<<<<<<<<<
 *         return ENDIAN_BIG
 *     else:
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_big_endian == 1);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":78
 * 
 *     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":80
 *         return ENDIAN_BIG
 *     else:
 *         return ENDIAN_LITTLE             # <<<<<<<<<<<<<<
 * 
 * cdef inline int is_big_endian(char endian):
 */
    __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":82
 *         return ENDIAN_LITTLE
 * 
 * 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":86
 *     Returns a boolean value whether the supplied C{endian} is big.
 *     """
 *     if endian == ENDIAN_NATIVE:             # <<<<<<<<<<<<<<
 *         return SYSTEM_ENDIAN == ENDIAN_BIG
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_endian == '@');
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":87
 *     """
 *     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":89
 *         return SYSTEM_ENDIAN == ENDIAN_BIG
 * 
 *     return endian == ENDIAN_NETWORK or endian == ENDIAN_BIG             # <<<<<<<<<<<<<<
 * 
 * cdef inline int is_native_endian(char endian):
 */
  if (!(__pyx_v_endian == '!')) {
    /* __pyx_t_1 allocated */
    __pyx_t_1 = (__pyx_v_endian == '>');
  } else {
    __pyx_t_1 = (__pyx_v_endian == '!');
  }
  __pyx_r = __pyx_t_1;
  /* __pyx_t_1 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":91
 *     return endian == ENDIAN_NETWORK or endian == ENDIAN_BIG
 * 
 * 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":92
 * 
 * cdef inline int is_native_endian(char endian):
 *     if endian == ENDIAN_NATIVE:             # <<<<<<<<<<<<<<
 *         return 1
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_endian == '@');
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

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

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":95
 *         return 1
 * 
 *     return endian == SYSTEM_ENDIAN             # <<<<<<<<<<<<<<
 * 
 * cdef inline void swap_bytes(unsigned char *buffer, Py_ssize_t size):
 */
  __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":97
 *     return endian == SYSTEM_ENDIAN
 * 
 * cdef inline void swap_bytes(unsigned char *buffer, Py_ssize_t size):             # <<<<<<<<<<<<<<
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(size)
 *     cdef Py_ssize_t i
 */

static INLINE void __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;
  __Pyx_SetupRefcountContext("swap_bytes");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":98
 * 
 * cdef inline void swap_bytes(unsigned char *buffer, Py_ssize_t size):
 *     cdef unsigned char *buf = <unsigned char *>PyMem_Malloc(size)             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i
 * 
 */
  __pyx_v_buf = ((unsigned char *)PyMem_Malloc(__pyx_v_size));

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

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":102
 * 
 *     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":104
 *         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":106
 *     memcpy(buffer, buf, size)
 * 
 *     PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 * cdef int is_broken_float():
 */
  PyMem_Free(__pyx_v_buf);

  __Pyx_FinishRefcountContext();
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":108
 *     PyMem_Free(buf)
 * 
 * cdef int is_broken_float():             # <<<<<<<<<<<<<<
 *     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":109
 * 
 * cdef int is_broken_float():
 *     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":112
 * 
 *     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":114
 *     cdef unsigned char *buf = <unsigned char *>&test
 * 
 *     if is_big_endian(SYSTEM_ENDIAN):             # <<<<<<<<<<<<<<
 *         result = memcmp(NaN, &test, 8) != 0
 *     else:
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_6cpyamf_4util_SYSTEM_ENDIAN);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":115
 * 
 *     if is_big_endian(SYSTEM_ENDIAN):
 *         result = memcmp(NaN, &test, 8) != 0             # <<<<<<<<<<<<<<
 *     else:
 *         swap_bytes(buf, 8)
 */
    __pyx_v_result = (memcmp(__pyx_v_6cpyamf_4util_NaN, (&__pyx_v_test), 8) != 0);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":117
 *         result = memcmp(NaN, &test, 8) != 0
 *     else:
 *         swap_bytes(buf, 8)             # <<<<<<<<<<<<<<
 *         result = memcmp(NaN, buf, 8)
 * 
 */
    __pyx_f_6cpyamf_4util_swap_bytes(__pyx_v_buf, 8);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":118
 *     else:
 *         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);
  }
  __pyx_L3:;

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

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":128
 *     cdef unsigned char len_changed
 * 
 *     def __new__(self):             # <<<<<<<<<<<<<<
 *         self._endian = ENDIAN_NETWORK
 *         self.length = 0
 */

static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_SetupRefcountContext("__cinit__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__new__", 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, "__new__", 0))) return -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":129
 * 
 *     def __new__(self):
 *         self._endian = ENDIAN_NETWORK             # <<<<<<<<<<<<<<
 *         self.length = 0
 *         self.len_changed = 0
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian = '!';

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":130
 *     def __new__(self):
 *         self._endian = ENDIAN_NETWORK
 *         self.length = 0             # <<<<<<<<<<<<<<
 *         self.len_changed = 0
 * 
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->length = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":131
 *         self._endian = ENDIAN_NETWORK
 *         self.length = 0
 *         self.len_changed = 0             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, buf=None):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":133
 *         self.len_changed = 0
 * 
 *     def __init__(self, buf=None):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             self.buffer = StringIO_NewOutput(128)
 */

static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6cpyamf_4util_18BufferedByteStream___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_buf = 0;
  char *__pyx_v_s;
  long __pyx_v_t;
  long __pyx_v_l;
  struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_other = 0;
  PyObject *__pyx_v_old_pos;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  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 = 133; __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 = 133; __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_old_pos = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":134
 * 
 *     def __init__(self, buf=None):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             self.buffer = StringIO_NewOutput(128)
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":135
 *     def __init__(self, buf=None):
 *         if not self.buffer:
 *             self.buffer = StringIO_NewOutput(128)             # <<<<<<<<<<<<<<
 * 
 *         if buf is None:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PycStringIO->NewOutput(128); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
    __Pyx_DECREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
    ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer = __pyx_t_3;
    __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":137
 *             self.buffer = StringIO_NewOutput(128)
 * 
 *         if buf is None:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_buf == Py_None);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":138
 * 
 *         if buf is None:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef char *s = NULL
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":140
 *             return
 * 
 *         cdef char *s = NULL             # <<<<<<<<<<<<<<
 *         cdef long t = 0
 *         cdef long l = 0
 */
  __pyx_v_s = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":141
 * 
 *         cdef char *s = NULL
 *         cdef long t = 0             # <<<<<<<<<<<<<<
 *         cdef long l = 0
 *         cdef BufferedByteStream other = <BufferedByteStream>buf
 */
  __pyx_v_t = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":142
 *         cdef char *s = NULL
 *         cdef long t = 0
 *         cdef long l = 0             # <<<<<<<<<<<<<<
 *         cdef BufferedByteStream other = <BufferedByteStream>buf
 * 
 */
  __pyx_v_l = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":143
 *         cdef long t = 0
 *         cdef long l = 0
 *         cdef BufferedByteStream other = <BufferedByteStream>buf             # <<<<<<<<<<<<<<
 * 
 *         if isinstance(buf, BufferedByteStream):
 */
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_buf)));
  __pyx_v_other = ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":145
 *         cdef BufferedByteStream other = <BufferedByteStream>buf
 * 
 *         if isinstance(buf, BufferedByteStream):             # <<<<<<<<<<<<<<
 *             t = <long>other.tell()
 *             other.seek(0)
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_TypeCheck(__pyx_v_buf, ((PyTypeObject *)((PyObject*)__pyx_ptype_6cpyamf_4util_BufferedByteStream))); 
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":146
 * 
 *         if isinstance(buf, BufferedByteStream):
 *             t = <long>other.tell()             # <<<<<<<<<<<<<<
 *             other.seek(0)
 *             l = StringIO_cread(other.buffer, &s, -1)
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_kp_tell); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __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 = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    /* __pyx_t_5 allocated */
    __pyx_t_5 = __pyx_PyInt_long(__pyx_t_4); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __pyx_v_t = ((long)__pyx_t_5);
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":147
 *         if isinstance(buf, BufferedByteStream):
 *             t = <long>other.tell()
 *             other.seek(0)             # <<<<<<<<<<<<<<
 *             l = StringIO_cread(other.buffer, &s, -1)
 *             StringIO_cwrite(self.buffer, s, l)
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __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_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":148
 *             t = <long>other.tell()
 *             other.seek(0)
 *             l = StringIO_cread(other.buffer, &s, -1)             # <<<<<<<<<<<<<<
 *             StringIO_cwrite(self.buffer, s, l)
 *             self.length = l
 */
    __pyx_v_l = PycStringIO->cread(__pyx_v_other->buffer, (&__pyx_v_s), -1);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":149
 *             other.seek(0)
 *             l = StringIO_cread(other.buffer, &s, -1)
 *             StringIO_cwrite(self.buffer, s, l)             # <<<<<<<<<<<<<<
 *             self.length = l
 *             other.seek(t)
 */
    PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_v_s, __pyx_v_l);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":150
 *             l = StringIO_cread(other.buffer, &s, -1)
 *             StringIO_cwrite(self.buffer, s, l)
 *             self.length = l             # <<<<<<<<<<<<<<
 *             other.seek(t)
 *         elif isinstance(buf, basestring):
 */
    ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->length = __pyx_v_l;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":151
 *             StringIO_cwrite(self.buffer, s, l)
 *             self.length = l
 *             other.seek(t)             # <<<<<<<<<<<<<<
 *         elif isinstance(buf, basestring):
 *             self.write(buf)
 */
    /* __pyx_t_6 allocated */
    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_kp_seek); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __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 released */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_6 released */
    /* __pyx_t_4 released */
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    goto __pyx_L8;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":152
 *             self.length = l
 *             other.seek(t)
 *         elif isinstance(buf, basestring):             # <<<<<<<<<<<<<<
 *             self.write(buf)
 *         elif hasattr(buf, 'getvalue'):
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_buf, __pyx_builtin_basestring); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":153
 *             other.seek(t)
 *         elif isinstance(buf, basestring):
 *             self.write(buf)             # <<<<<<<<<<<<<<
 *         elif hasattr(buf, 'getvalue'):
 *             self.write(buf.getvalue())
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __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_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_3 released */
    /* __pyx_t_4 released */
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */
    goto __pyx_L8;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":154
 *         elif isinstance(buf, basestring):
 *             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_2 allocated */
  __pyx_t_2 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_20); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":155
 *             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_6 allocated */
    __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_3 allocated */
    __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 = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __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 released */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_6 released */
    /* __pyx_t_4 released */
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    goto __pyx_L8;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":156
 *         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_2 allocated */
  __pyx_t_2 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_21); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    /* __pyx_t_1 allocated */
    __pyx_t_1 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_22); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_1) {
      /* __pyx_t_7 allocated */
      __pyx_t_7 = PyObject_HasAttr(__pyx_v_buf, __pyx_kp_23); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      /* __pyx_t_8 allocated */
      __pyx_t_8 = __pyx_t_7;
      /* __pyx_t_7 released */
    } else {
      __pyx_t_8 = __pyx_t_1;
      /* __pyx_t_1 released */
    }
    /* __pyx_t_1 allocated */
    __pyx_t_1 = __pyx_t_8;
    /* __pyx_t_8 released */
  } else {
    __pyx_t_1 = __pyx_t_2;
    /* __pyx_t_2 released */
  }
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":157
 *             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 allocated */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_tell); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __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 = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_v_old_pos);
    __pyx_v_old_pos = __pyx_t_4;
    __pyx_t_4 = 0;
    /* __pyx_t_4 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":158
 *         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 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __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_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":159
 *             old_pos = buf.tell()
 *             buf.seek(0)
 *             self.write(buf.read())             # <<<<<<<<<<<<<<
 *             buf.seek(old_pos)
 *         else:
 */
    /* __pyx_t_6 allocated */
    __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_read); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __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 = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __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 released */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_6 released */
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":160
 *             buf.seek(0)
 *             self.write(buf.read())
 *             buf.seek(old_pos)             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError("Unable to coerce buf->StringIO")
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __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_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */
    goto __pyx_L8;
  }
  /*else*/ {

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

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

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":167
 * 
 *     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":168
 *     property endian:
 *         def __set__(self, value):
 *             if PyString_Check(value) == 0:             # <<<<<<<<<<<<<<
 *                 raise TypeError('String value expected')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (PyString_Check(__pyx_v_value) == 0);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":169
 *         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 allocated */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __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 allocated */
    __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 = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    /* __pyx_t_2 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":171
 *                 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 allocated */
  __pyx_t_3 = __pyx_v_value;
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_26, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */
  if (((int)__pyx_t_1)) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_27, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /* __pyx_t_2 released */
    /* __pyx_t_5 allocated */
    __pyx_t_5 = ((int)__pyx_t_4);
    /* __pyx_t_4 released */
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
    /* __pyx_t_1 released */
  }
  if (__pyx_t_5) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_28, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    /* __pyx_t_1 allocated */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /* __pyx_t_2 released */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = ((int)__pyx_t_1);
    /* __pyx_t_1 released */
  } else {
    __pyx_t_4 = __pyx_t_5;
    /* __pyx_t_5 released */
  }
  if (__pyx_t_4) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_kp_29, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    /* __pyx_t_5 allocated */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /* __pyx_t_2 released */
    /* __pyx_t_1 allocated */
    __pyx_t_1 = ((int)__pyx_t_5);
    /* __pyx_t_5 released */
  } else {
    __pyx_t_1 = __pyx_t_4;
    /* __pyx_t_4 released */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __pyx_t_1;
  /* __pyx_t_1 released */
  if (__pyx_t_4) {
    /* __pyx_t_4 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":172
 * 
 *             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 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_30);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_30);
    __Pyx_GIVEREF(__pyx_kp_30);
    /* __pyx_t_2 allocated */
    __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 = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /* __pyx_t_2 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":174
 *                 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)->_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":176
 *             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":177
 * 
 *         def __get__(self):
 *             return PyString_FromStringAndSize(&self._endian, 1)             # <<<<<<<<<<<<<<
 * 
 *     cdef long c_length(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyString_FromStringAndSize((&((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  /* __pyx_t_1 released */
  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":179
 *             return PyString_FromStringAndSize(&self._endian, 1)
 * 
 *     cdef long c_length(self):             # <<<<<<<<<<<<<<
 *         if self.len_changed == 0:
 *             return self.length
 */

static  long __pyx_f_6cpyamf_4util_18BufferedByteStream_c_length(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self) {
  long __pyx_v_cur_pos;
  long __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_SetupRefcountContext("c_length");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":180
 * 
 *     cdef long c_length(self):
 *         if self.len_changed == 0:             # <<<<<<<<<<<<<<
 *             return self.length
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_self->len_changed == 0);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":181
 *     cdef long c_length(self):
 *         if self.len_changed == 0:
 *             return self.length             # <<<<<<<<<<<<<<
 * 
 *         cdef long cur_pos = <long>self.buffer.tell()
 */
    __pyx_r = __pyx_v_self->length;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":183
 *             return self.length
 * 
 *         cdef long cur_pos = <long>self.buffer.tell()             # <<<<<<<<<<<<<<
 * 
 *         self.buffer.seek(0, 2)
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self->buffer, __pyx_kp_tell); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_3 allocated */
  __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 = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __pyx_PyInt_long(__pyx_t_3); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  __pyx_v_cur_pos = ((long)__pyx_t_4);
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":185
 *         cdef long cur_pos = <long>self.buffer.tell()
 * 
 *         self.buffer.seek(0, 2)             # <<<<<<<<<<<<<<
 * 
 *         self.length = <long>self.buffer.tell()
 */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self->buffer, __pyx_kp_seek); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __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_INCREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_2 released */
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":187
 *         self.buffer.seek(0, 2)
 * 
 *         self.length = <long>self.buffer.tell()             # <<<<<<<<<<<<<<
 *         self.len_changed = 0
 * 
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_GetAttr(__pyx_v_self->buffer, __pyx_kp_tell); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __pyx_PyInt_long(__pyx_t_2); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */
  __pyx_v_self->length = ((long)__pyx_t_4);
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":188
 * 
 *         self.length = <long>self.buffer.tell()
 *         self.len_changed = 0             # <<<<<<<<<<<<<<
 * 
 *         self.buffer.seek(cur_pos, 0)
 */
  __pyx_v_self->len_changed = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":190
 *         self.len_changed = 0
 * 
 *         self.buffer.seek(cur_pos, 0)             # <<<<<<<<<<<<<<
 * 
 *         return self.length
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self->buffer, __pyx_kp_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_cur_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  /* __pyx_t_2 released */
  /* __pyx_t_3 released */
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":192
 *         self.buffer.seek(cur_pos, 0)
 * 
 *         return self.length             # <<<<<<<<<<<<<<
 * 
 *     cdef long unpack_int(self, char *buf, long num_bytes):
 */
  __pyx_r = __pyx_v_self->length;
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":194
 *         return self.length
 * 
 *     cdef long unpack_int(self, char *buf, long num_bytes):             # <<<<<<<<<<<<<<
 *         """
 *         Unpacks a long from C{buf}.
 */

static  long __pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_int(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self, char *__pyx_v_buf, long __pyx_v_num_bytes) {
  long __pyx_v_x;
  long __pyx_v_bytes_left;
  unsigned char *__pyx_v_bytes;
  long __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("unpack_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":198
 *         Unpacks a long from C{buf}.
 *         """
 *         cdef long x = 0             # <<<<<<<<<<<<<<
 *         cdef long bytes_left = num_bytes
 *         cdef unsigned char *bytes = <unsigned char *>buf
 */
  __pyx_v_x = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":199
 *         """
 *         cdef long x = 0
 *         cdef long bytes_left = num_bytes             # <<<<<<<<<<<<<<
 *         cdef unsigned char *bytes = <unsigned char *>buf
 * 
 */
  __pyx_v_bytes_left = __pyx_v_num_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":200
 *         cdef long x = 0
 *         cdef long bytes_left = num_bytes
 *         cdef unsigned char *bytes = <unsigned char *>buf             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_bytes = ((unsigned char *)__pyx_v_buf);

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

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":204
 *         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":205
 *             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":206
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 *                 bytes_left -= 1             # <<<<<<<<<<<<<<
 *         else:
 *             while bytes_left > 0:
 */
      __pyx_v_bytes_left -= 1;
    }
    goto __pyx_L3;
  }
  /*else*/ {

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":209
 *         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":210
 *             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_L3:;

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

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":213
 * 
 *         if SIZEOF_LONG > num_bytes:
 *             x |= -(x & (1L << ((8 * num_bytes) - 1)))             # <<<<<<<<<<<<<<
 * 
 *         return x
 */
    __pyx_v_x |= (-(__pyx_v_x & (1L << ((8 * __pyx_v_num_bytes) - 1))));
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":215
 *             x |= -(x & (1L << ((8 * num_bytes) - 1)))
 * 
 *         return x             # <<<<<<<<<<<<<<
 * 
 *     cdef unsigned long unpack_uint(self, char *buf, long num_bytes):
 */
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":217
 *         return x
 * 
 *     cdef unsigned long unpack_uint(self, char *buf, long num_bytes):             # <<<<<<<<<<<<<<
 *         """
 *         Unpacks an unsigned long from C{buf}.
 */

static  unsigned long __pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_uint(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self, char *__pyx_v_buf, long __pyx_v_num_bytes) {
  unsigned long __pyx_v_x;
  unsigned char *__pyx_v_bytes;
  unsigned long __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("unpack_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":221
 *         Unpacks an unsigned long from C{buf}.
 *         """
 *         cdef unsigned long x = 0             # <<<<<<<<<<<<<<
 *         cdef unsigned char *bytes = <unsigned char *>buf
 * 
 */
  __pyx_v_x = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":222
 *         """
 *         cdef unsigned long x = 0
 *         cdef unsigned char *bytes = <unsigned char *>buf             # <<<<<<<<<<<<<<
 * 
 *         if is_big_endian(self._endian):
 */
  __pyx_v_bytes = ((unsigned char *)__pyx_v_buf);

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

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":226
 *         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":227
 *             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":228
 *                 x = (x << 8) | bytes[0]
 *                 bytes += 1
 *                 num_bytes -= 1             # <<<<<<<<<<<<<<
 *         else:
 *             while num_bytes > 0:
 */
      __pyx_v_num_bytes -= 1;
    }
    goto __pyx_L3;
  }
  /*else*/ {

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":231
 *         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":232
 *             while num_bytes > 0:
 *                 x = (x << 8) | bytes[num_bytes - 1]
 *                 num_bytes -= 1             # <<<<<<<<<<<<<<
 * 
 *         return x
 */
      __pyx_v_num_bytes -= 1;
    }
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":234
 *                 num_bytes -= 1
 * 
 *         return x             # <<<<<<<<<<<<<<
 * 
 *     cdef void pack_int(self, long x, long num_bytes):
 */
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":236
 *         return x
 * 
 *     cdef void pack_int(self, long x, long num_bytes):             # <<<<<<<<<<<<<<
 *         cdef long maxint = 1
 *         cdef long minint = -1
 */

static  void __pyx_f_6cpyamf_4util_18BufferedByteStream_pack_int(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self, long __pyx_v_x, long __pyx_v_num_bytes) {
  long __pyx_v_maxint;
  long __pyx_v_minint;
  char *__pyx_v_buf;
  long __pyx_v_i;
  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":237
 * 
 *     cdef void pack_int(self, long x, long num_bytes):
 *         cdef long maxint = 1             # <<<<<<<<<<<<<<
 *         cdef long minint = -1
 * 
 */
  __pyx_v_maxint = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":238
 *     cdef void pack_int(self, long x, long num_bytes):
 *         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":240
 *         cdef long minint = -1
 * 
 *         if num_bytes != SIZEOF_LONG:             # <<<<<<<<<<<<<<
 *             maxint <<= <long>(num_bytes * 8)
 *             minint = (-maxint)
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_num_bytes != SIZEOF_LONG);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

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

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

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":245
 * 
 *             if x >= maxint or x < minint:
 *                 raise OverflowError('integer out of range')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 */
      /* __pyx_t_2 allocated */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(__pyx_kp_31);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_31);
      __Pyx_GIVEREF(__pyx_kp_31);
      /* __pyx_t_3 allocated */
      __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 = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      /* __pyx_t_2 released */
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      /* __pyx_t_3 released */
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __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":247
 *                 raise OverflowError('integer out of range')
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)             # <<<<<<<<<<<<<<
 *         cdef long i = num_bytes
 * 
 */
  __pyx_v_buf = ((char *)PyMem_Malloc(__pyx_v_num_bytes));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":248
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 *         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":250
 *         cdef long i = num_bytes
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while i > 0:
 *                 i -= 1
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_4) {
    /* __pyx_t_4 released */

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":252
 *         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":253
 *             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":254
 *                 i -= 1
 *                 buf[i] = <char>x
 *                 x >>= 8             # <<<<<<<<<<<<<<
 *         else:
 *             while i > 0:
 */
      __pyx_v_x >>= 8;
    }
    goto __pyx_L5;
  }
  /*else*/ {

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":257
 *         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":258
 *             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":259
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 *                 x >>= 8             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, buf, num_bytes)
 */
      __pyx_v_x >>= 8;
    }
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":261
 *                 x >>= 8
 * 
 *         StringIO_cwrite(self.buffer, buf, num_bytes)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 * 
 */
  PycStringIO->cwrite(__pyx_v_self->buffer, __pyx_v_buf, __pyx_v_num_bytes);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":262
 * 
 *         StringIO_cwrite(self.buffer, buf, num_bytes)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *     cdef void pack_uint(self, unsigned long x, long num_bytes):
 */
  PyMem_Free(__pyx_v_buf);

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("cpyamf.util.BufferedByteStream.pack_int");
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":264
 *         PyMem_Free(buf)
 * 
 *     cdef void pack_uint(self, unsigned long x, long num_bytes):             # <<<<<<<<<<<<<<
 *         """
 *         Packs an unsigned long into a buffer.
 */

static  void __pyx_f_6cpyamf_4util_18BufferedByteStream_pack_uint(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self, unsigned long __pyx_v_x, long __pyx_v_num_bytes) {
  unsigned long __pyx_v_maxint;
  char *__pyx_v_buf;
  long __pyx_v_i;
  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":268
 *         Packs an unsigned long into a buffer.
 *         """
 *         cdef unsigned long maxint = 1             # <<<<<<<<<<<<<<
 * 
 *         if num_bytes != SIZEOF_LONG:
 */
  __pyx_v_maxint = 1;

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

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":271
 * 
 *         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":273
 *             maxint <<= <unsigned long>(num_bytes * 8)
 * 
 *             if x >= maxint:             # <<<<<<<<<<<<<<
 *                 raise OverflowError('integer out of range')
 * 
 */
    /* __pyx_t_1 allocated */
    __pyx_t_1 = (__pyx_v_x >= __pyx_v_maxint);
    if (__pyx_t_1) {
      /* __pyx_t_1 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":274
 * 
 *             if x >= maxint:
 *                 raise OverflowError('integer out of range')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 */
      /* __pyx_t_2 allocated */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(__pyx_kp_32);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_32);
      __Pyx_GIVEREF(__pyx_kp_32);
      /* __pyx_t_3 allocated */
      __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 = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      /* __pyx_t_2 released */
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      /* __pyx_t_3 released */
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __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":276
 *                 raise OverflowError('integer out of range')
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)             # <<<<<<<<<<<<<<
 *         cdef long i = num_bytes
 * 
 */
  __pyx_v_buf = ((char *)PyMem_Malloc(__pyx_v_num_bytes));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":277
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(num_bytes)
 *         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":279
 *         cdef long i = num_bytes
 * 
 *         if is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             while i > 0:
 *                 i -= 1
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __pyx_f_6cpyamf_4util_is_big_endian(__pyx_v_self->_endian);
  if (__pyx_t_4) {
    /* __pyx_t_4 released */

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":281
 *         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":282
 *             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":283
 *                 i -= 1
 *                 buf[i] = <char>x
 *                 x >>= 8             # <<<<<<<<<<<<<<
 *         else:
 *             while i > 0:
 */
      __pyx_v_x >>= 8;
    }
    goto __pyx_L5;
  }
  /*else*/ {

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

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":286
 *         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":287
 *             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":288
 *                 buf[num_bytes - i] = <char>x
 *                 i -= 1
 *                 x >>= 8             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, buf, num_bytes)
 */
      __pyx_v_x >>= 8;
    }
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":290
 *                 x >>= 8
 * 
 *         StringIO_cwrite(self.buffer, buf, num_bytes)             # <<<<<<<<<<<<<<
 * 
 *         PyMem_Free(buf)
 */
  PycStringIO->cwrite(__pyx_v_self->buffer, __pyx_v_buf, __pyx_v_num_bytes);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":292
 *         StringIO_cwrite(self.buffer, buf, num_bytes)
 * 
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *     def tell(self):
 */
  PyMem_Free(__pyx_v_buf);

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("cpyamf.util.BufferedByteStream.pack_uint");
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":294
 *         PyMem_Free(buf)
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("tell");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":295
 * 
 *     def tell(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":296
 *     def tell(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return self.buffer.tell()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_33);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_33);
    __Pyx_GIVEREF(__pyx_kp_33);
    /* __pyx_t_4 allocated */
    __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 = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":298
 *             raise ValueError('buffer is closed')
 * 
 *         return self.buffer.tell()             # <<<<<<<<<<<<<<
 * 
 *     def seek(self, int pos, int mode=0):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_tell); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":300
 *         return self.buffer.tell()
 * 
 *     def seek(self, int pos, int mode=0):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_pos;
  int __pyx_v_mode;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  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};
    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 = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pos = __pyx_PyInt_int(values[0]); if (unlikely((__pyx_v_pos == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[1]) {
      __pyx_v_mode = __pyx_PyInt_int(values[1]); if (unlikely((__pyx_v_mode == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_mode = 0;
    }
  } else {
    __pyx_v_mode = 0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_mode = __pyx_PyInt_int(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_mode == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  1: __pyx_v_pos = __pyx_PyInt_int(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_pos == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      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 = 300; __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":301
 * 
 *     def seek(self, int pos, int mode=0):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":302
 *     def seek(self, int pos, int mode=0):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return self.buffer.seek(pos, mode)
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_34);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_34);
    __Pyx_GIVEREF(__pyx_kp_34);
    /* __pyx_t_4 allocated */
    __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 = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":304
 *             raise ValueError('buffer is closed')
 * 
 *         return self.buffer.seek(pos, mode)             # <<<<<<<<<<<<<<
 * 
 *     cdef int c_at_eof(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  /* __pyx_t_6 allocated */
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_5 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_6 released */
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __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":306
 *         return self.buffer.seek(pos, mode)
 * 
 *     cdef int c_at_eof(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static  int __pyx_f_6cpyamf_4util_18BufferedByteStream_c_at_eof(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  __Pyx_SetupRefcountContext("c_at_eof");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":307
 * 
 *     cdef int c_at_eof(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":308
 *     cdef int c_at_eof(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return <long>self.remaining() == 0
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_35);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_35);
    __Pyx_GIVEREF(__pyx_kp_35);
    /* __pyx_t_4 allocated */
    __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 = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":310
 *             raise ValueError('buffer is closed')
 * 
 *         return <long>self.remaining() == 0             # <<<<<<<<<<<<<<
 * 
 *     def at_eof(self):
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_remaining); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_PyInt_long(__pyx_t_3); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  __pyx_r = (((long)__pyx_t_5) == 0);
  /* __pyx_t_5 released */
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("cpyamf.util.BufferedByteStream.c_at_eof");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":312
 *         return <long>self.remaining() == 0
 * 
 *     def at_eof(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof(PyObject *__pyx_v_self, PyObject *unused) {
  long __pyx_v_remaining;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("at_eof");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":313
 * 
 *     def at_eof(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":314
 *     def at_eof(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef long remaining = self.c_remaining()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_36);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_36);
    __Pyx_GIVEREF(__pyx_kp_36);
    /* __pyx_t_4 allocated */
    __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 = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":316
 *             raise ValueError('buffer is closed')
 * 
 *         cdef long remaining = self.c_remaining()             # <<<<<<<<<<<<<<
 * 
 *         if remaining == 0:
 */
  __pyx_v_remaining = ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->c_remaining(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":318
 *         cdef long remaining = self.c_remaining()
 * 
 *         if remaining == 0:             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_remaining == 0);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":319
 * 
 *         if remaining == 0:
 *             return True             # <<<<<<<<<<<<<<
 * 
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":321
 *             return True
 * 
 *         return False             # <<<<<<<<<<<<<<
 * 
 *     cdef long c_remaining(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":323
 *         return False
 * 
 *     cdef long c_remaining(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static  long __pyx_f_6cpyamf_4util_18BufferedByteStream_c_remaining(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *__pyx_v_self) {
  long __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  __Pyx_SetupRefcountContext("c_remaining");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":324
 * 
 *     cdef long c_remaining(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":325
 *     cdef long c_remaining(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if self.len_changed == 1:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_37);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_37);
    __Pyx_GIVEREF(__pyx_kp_37);
    /* __pyx_t_4 allocated */
    __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 = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":327
 *             raise ValueError('buffer is closed')
 * 
 *         if self.len_changed == 1:             # <<<<<<<<<<<<<<
 *             self.c_length()
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_self->len_changed == 1);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":328
 * 
 *         if self.len_changed == 1:
 *             self.c_length()             # <<<<<<<<<<<<<<
 * 
 *         return self.length - <long>self.tell()
 */
    ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)__pyx_v_self->__pyx_vtab)->c_length(__pyx_v_self);
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":330
 *             self.c_length()
 * 
 *         return self.length - <long>self.tell()             # <<<<<<<<<<<<<<
 * 
 *     def remaining(self):
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_tell); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_PyInt_long(__pyx_t_3); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  __pyx_r = (__pyx_v_self->length - ((long)__pyx_t_5));
  /* __pyx_t_5 released */
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("cpyamf.util.BufferedByteStream.c_remaining");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":332
 *         return self.length - <long>self.tell()
 * 
 *     def remaining(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining(PyObject *__pyx_v_self, PyObject *unused) {
  long __pyx_v_cur_pos;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("remaining");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":333
 * 
 *     def remaining(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":334
 *     def remaining(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef long cur_pos = PyInt_AsLong(self.tell())
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_38);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_38);
    __Pyx_GIVEREF(__pyx_kp_38);
    /* __pyx_t_4 allocated */
    __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 = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":336
 *             raise ValueError('buffer is closed')
 * 
 *         cdef long cur_pos = PyInt_AsLong(self.tell())             # <<<<<<<<<<<<<<
 * 
 *         if self.len_changed == 1:
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_tell); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __pyx_v_cur_pos = PyInt_AsLong(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":338
 *         cdef long cur_pos = PyInt_AsLong(self.tell())
 * 
 *         if self.len_changed == 1:             # <<<<<<<<<<<<<<
 *             self.c_length()
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed == 1);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":339
 * 
 *         if self.len_changed == 1:
 *             self.c_length()             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(self.length - cur_pos)
 */
    ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->c_length(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self));
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":341
 *             self.c_length()
 * 
 *         return PyInt_FromLong(self.length - cur_pos)             # <<<<<<<<<<<<<<
 * 
 *     def getvalue(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyInt_FromLong((((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->length - __pyx_v_cur_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":343
 *         return PyInt_FromLong(self.length - cur_pos)
 * 
 *     def getvalue(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("getvalue");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":344
 * 
 *     def getvalue(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":345
 *     def getvalue(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return self.buffer.getvalue()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_39);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_39);
    __Pyx_GIVEREF(__pyx_kp_39);
    /* __pyx_t_4 allocated */
    __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 = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":347
 *             raise ValueError('buffer is closed')
 * 
 *         return self.buffer.getvalue()             # <<<<<<<<<<<<<<
 * 
 *     def read(self, int n=-1):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_getvalue); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":349
 *         return self.buffer.getvalue()
 * 
 *     def read(self, int n=-1):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_n;
  char *__pyx_v_buf;
  int __pyx_v_chars_read;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_n,0};
  __Pyx_SetupRefcountContext("read");
  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_n);
        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 = 349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_n = __pyx_PyInt_int(values[0]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_n = -1;
    }
  } else {
    __pyx_v_n = -1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_n = __pyx_PyInt_int(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __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("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.read");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":350
 * 
 *     def read(self, int n=-1):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":351
 *     def read(self, int n=-1):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __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_4 allocated */
    __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 = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":353
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef int chars_read = StringIO_cread(self.buffer, &buf, n)
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":354
 * 
 *         cdef char *buf = NULL
 *         cdef int chars_read = StringIO_cread(self.buffer, &buf, n)             # <<<<<<<<<<<<<<
 * 
 *         if n > chars_read:
 */
  __pyx_v_chars_read = PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), __pyx_v_n);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":356
 *         cdef int chars_read = StringIO_cread(self.buffer, &buf, n)
 * 
 *         if n > chars_read:             # <<<<<<<<<<<<<<
 *             if chars_read > 0:
 *                 raise IOError
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_n > __pyx_v_chars_read);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":357
 * 
 *         if n > chars_read:
 *             if chars_read > 0:             # <<<<<<<<<<<<<<
 *                 raise IOError
 * 
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (__pyx_v_chars_read > 0);
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":358
 *         if n > chars_read:
 *             if chars_read > 0:
 *                 raise IOError             # <<<<<<<<<<<<<<
 * 
 *             raise EOFError
 */
      __Pyx_Raise(__pyx_builtin_IOError, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":360
 *                 raise IOError
 * 
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyString_FromStringAndSize(buf, chars_read);
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":362
 *             raise EOFError
 * 
 *         return PyString_FromStringAndSize(buf, chars_read);             # <<<<<<<<<<<<<<
 * 
 *     def read_uchar(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_buf, __pyx_v_chars_read); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":364
 *         return PyString_FromStringAndSize(buf, chars_read);
 * 
 *     def read_uchar(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  __Pyx_SetupRefcountContext("read_uchar");
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":365
 * 
 *     def read_uchar(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":366
 *     def read_uchar(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_41);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_41);
    __Pyx_GIVEREF(__pyx_kp_41);
    /* __pyx_t_4 allocated */
    __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 = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":368
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":370
 *         cdef char *buf = NULL
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 1) != 1);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":371
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         result = <unsigned char>buf[0]
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":373
 *             raise EOFError
 * 
 *         result = <unsigned char>buf[0]             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(<long>result)
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((unsigned char)(__pyx_v_buf[0]))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":375
 *         result = <unsigned char>buf[0]
 * 
 *         return PyInt_FromLong(<long>result)             # <<<<<<<<<<<<<<
 * 
 *     def read_char(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_PyInt_long(__pyx_v_result); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((long)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_5 released */
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":377
 *         return PyInt_FromLong(<long>result)
 * 
 *     def read_char(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_char");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":378
 * 
 *     def read_char(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":379
 *     def read_char(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_42);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_42);
    __Pyx_GIVEREF(__pyx_kp_42);
    /* __pyx_t_4 allocated */
    __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 = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":381
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":383
 *         cdef char *buf = NULL
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 1) != 1);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":384
 * 
 *         if StringIO_cread(self.buffer, &buf, 1) != 1:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(<long>buf[0])
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":386
 *             raise EOFError
 * 
 *         return PyInt_FromLong(<long>buf[0])             # <<<<<<<<<<<<<<
 * 
 *     def read_ushort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((long)(__pyx_v_buf[0]))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":388
 *         return PyInt_FromLong(<long>buf[0])
 * 
 *     def read_ushort(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  unsigned short __pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_ushort");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":389
 * 
 *     def read_ushort(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":390
 *     def read_ushort(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_43);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_43);
    __Pyx_GIVEREF(__pyx_kp_43);
    /* __pyx_t_4 allocated */
    __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 = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":392
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef unsigned short result = 0
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":393
 * 
 *         cdef char *buf = NULL
 *         cdef unsigned short result = 0             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:
 */
  __pyx_v_result = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":395
 *         cdef unsigned short result = 0
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 2) != 2);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":396
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         result = <unsigned short>self.unpack_uint(buf, 2)
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":398
 *             raise EOFError
 * 
 *         result = <unsigned short>self.unpack_uint(buf, 2)             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(<long>result)
 */
  __pyx_v_result = ((unsigned short)((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 2));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":400
 *         result = <unsigned short>self.unpack_uint(buf, 2)
 * 
 *         return PyInt_FromLong(<long>result)             # <<<<<<<<<<<<<<
 * 
 *     def read_short(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((long)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":402
 *         return PyInt_FromLong(<long>result)
 * 
 *     def read_short(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  short __pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_short");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":403
 * 
 *     def read_short(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":404
 *     def read_short(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_44);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_44);
    __Pyx_GIVEREF(__pyx_kp_44);
    /* __pyx_t_4 allocated */
    __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 = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":406
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef short result = 0
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":407
 * 
 *         cdef char *buf = NULL
 *         cdef short result = 0             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:
 */
  __pyx_v_result = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":409
 *         cdef short result = 0
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 2) != 2);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":410
 * 
 *         if StringIO_cread(self.buffer, &buf, 2) != 2:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         result = <short>self.unpack_uint(buf, 2)
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":412
 *             raise EOFError
 * 
 *         result = <short>self.unpack_uint(buf, 2)             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(<long>result)
 */
  __pyx_v_result = ((short)((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 2));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":414
 *         result = <short>self.unpack_uint(buf, 2)
 * 
 *         return PyInt_FromLong(<long>result)             # <<<<<<<<<<<<<<
 * 
 *     def read_ulong(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((long)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":416
 *         return PyInt_FromLong(<long>result)
 * 
 *     def read_ulong(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_ulong");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":417
 * 
 *     def read_ulong(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":418
 *     def read_ulong(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_45);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_45);
    __Pyx_GIVEREF(__pyx_kp_45);
    /* __pyx_t_4 allocated */
    __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 = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":420
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":422
 *         cdef char *buf = NULL
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 4) != 4);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":423
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return self.unpack_uint(buf, 4)
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":425
 *             raise EOFError
 * 
 *         return self.unpack_uint(buf, 4)             # <<<<<<<<<<<<<<
 * 
 *     def read_long(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":427
 *         return self.unpack_uint(buf, 4)
 * 
 *     def read_long(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  short __pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_long");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":428
 * 
 *     def read_long(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":429
 *     def read_long(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_46);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_46);
    __Pyx_GIVEREF(__pyx_kp_46);
    /* __pyx_t_4 allocated */
    __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 = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":431
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef short result = 0
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":432
 * 
 *         cdef char *buf = NULL
 *         cdef short result = 0             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 */
  __pyx_v_result = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":434
 *         cdef short result = 0
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 4) != 4);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":435
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(self.unpack_int(buf, 4))
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":437
 *             raise EOFError
 * 
 *         return PyInt_FromLong(self.unpack_int(buf, 4))             # <<<<<<<<<<<<<<
 * 
 *     def read_24bit_uint(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_int(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":439
 *         return PyInt_FromLong(self.unpack_int(buf, 4))
 * 
 *     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\n        @since: 0.4\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_uint(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_24bit_uint");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":445
 *         @since: 0.4
 *         """
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":446
 *         """
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_47);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_47);
    __Pyx_GIVEREF(__pyx_kp_47);
    /* __pyx_t_4 allocated */
    __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 = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":448
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":450
 *         cdef char *buf = NULL
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 3) != 3);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":451
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(self.unpack_uint(buf, 3))
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":453
 *             raise EOFError
 * 
 *         return PyInt_FromLong(self.unpack_uint(buf, 3))             # <<<<<<<<<<<<<<
 * 
 *     def read_24bit_int(self):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":455
 *         return PyInt_FromLong(self.unpack_uint(buf, 3))
 * 
 *     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\n        @since: 0.4\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_24bit_int(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_24bit_int");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":461
 *         @since: 0.4
 *         """
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":462
 *         """
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_48);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_48);
    __Pyx_GIVEREF(__pyx_kp_48);
    /* __pyx_t_4 allocated */
    __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 = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":464
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":466
 *         cdef char *buf = NULL
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 3) != 3);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":467
 * 
 *         if StringIO_cread(self.buffer, &buf, 3) != 3:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyInt_FromLong(self.unpack_int(buf, 3))
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":469
 *             raise EOFError
 * 
 *         return PyInt_FromLong(self.unpack_int(buf, 3))             # <<<<<<<<<<<<<<
 * 
 *     def write(self, object obj):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyInt_FromLong(((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->unpack_int(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_buf, 3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":471
 *         return PyInt_FromLong(self.unpack_int(buf, 3))
 * 
 *     def write(self, object obj):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write(PyObject *__pyx_v_self, PyObject *__pyx_v_obj); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write(PyObject *__pyx_v_self, PyObject *__pyx_v_obj) {
  char *__pyx_v_buffer;
  Py_ssize_t __pyx_v_length;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("write");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":472
 * 
 *     def write(self, object obj):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":473
 *     def write(self, object obj):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buffer
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_49);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_49);
    __Pyx_GIVEREF(__pyx_kp_49);
    /* __pyx_t_4 allocated */
    __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 = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":478
 *         cdef Py_ssize_t length
 * 
 *         if PyString_AsStringAndSize(obj, &buffer, &length):             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyString_AsStringAndSize(__pyx_v_obj, (&__pyx_v_buffer), (&__pyx_v_length));
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":479
 * 
 *         if PyString_AsStringAndSize(obj, &buffer, &length):
 *             return             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, buffer, length)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":481
 *             return
 * 
 *         StringIO_cwrite(self.buffer, buffer, length)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_v_buffer, __pyx_v_length);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":482
 * 
 *         StringIO_cwrite(self.buffer, buffer, length)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_uchar(self, long val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":484
 *         self.len_changed = 1
 * 
 *     def write_uchar(self, long val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) {
  long __pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_uchar");
  assert(__pyx_arg_val); {
    __pyx_v_val = __pyx_PyInt_long(__pyx_arg_val); if (unlikely((__pyx_v_val == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_uchar");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":485
 * 
 *     def write_uchar(self, long val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":486
 *     def write_uchar(self, long val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if val < 0 or val > 255:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_50);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_50);
    __Pyx_GIVEREF(__pyx_kp_50);
    /* __pyx_t_4 allocated */
    __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 = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":488
 *             raise ValueError('buffer is closed')
 * 
 *         if val < 0 or val > 255:             # <<<<<<<<<<<<<<
 *             raise OverflowError('uchar not in range')
 * 
 */
  if (!(__pyx_v_val < 0)) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (__pyx_v_val > 255);
  } else {
    __pyx_t_2 = (__pyx_v_val < 0);
  }
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":489
 * 
 *         if val < 0 or val > 255:
 *             raise OverflowError('uchar not in range')             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_51);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_51);
    __Pyx_GIVEREF(__pyx_kp_51);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":491
 *             raise OverflowError('uchar not in range')
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, ((char *)(&__pyx_v_val)), 1);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":492
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_char(self, long val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":494
 *         self.len_changed = 1
 * 
 *     def write_char(self, long val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) {
  long __pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_char");
  assert(__pyx_arg_val); {
    __pyx_v_val = __pyx_PyInt_long(__pyx_arg_val); if (unlikely((__pyx_v_val == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_char");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":495
 * 
 *     def write_char(self, long val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":496
 *     def write_char(self, long val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if val < -128 or val > 127:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_52);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_52);
    __Pyx_GIVEREF(__pyx_kp_52);
    /* __pyx_t_4 allocated */
    __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 = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":498
 *             raise ValueError('buffer is closed')
 * 
 *         if val < -128 or val > 127:             # <<<<<<<<<<<<<<
 *             raise OverflowError('char not in range')
 * 
 */
  if (!(__pyx_v_val < -128)) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (__pyx_v_val > 127);
  } else {
    __pyx_t_2 = (__pyx_v_val < -128);
  }
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":499
 * 
 *         if val < -128 or val > 127:
 *             raise OverflowError('char not in range')             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_53);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_53);
    __Pyx_GIVEREF(__pyx_kp_53);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":501
 *             raise OverflowError('char not in range')
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, ((char *)(&__pyx_v_val)), 1);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":502
 * 
 *         StringIO_cwrite(self.buffer, <char *>&val, 1);
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_ushort(self, long val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":504
 *         self.len_changed = 1
 * 
 *     def write_ushort(self, long val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) {
  long __pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_ushort");
  assert(__pyx_arg_val); {
    __pyx_v_val = __pyx_PyInt_long(__pyx_arg_val); if (unlikely((__pyx_v_val == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_ushort");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":505
 * 
 *     def write_ushort(self, long val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":506
 *     def write_ushort(self, long val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if val < 0 or val > 65535:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_54);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_54);
    __Pyx_GIVEREF(__pyx_kp_54);
    /* __pyx_t_4 allocated */
    __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 = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":508
 *             raise ValueError('buffer is closed')
 * 
 *         if val < 0 or val > 65535:             # <<<<<<<<<<<<<<
 *             raise OverflowError('ushort not in range')
 * 
 */
  if (!(__pyx_v_val < 0)) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (__pyx_v_val > 65535);
  } else {
    __pyx_t_2 = (__pyx_v_val < 0);
  }
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":509
 * 
 *         if val < 0 or val > 65535:
 *             raise OverflowError('ushort not in range')             # <<<<<<<<<<<<<<
 * 
 *         self.pack_uint(val, 2)
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_55);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_55);
    __Pyx_GIVEREF(__pyx_kp_55);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":511
 *             raise OverflowError('ushort not in range')
 * 
 *         self.pack_uint(val, 2)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_val, 2);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":512
 * 
 *         self.pack_uint(val, 2)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_short(self, long val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":514
 *         self.len_changed = 1
 * 
 *     def write_short(self, long val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) {
  long __pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_short");
  assert(__pyx_arg_val); {
    __pyx_v_val = __pyx_PyInt_long(__pyx_arg_val); if (unlikely((__pyx_v_val == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_short");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":515
 * 
 *     def write_short(self, long val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":516
 *     def write_short(self, long val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if val < -32768 or val > 32767:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_56);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_56);
    __Pyx_GIVEREF(__pyx_kp_56);
    /* __pyx_t_4 allocated */
    __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 = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":518
 *             raise ValueError('buffer is closed')
 * 
 *         if val < -32768 or val > 32767:             # <<<<<<<<<<<<<<
 *             raise OverflowError('short not in range')
 * 
 */
  if (!(__pyx_v_val < -32768)) {
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (__pyx_v_val > 32767);
  } else {
    __pyx_t_2 = (__pyx_v_val < -32768);
  }
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":519
 * 
 *         if val < -32768 or val > 32767:
 *             raise OverflowError('short not in range')             # <<<<<<<<<<<<<<
 * 
 *         self.pack_int(val, 2)
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_57);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_57);
    __Pyx_GIVEREF(__pyx_kp_57);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":521
 *             raise OverflowError('short not in range')
 * 
 *         self.pack_int(val, 2)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_int(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_val, 2);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":522
 * 
 *         self.pack_int(val, 2)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_ulong(self, val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":524
 *         self.len_changed = 1
 * 
 *     def write_ulong(self, val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  unsigned long __pyx_t_6;
  __Pyx_SetupRefcountContext("write_ulong");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":525
 * 
 *     def write_ulong(self, val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":526
 *     def write_ulong(self, val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if val < 0 or val > 4294967295L:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_58);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_58);
    __Pyx_GIVEREF(__pyx_kp_58);
    /* __pyx_t_4 allocated */
    __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 = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":528
 *             raise ValueError('buffer is closed')
 * 
 *         if val < 0 or val > 4294967295L:             # <<<<<<<<<<<<<<
 *             raise OverflowError
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_val, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  if (!__pyx_t_2) {
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_RichCompare(__pyx_v_val, __pyx_int_4294967295L, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_1 allocated */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_5 allocated */
    __pyx_t_5 = __pyx_t_1;
    /* __pyx_t_1 released */
  } else {
    __pyx_t_5 = __pyx_t_2;
    /* __pyx_t_2 released */
  }
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":529
 * 
 *         if val < 0 or val > 4294967295L:
 *             raise OverflowError             # <<<<<<<<<<<<<<
 * 
 *         self.pack_uint(<unsigned long>val, 4)
 */
    __Pyx_Raise(__pyx_builtin_OverflowError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":531
 *             raise OverflowError
 * 
 *         self.pack_uint(<unsigned long>val, 4)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  /* __pyx_t_6 allocated */
  __pyx_t_6 = PyInt_AsUnsignedLongMask(__pyx_v_val); if (unlikely((__pyx_t_6 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), ((unsigned long)__pyx_t_6), 4);
  /* __pyx_t_6 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":532
 * 
 *         self.pack_uint(<unsigned long>val, 4)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_long(self, val):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":534
 *         self.len_changed = 1
 * 
 *     def write_long(self, val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  __Pyx_SetupRefcountContext("write_long");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":535
 * 
 *     def write_long(self, val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":536
 *     def write_long(self, val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if not -2147483648 <= val <= 2147483647:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_59);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_59);
    __Pyx_GIVEREF(__pyx_kp_59);
    /* __pyx_t_4 allocated */
    __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 = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":538
 *             raise ValueError('buffer is closed')
 * 
 *         if not -2147483648 <= val <= 2147483647:             # <<<<<<<<<<<<<<
 *             raise OverflowError
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_RichCompare(__pyx_int_neg_2147483648, __pyx_v_val, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (__Pyx_PyObject_IsTrue(__pyx_t_4)) {
    __Pyx_DECREF(__pyx_t_4);
    __pyx_t_4 = PyObject_RichCompare(__pyx_v_val, __pyx_int_2147483647, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
  }
  /* __pyx_t_2 allocated */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (!__pyx_t_2);
  /* __pyx_t_2 released */
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":539
 * 
 *         if not -2147483648 <= val <= 2147483647:
 *             raise OverflowError             # <<<<<<<<<<<<<<
 * 
 *         self.pack_int(<long>val, 4)
 */
    __Pyx_Raise(__pyx_builtin_OverflowError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":541
 *             raise OverflowError
 * 
 *         self.pack_int(<long>val, 4)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_PyInt_long(__pyx_v_val); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_int(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), ((long)__pyx_t_5), 4);
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":542
 * 
 *         self.pack_int(<long>val, 4)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_24bit_uint(self, unsigned long n):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":544
 *         self.len_changed = 1
 * 
 *     def write_24bit_uint(self, unsigned long n):             # <<<<<<<<<<<<<<
 *         """
 *         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_n); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_uint[] = "\n        Writes a 24 bit unsigned integer to the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_uint(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) {
  unsigned long __pyx_v_n;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_24bit_uint");
  assert(__pyx_arg_n); {
    __pyx_v_n = PyInt_AsUnsignedLongMask(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 544; __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":548
 *         Writes a 24 bit unsigned integer to the stream.
 *         """
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":549
 *         """
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if not 0 <= n <= 0xffffff:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_60);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_60);
    __Pyx_GIVEREF(__pyx_kp_60);
    /* __pyx_t_4 allocated */
    __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 = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":551
 *             raise ValueError('buffer is closed')
 * 
 *         if not 0 <= n <= 0xffffff:             # <<<<<<<<<<<<<<
 *             raise OverflowError("n is out of range")
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (0 <= __pyx_v_n);
  if (__pyx_t_2) {
    __pyx_t_2 = (__pyx_v_n <= 0xffffff);
  }
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (!__pyx_t_2);
  /* __pyx_t_2 released */
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":552
 * 
 *         if not 0 <= n <= 0xffffff:
 *             raise OverflowError("n is out of range")             # <<<<<<<<<<<<<<
 * 
 *         self.pack_uint(n, 3)
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_61);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_61);
    __Pyx_GIVEREF(__pyx_kp_61);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":554
 *             raise OverflowError("n is out of range")
 * 
 *         self.pack_uint(n, 3)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_uint(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_n, 3);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":555
 * 
 *         self.pack_uint(n, 3)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def write_24bit_int(self, long n):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":557
 *         self.len_changed = 1
 * 
 *     def write_24bit_int(self, long n):             # <<<<<<<<<<<<<<
 *         """
 *         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_n); /*proto*/
static char __pyx_doc_6cpyamf_4util_18BufferedByteStream_write_24bit_int[] = "\n        Writes a 24 bit integer to the stream.\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_24bit_int(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) {
  long __pyx_v_n;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_24bit_int");
  assert(__pyx_arg_n); {
    __pyx_v_n = __pyx_PyInt_long(__pyx_arg_n); if (unlikely((__pyx_v_n == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __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":561
 *         Writes a 24 bit integer to the stream.
 *         """
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":562
 *         """
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if not -8388608 <= n <= 8388607:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_62);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_62);
    __Pyx_GIVEREF(__pyx_kp_62);
    /* __pyx_t_4 allocated */
    __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 = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":564
 *             raise ValueError('buffer is closed')
 * 
 *         if not -8388608 <= n <= 8388607:             # <<<<<<<<<<<<<<
 *             raise OverflowError("n is out of range")
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (-8388608 <= __pyx_v_n);
  if (__pyx_t_2) {
    __pyx_t_2 = (__pyx_v_n <= 8388607);
  }
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (!__pyx_t_2);
  /* __pyx_t_2 released */
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":565
 * 
 *         if not -8388608 <= n <= 8388607:
 *             raise OverflowError("n is out of range")             # <<<<<<<<<<<<<<
 * 
 *         self.pack_int(n, 3)
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_63);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_63);
    __Pyx_GIVEREF(__pyx_kp_63);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":567
 *             raise OverflowError("n is out of range")
 * 
 *         self.pack_int(n, 3)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->pack_int(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self), __pyx_v_n, 3);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":568
 * 
 *         self.pack_int(n, 3)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def read_utf8_string(self, unsigned int l):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":570
 *         self.len_changed = 1
 * 
 *     def read_utf8_string(self, unsigned int l):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_arg_l); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_arg_l) {
  unsigned int __pyx_v_l;
  char *__pyx_v_buf;
  long __pyx_v_n;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_utf8_string");
  assert(__pyx_arg_l); {
    __pyx_v_l = PyInt_AsUnsignedLongMask(__pyx_arg_l); if (unlikely((__pyx_v_l == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __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":571
 * 
 *     def read_utf8_string(self, unsigned int l):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":572
 *     def read_utf8_string(self, unsigned int l):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char* buf = NULL
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_64);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_64);
    __Pyx_GIVEREF(__pyx_kp_64);
    /* __pyx_t_4 allocated */
    __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 = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":574
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char* buf = NULL             # <<<<<<<<<<<<<<
 *         cdef long n
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":577
 *         cdef long n
 * 
 *         n = StringIO_cread(self.buffer, &buf, l)             # <<<<<<<<<<<<<<
 * 
 *         if n != l:
 */
  __pyx_v_n = PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), __pyx_v_l);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":579
 *         n = StringIO_cread(self.buffer, &buf, l)
 * 
 *         if n != l:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_n != __pyx_v_l);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":580
 * 
 *         if n != l:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         return PyUnicode_DecodeUTF8(buf, n, '')
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":582
 *             raise EOFError
 * 
 *         return PyUnicode_DecodeUTF8(buf, n, '')             # <<<<<<<<<<<<<<
 * 
 *     def write_utf8_string(self, object s):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyUnicode_DecodeUTF8(__pyx_v_buf, __pyx_v_n, __pyx_k_65); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":584
 *         return PyUnicode_DecodeUTF8(buf, n, '')
 * 
 *     def write_utf8_string(self, object s):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string(PyObject *__pyx_v_self, PyObject *__pyx_v_s) {
  PyObject *__pyx_v_encoded_string;
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_l;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  unsigned char __pyx_t_6;
  __Pyx_SetupRefcountContext("write_utf8_string");
  __pyx_v_encoded_string = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":585
 * 
 *     def write_utf8_string(self, object s):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":586
 *     def write_utf8_string(self, object s):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef object encoded_string
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_66);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_66);
    __Pyx_GIVEREF(__pyx_kp_66);
    /* __pyx_t_4 allocated */
    __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 = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":589
 * 
 *         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":590
 *         cdef object encoded_string
 *         cdef char *buf = NULL
 *         cdef Py_ssize_t l = -1             # <<<<<<<<<<<<<<
 * 
 *         if PyUnicode_Check(s):
 */
  __pyx_v_l = -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":592
 *         cdef Py_ssize_t l = -1
 * 
 *         if PyUnicode_Check(s):             # <<<<<<<<<<<<<<
 *             encoded_string = PyUnicode_AsUTF8String(s)
 *         elif PyString_Check(s):
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyUnicode_Check(__pyx_v_s);
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":593
 * 
 *         if PyUnicode_Check(s):
 *             encoded_string = PyUnicode_AsUTF8String(s)             # <<<<<<<<<<<<<<
 *         elif PyString_Check(s):
 *             encoded_string = PyString_AsEncodedObject(s, "utf8", "strict")
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyUnicode_AsUTF8String(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_v_encoded_string);
    __pyx_v_encoded_string = __pyx_t_4;
    __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    goto __pyx_L6;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":594
 *         if PyUnicode_Check(s):
 *             encoded_string = PyUnicode_AsUTF8String(s)
 *         elif PyString_Check(s):             # <<<<<<<<<<<<<<
 *             encoded_string = PyString_AsEncodedObject(s, "utf8", "strict")
 *         else:
 */
  /* __pyx_t_6 allocated */
  __pyx_t_6 = PyString_Check(__pyx_v_s);
  if (__pyx_t_6) {
    /* __pyx_t_6 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":595
 *             encoded_string = PyUnicode_AsUTF8String(s)
 *         elif PyString_Check(s):
 *             encoded_string = PyString_AsEncodedObject(s, "utf8", "strict")             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError('value must be Unicode or str')
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyString_AsEncodedObject(__pyx_v_s, __pyx_k_67, __pyx_k_68); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_v_encoded_string);
    __pyx_v_encoded_string = __pyx_t_4;
    __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":597
 *             encoded_string = PyString_AsEncodedObject(s, "utf8", "strict")
 *         else:
 *             raise TypeError('value must be Unicode or str')             # <<<<<<<<<<<<<<
 * 
 *         if not encoded_string:
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_69);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_69);
    __Pyx_GIVEREF(__pyx_kp_69);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":599
 *             raise TypeError('value must be Unicode or str')
 * 
 *         if not encoded_string:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_encoded_string); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (!__pyx_t_2);
  /* __pyx_t_2 released */
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":600
 * 
 *         if not encoded_string:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         if (PyString_AsStringAndSize(encoded_string, &buf, &l) == -1):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

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

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":603
 * 
 *         if (PyString_AsStringAndSize(encoded_string, &buf, &l) == -1):
 *             return             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, buf, l)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":605
 *             return
 * 
 *         StringIO_cwrite(self.buffer, buf, l)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_v_buf, __pyx_v_l);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":606
 * 
 *         StringIO_cwrite(self.buffer, buf, l)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def read_double(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":608
 *         self.len_changed = 1
 * 
 *     def read_double(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double(PyObject *__pyx_v_self, PyObject *unused) {
  double __pyx_v_x;
  char *__pyx_v_buf;
  unsigned char __pyx_v_le;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_SetupRefcountContext("read_double");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":609
 * 
 *     def read_double(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":610
 *     def read_double(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef double x
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_70);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_70);
    __Pyx_GIVEREF(__pyx_kp_70);
    /* __pyx_t_4 allocated */
    __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 = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":613
 * 
 *         cdef double x
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef unsigned char le = 1
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":614
 *         cdef double x
 *         cdef char *buf = NULL
 *         cdef unsigned char le = 1             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 8) != 8:
 */
  __pyx_v_le = 1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":616
 *         cdef unsigned char le = 1
 * 
 *         if StringIO_cread(self.buffer, &buf, 8) != 8:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 8) != 8);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":617
 * 
 *         if StringIO_cread(self.buffer, &buf, 8) != 8:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         if float_broken:
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":619
 *             raise EOFError
 * 
 *         if float_broken:             # <<<<<<<<<<<<<<
 *             le = 0
 *             if not is_big_endian(self._endian):
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_v_6cpyamf_4util_float_broken;
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":620
 * 
 *         if float_broken:
 *             le = 0             # <<<<<<<<<<<<<<
 *             if not is_big_endian(self._endian):
 *                 swap_bytes(<unsigned char *>buf, 8)
 */
    __pyx_v_le = 0;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":621
 *         if float_broken:
 *             le = 0
 *             if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                 swap_bytes(<unsigned char *>buf, 8)
 * 
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian));
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":622
 *             le = 0
 *             if not is_big_endian(self._endian):
 *                 swap_bytes(<unsigned char *>buf, 8)             # <<<<<<<<<<<<<<
 * 
 *             if memcmp(NaN, buf, 8) == 0:
 */
      __pyx_f_6cpyamf_4util_swap_bytes(((unsigned char *)__pyx_v_buf), 8);
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":624
 *                 swap_bytes(<unsigned char *>buf, 8)
 * 
 *             if memcmp(NaN, buf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return fpconst.NaN
 *             elif memcmp(NegInf, buf, 8) == 0:
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (memcmp(__pyx_v_6cpyamf_4util_NaN, __pyx_v_buf, 8) == 0);
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":625
 * 
 *             if memcmp(NaN, buf, 8) == 0:
 *                 return fpconst.NaN             # <<<<<<<<<<<<<<
 *             elif memcmp(NegInf, buf, 8) == 0:
 *                 return fpconst.NegInf
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      /* __pyx_t_4 allocated */
      __pyx_t_4 = PyObject_GetAttr(__pyx_1, __pyx_kp_NaN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      /* __pyx_t_4 released */
      goto __pyx_L0;
      goto __pyx_L9;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":626
 *             if memcmp(NaN, buf, 8) == 0:
 *                 return fpconst.NaN
 *             elif memcmp(NegInf, buf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return fpconst.NegInf
 *             elif memcmp(PosInf, buf, 8) == 0:
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (memcmp(__pyx_v_6cpyamf_4util_NegInf, __pyx_v_buf, 8) == 0);
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":627
 *                 return fpconst.NaN
 *             elif memcmp(NegInf, buf, 8) == 0:
 *                 return fpconst.NegInf             # <<<<<<<<<<<<<<
 *             elif memcmp(PosInf, buf, 8) == 0:
 *                 return fpconst.PosInf
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      /* __pyx_t_4 allocated */
      __pyx_t_4 = PyObject_GetAttr(__pyx_1, __pyx_kp_NegInf); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      /* __pyx_t_4 released */
      goto __pyx_L0;
      goto __pyx_L9;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":628
 *             elif memcmp(NegInf, buf, 8) == 0:
 *                 return fpconst.NegInf
 *             elif memcmp(PosInf, buf, 8) == 0:             # <<<<<<<<<<<<<<
 *                 return fpconst.PosInf
 *         elif is_big_endian(self._endian):
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (memcmp(__pyx_v_6cpyamf_4util_PosInf, __pyx_v_buf, 8) == 0);
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":629
 *                 return fpconst.NegInf
 *             elif memcmp(PosInf, buf, 8) == 0:
 *                 return fpconst.PosInf             # <<<<<<<<<<<<<<
 *         elif is_big_endian(self._endian):
 *             le = 0
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      /* __pyx_t_4 allocated */
      __pyx_t_4 = PyObject_GetAttr(__pyx_1, __pyx_kp_PosInf); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      /* __pyx_t_4 released */
      goto __pyx_L0;
      goto __pyx_L9;
    }
    __pyx_L9:;
    goto __pyx_L7;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":630
 *             elif memcmp(PosInf, buf, 8) == 0:
 *                 return fpconst.PosInf
 *         elif is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             le = 0
 * 
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian);
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":631
 *                 return fpconst.PosInf
 *         elif is_big_endian(self._endian):
 *             le = 0             # <<<<<<<<<<<<<<
 * 
 *         x = _PyFloat_Unpack8(<unsigned char *>buf, le)
 */
    __pyx_v_le = 0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":633
 *             le = 0
 * 
 *         x = _PyFloat_Unpack8(<unsigned char *>buf, le)             # <<<<<<<<<<<<<<
 * 
 *         return PyFloat_FromDouble(x)
 */
  __pyx_v_x = _PyFloat_Unpack8(((unsigned char *)__pyx_v_buf), __pyx_v_le);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":635
 *         x = _PyFloat_Unpack8(<unsigned char *>buf, le)
 * 
 *         return PyFloat_FromDouble(x)             # <<<<<<<<<<<<<<
 * 
 *     def write_double(self, val):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":637
 *         return PyFloat_FromDouble(x)
 * 
 *     def write_double(self, val):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  char *__pyx_v_buf;
  int __pyx_v_le;
  int __pyx_v_done;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  double __pyx_t_7;
  __Pyx_SetupRefcountContext("write_double");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":638
 * 
 *     def write_double(self, val):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":639
 *     def write_double(self, val):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(8)
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_71);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_71);
    __Pyx_GIVEREF(__pyx_kp_71);
    /* __pyx_t_4 allocated */
    __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 = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":641
 *             raise ValueError('buffer is closed')
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(8)             # <<<<<<<<<<<<<<
 *         cdef int le = 0
 *         cdef int done = 0
 */
  __pyx_v_buf = ((char *)PyMem_Malloc(8));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":642
 * 
 *         cdef char *buf = <char *>PyMem_Malloc(8)
 *         cdef int le = 0             # <<<<<<<<<<<<<<
 *         cdef int done = 0
 * 
 */
  __pyx_v_le = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":643
 *         cdef char *buf = <char *>PyMem_Malloc(8)
 *         cdef int le = 0
 *         cdef int done = 0             # <<<<<<<<<<<<<<
 * 
 *         if float_broken:
 */
  __pyx_v_done = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":645
 *         cdef int done = 0
 * 
 *         if float_broken:             # <<<<<<<<<<<<<<
 *             if fpconst.isNaN(val):
 *                 memcpy(buf, NaN, 8)
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_v_6cpyamf_4util_float_broken;
  if (__pyx_t_5) {
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":646
 * 
 *         if float_broken:
 *             if fpconst.isNaN(val):             # <<<<<<<<<<<<<<
 *                 memcpy(buf, NaN, 8)
 *                 done = 1
 */
    __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_1, __pyx_kp_isNaN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_val);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_val);
    __Pyx_GIVEREF(__pyx_v_val);
    /* __pyx_t_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":647
 *         if float_broken:
 *             if fpconst.isNaN(val):
 *                 memcpy(buf, NaN, 8)             # <<<<<<<<<<<<<<
 *                 done = 1
 *             elif fpconst.isNegInf(val):
 */
      memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_NaN, 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":648
 *             if fpconst.isNaN(val):
 *                 memcpy(buf, NaN, 8)
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif fpconst.isNegInf(val):
 *                 memcpy(buf, NegInf, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":649
 *                 memcpy(buf, NaN, 8)
 *                 done = 1
 *             elif fpconst.isNegInf(val):             # <<<<<<<<<<<<<<
 *                 memcpy(buf, NegInf, 8)
 *                 done = 1
 */
    __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    /* __pyx_t_6 allocated */
    __pyx_t_6 = PyObject_GetAttr(__pyx_1, __pyx_kp_isNegInf); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_val);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_val);
    __Pyx_GIVEREF(__pyx_v_val);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_6 released */
    /* __pyx_t_3 released */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":650
 *                 done = 1
 *             elif fpconst.isNegInf(val):
 *                 memcpy(buf, NegInf, 8)             # <<<<<<<<<<<<<<
 *                 done = 1
 *             elif fpconst.isPosInf(val):
 */
      memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_NegInf, 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":651
 *             elif fpconst.isNegInf(val):
 *                 memcpy(buf, NegInf, 8)
 *                 done = 1             # <<<<<<<<<<<<<<
 *             elif fpconst.isPosInf(val):
 *                 memcpy(buf, PosInf, 8)
 */
      __pyx_v_done = 1;
      goto __pyx_L7;
    }

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":652
 *                 memcpy(buf, NegInf, 8)
 *                 done = 1
 *             elif fpconst.isPosInf(val):             # <<<<<<<<<<<<<<
 *                 memcpy(buf, PosInf, 8)
 *                 done = 1
 */
    __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_fpconst); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_1, __pyx_kp_isPosInf); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_val);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_val);
    __Pyx_GIVEREF(__pyx_v_val);
    /* __pyx_t_6 allocated */
    __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* __pyx_t_6 released */
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":653
 *                 done = 1
 *             elif fpconst.isPosInf(val):
 *                 memcpy(buf, PosInf, 8)             # <<<<<<<<<<<<<<
 *                 done = 1
 * 
 */
      memcpy(__pyx_v_buf, __pyx_v_6cpyamf_4util_PosInf, 8);

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":654
 *             elif fpconst.isPosInf(val):
 *                 memcpy(buf, PosInf, 8)
 *                 done = 1             # <<<<<<<<<<<<<<
 * 
 *             if done == 1 and not is_big_endian(self._endian):
 */
      __pyx_v_done = 1;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":656
 *                 done = 1
 * 
 *             if done == 1 and not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                 swap_bytes(<unsigned char *>buf, 8)
 * 
 */
    if ((__pyx_v_done == 1)) {
      /* __pyx_t_2 allocated */
      __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian));
    } else {
      __pyx_t_2 = (__pyx_v_done == 1);
    }
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":657
 * 
 *             if done == 1 and not is_big_endian(self._endian):
 *                 swap_bytes(<unsigned char *>buf, 8)             # <<<<<<<<<<<<<<
 * 
 *         if done == 0:
 */
      __pyx_f_6cpyamf_4util_swap_bytes(((unsigned char *)__pyx_v_buf), 8);
      goto __pyx_L8;
    }
    __pyx_L8:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":659
 *                 swap_bytes(<unsigned char *>buf, 8)
 * 
 *         if done == 0:             # <<<<<<<<<<<<<<
 *             if not is_big_endian(self._endian):
 *                 le = 1
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_done == 0);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":660
 * 
 *         if done == 0:
 *             if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *                 le = 1
 * 
 */
    /* __pyx_t_2 allocated */
    __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian));
    if (__pyx_t_2) {
      /* __pyx_t_2 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":661
 *         if done == 0:
 *             if not is_big_endian(self._endian):
 *                 le = 1             # <<<<<<<<<<<<<<
 * 
 *             _PyFloat_Pack8(val, <unsigned char *>buf, le)
 */
      __pyx_v_le = 1;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":663
 *                 le = 1
 * 
 *             _PyFloat_Pack8(val, <unsigned char *>buf, le)             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(self.buffer, buf, 8)
 */
    /* __pyx_t_7 allocated */
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_val); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    _PyFloat_Pack8(__pyx_t_7, ((unsigned char *)__pyx_v_buf), __pyx_v_le);
    /* __pyx_t_7 released */
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":665
 *             _PyFloat_Pack8(val, <unsigned char *>buf, le)
 * 
 *         StringIO_cwrite(self.buffer, buf, 8)             # <<<<<<<<<<<<<<
 *         PyMem_Free(buf)
 *         self.len_changed = 1
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_v_buf, 8);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":666
 * 
 *         StringIO_cwrite(self.buffer, buf, 8)
 *         PyMem_Free(buf)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":667
 *         StringIO_cwrite(self.buffer, buf, 8)
 *         PyMem_Free(buf)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def read_float(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_double");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":669
 *         self.len_changed = 1
 * 
 *     def read_float(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float(PyObject *__pyx_v_self, PyObject *unused) {
  float __pyx_v_x;
  char *__pyx_v_buf;
  unsigned char __pyx_v_le;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("read_float");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":670
 * 
 *     def read_float(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":671
 *     def read_float(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef float x
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_72);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_72);
    __Pyx_GIVEREF(__pyx_kp_72);
    /* __pyx_t_4 allocated */
    __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 = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":675
 *         cdef float x
 *         cdef char *buf
 *         cdef unsigned char le = 0             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 */
  __pyx_v_le = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":677
 *         cdef unsigned char le = 0
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:             # <<<<<<<<<<<<<<
 *             raise EOFError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), 4) != 4);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":678
 * 
 *         if StringIO_cread(self.buffer, &buf, 4) != 4:
 *             raise EOFError             # <<<<<<<<<<<<<<
 * 
 *         if not is_big_endian(self._endian):
 */
    __Pyx_Raise(__pyx_builtin_EOFError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":680
 *             raise EOFError
 * 
 *         if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             le = 1
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian));
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

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

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":683
 *             le = 1
 * 
 *         x = _PyFloat_Unpack4(<unsigned char *>buf, le)             # <<<<<<<<<<<<<<
 * 
 *         return PyFloat_FromDouble(x)
 */
  __pyx_v_x = _PyFloat_Unpack4(((unsigned char *)__pyx_v_buf), __pyx_v_le);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":685
 *         x = _PyFloat_Unpack4(<unsigned char *>buf, le)
 * 
 *         return PyFloat_FromDouble(x)             # <<<<<<<<<<<<<<
 * 
 *     def write_float(self, double c):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":687
 *         return PyFloat_FromDouble(x)
 * 
 *     def write_float(self, double c):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float(PyObject *__pyx_v_self, PyObject *__pyx_arg_c); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float(PyObject *__pyx_v_self, PyObject *__pyx_arg_c) {
  double __pyx_v_c;
  char __pyx_v_buf[8];
  unsigned char __pyx_v_le;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("write_float");
  assert(__pyx_arg_c); {
    __pyx_v_c = __pyx_PyFloat_AsDouble(__pyx_arg_c); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.write_float");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":688
 * 
 *     def write_float(self, double c):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":689
 *     def write_float(self, double c):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         cdef char buf[8]
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_73);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_73);
    __Pyx_GIVEREF(__pyx_kp_73);
    /* __pyx_t_4 allocated */
    __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 = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":692
 * 
 *         cdef char buf[8]
 *         cdef unsigned char le = 0             # <<<<<<<<<<<<<<
 * 
 *         if not is_big_endian(self._endian):
 */
  __pyx_v_le = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":694
 *         cdef unsigned char le = 0
 * 
 *         if not is_big_endian(self._endian):             # <<<<<<<<<<<<<<
 *             le = 1
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_f_6cpyamf_4util_is_big_endian(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->_endian));
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

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

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":697
 *             le = 1
 * 
 *         _PyFloat_Pack4(c, <unsigned char *>buf, le)             # <<<<<<<<<<<<<<
 *         StringIO_cwrite(self.buffer, buf, 4)
 *         self.len_changed = 1
 */
  _PyFloat_Pack4(__pyx_v_c, ((unsigned char *)__pyx_v_buf), __pyx_v_le);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":698
 * 
 *         _PyFloat_Pack4(c, <unsigned char *>buf, le)
 *         StringIO_cwrite(self.buffer, buf, 4)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  PycStringIO->cwrite(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_v_buf, 4);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":699
 *         _PyFloat_Pack4(c, <unsigned char *>buf, le)
 *         StringIO_cwrite(self.buffer, buf, 4)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":701
 *         self.len_changed = 1
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             return 0
 */

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;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("__len__");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":702
 * 
 *     def __len__(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":703
 *     def __len__(self):
 *         if not self.buffer:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         return self.c_length()
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":705
 *             return 0
 * 
 *         return self.c_length()             # <<<<<<<<<<<<<<
 * 
 *     def peek(self, long size=1):
 */
  __pyx_r = ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->c_length(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self));
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":707
 *         return self.c_length()
 * 
 *     def peek(self, long size=1):             # <<<<<<<<<<<<<<
 *         if size == -1:
 *             return self.peek(<long>self.remaining())
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  long __pyx_v_size;
  char *__pyx_v_buffer;
  long __pyx_v_pos;
  long __pyx_v_remaining;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  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};
    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 = 707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_size = __pyx_PyInt_long(values[0]); if (unlikely((__pyx_v_size == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_size = 1;
    }
  } else {
    __pyx_v_size = 1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = __pyx_PyInt_long(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_size == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __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("peek", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.peek");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":708
 * 
 *     def peek(self, long size=1):
 *         if size == -1:             # <<<<<<<<<<<<<<
 *             return self.peek(<long>self.remaining())
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_size == -1);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":709
 *     def peek(self, long size=1):
 *         if size == -1:
 *             return self.peek(<long>self.remaining())             # <<<<<<<<<<<<<<
 * 
 *         if size < -1:
 */
    __Pyx_XDECREF(__pyx_r);
    /* __pyx_t_2 allocated */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_peek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_remaining); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    /* __pyx_t_4 allocated */
    __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 = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    /* __pyx_t_5 allocated */
    __pyx_t_5 = __pyx_PyInt_long(__pyx_t_4); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyInt_FromLong(((long)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_5 released */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __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 released */
    /* __pyx_t_4 allocated */
    __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 = 709; __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_t_2 released */
    /* __pyx_t_3 released */
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":711
 *             return self.peek(<long>self.remaining())
 * 
 *         if size < -1:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot peek backwards")
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_size < -1);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":712
 * 
 *         if size < -1:
 *             raise ValueError("Cannot peek backwards")             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buffer = NULL
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_74);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_74);
    __Pyx_GIVEREF(__pyx_kp_74);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":714
 *             raise ValueError("Cannot peek backwards")
 * 
 *         cdef char *buffer = NULL             # <<<<<<<<<<<<<<
 *         cdef long pos = <long>self.tell()
 *         cdef long remaining = self.c_remaining()
 */
  __pyx_v_buffer = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":715
 * 
 *         cdef char *buffer = NULL
 *         cdef long pos = <long>self.tell()             # <<<<<<<<<<<<<<
 *         cdef long remaining = self.c_remaining()
 * 
 */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_tell); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  /* __pyx_t_4 allocated */
  __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 = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = __pyx_PyInt_long(__pyx_t_4); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __pyx_v_pos = ((long)__pyx_t_5);
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":716
 *         cdef char *buffer = NULL
 *         cdef long pos = <long>self.tell()
 *         cdef long remaining = self.c_remaining()             # <<<<<<<<<<<<<<
 * 
 *         if remaining >= size:
 */
  __pyx_v_remaining = ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->c_remaining(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":718
 *         cdef long remaining = self.c_remaining()
 * 
 *         if remaining >= size:             # <<<<<<<<<<<<<<
 *             if StringIO_cread(self.buffer, &buffer, size) != size:
 *                 raise RuntimeError
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = (__pyx_v_remaining >= __pyx_v_size);
  if (__pyx_t_1) {
    /* __pyx_t_1 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":719
 * 
 *         if remaining >= size:
 *             if StringIO_cread(self.buffer, &buffer, size) != size:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError
 *         else:
 */
    /* __pyx_t_1 allocated */
    __pyx_t_1 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buffer), __pyx_v_size) != __pyx_v_size);
    if (__pyx_t_1) {
      /* __pyx_t_1 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":720
 *         if remaining >= size:
 *             if StringIO_cread(self.buffer, &buffer, size) != size:
 *                 raise RuntimeError             # <<<<<<<<<<<<<<
 *         else:
 *             if StringIO_cread(self.buffer, &buffer, remaining) != remaining:
 */
      __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L9;
    }
    __pyx_L9:;
    goto __pyx_L8;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":722
 *                 raise RuntimeError
 *         else:
 *             if StringIO_cread(self.buffer, &buffer, remaining) != remaining:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError
 * 
 */
    /* __pyx_t_1 allocated */
    __pyx_t_1 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buffer), __pyx_v_remaining) != __pyx_v_remaining);
    if (__pyx_t_1) {
      /* __pyx_t_1 released */

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":723
 *         else:
 *             if StringIO_cread(self.buffer, &buffer, remaining) != remaining:
 *                 raise RuntimeError             # <<<<<<<<<<<<<<
 * 
 *             size = remaining
 */
      __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":725
 *                 raise RuntimeError
 * 
 *             size = remaining             # <<<<<<<<<<<<<<
 * 
 *         self.seek(pos)
 */
    __pyx_v_size = __pyx_v_remaining;
  }
  __pyx_L8:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":727
 *             size = remaining
 * 
 *         self.seek(pos)             # <<<<<<<<<<<<<<
 * 
 *         return PyString_FromStringAndSize(buffer, size)
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_2 released */
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":729
 *         self.seek(pos)
 * 
 *         return PyString_FromStringAndSize(buffer, size)             # <<<<<<<<<<<<<<
 * 
 *     def truncate(self, long size=0):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_buffer, __pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.peek");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":731
 *         return PyString_FromStringAndSize(buffer, size)
 * 
 *     def truncate(self, long size=0):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  long __pyx_v_size;
  char *__pyx_v_buffer;
  unsigned long __pyx_v_cur_pos;
  PyObject *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned long __pyx_t_6;
  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 = 731; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_size = __pyx_PyInt_long(values[0]); if (unlikely((__pyx_v_size == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __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_long(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_size == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __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 = 731; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.truncate");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":732
 * 
 *     def truncate(self, long size=0):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":733
 *     def truncate(self, long size=0):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         if size == 0:
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_75);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_75);
    __Pyx_GIVEREF(__pyx_kp_75);
    /* __pyx_t_4 allocated */
    __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 = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":735
 *             raise ValueError('buffer is closed')
 * 
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             self.buffer = None
 *             self.__init__(self)
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_size == 0);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":736
 * 
 *         if size == 0:
 *             self.buffer = None             # <<<<<<<<<<<<<<
 *             self.__init__(self)
 *             self.len_changed = 1
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
    __Pyx_DECREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
    ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer = Py_None;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":737
 *         if size == 0:
 *             self.buffer = None
 *             self.__init__(self)             # <<<<<<<<<<<<<<
 *             self.len_changed = 1
 * 
 */
    /* __pyx_t_4 allocated */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_kp___init__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_self);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self);
    __Pyx_GIVEREF(__pyx_v_self);
    /* __pyx_t_5 allocated */
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_4 released */
    /* __pyx_t_3 released */
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    /* __pyx_t_5 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":738
 *             self.buffer = None
 *             self.__init__(self)
 *             self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *             return
 */
    ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":740
 *             self.len_changed = 1
 * 
 *             return             # <<<<<<<<<<<<<<
 * 
 *         if size > self.c_length():
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":742
 *             return
 * 
 *         if size > self.c_length():             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (__pyx_v_size > ((struct __pyx_vtabstruct_6cpyamf_4util_BufferedByteStream *)((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->__pyx_vtab)->c_length(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)));
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":743
 * 
 *         if size > self.c_length():
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef char *buffer = NULL
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":745
 *             return
 * 
 *         cdef char *buffer = NULL             # <<<<<<<<<<<<<<
 *         cdef unsigned long cur_pos = <unsigned long>self.tell()
 * 
 */
  __pyx_v_buffer = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":746
 * 
 *         cdef char *buffer = NULL
 *         cdef unsigned long cur_pos = <unsigned long>self.tell()             # <<<<<<<<<<<<<<
 * 
 *         self.seek(0)
 */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_tell); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  /* __pyx_t_6 allocated */
  __pyx_t_6 = PyInt_AsUnsignedLongMask(__pyx_t_3); if (unlikely((__pyx_t_6 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  __pyx_v_cur_pos = ((unsigned long)__pyx_t_6);
  /* __pyx_t_6 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":748
 *         cdef unsigned long cur_pos = <unsigned long>self.tell()
 * 
 *         self.seek(0)             # <<<<<<<<<<<<<<
 * 
 *         if StringIO_cread(self.buffer, &buffer, size) != size:
 */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_seek); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __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_5)); __pyx_t_5 = 0;
  /* __pyx_t_3 released */
  /* __pyx_t_5 released */
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":750
 *         self.seek(0)
 * 
 *         if StringIO_cread(self.buffer, &buffer, size) != size:             # <<<<<<<<<<<<<<
 *             raise RuntimeError
 * 
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buffer), __pyx_v_size) != __pyx_v_size);
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":751
 * 
 *         if StringIO_cread(self.buffer, &buffer, size) != size:
 *             raise RuntimeError             # <<<<<<<<<<<<<<
 * 
 *         buf = StringIO_NewOutput(128)
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":753
 *             raise RuntimeError
 * 
 *         buf = StringIO_NewOutput(128)             # <<<<<<<<<<<<<<
 *         StringIO_cwrite(buf, buffer, size)
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PycStringIO->NewOutput(128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_v_buf);
  __pyx_v_buf = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":754
 * 
 *         buf = StringIO_NewOutput(128)
 *         StringIO_cwrite(buf, buffer, size)             # <<<<<<<<<<<<<<
 * 
 *         buf.seek(cur_pos)
 */
  PycStringIO->cwrite(__pyx_v_buf, __pyx_v_buffer, __pyx_v_size);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":756
 *         StringIO_cwrite(buf, buffer, size)
 * 
 *         buf.seek(cur_pos)             # <<<<<<<<<<<<<<
 * 
 *         self.buffer = buf
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_cur_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_3 released */
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":758
 *         buf.seek(cur_pos)
 * 
 *         self.buffer = buf             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  __Pyx_INCREF(__pyx_v_buf);
  __Pyx_GIVEREF(__pyx_v_buf);
  __Pyx_GOTREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  __Pyx_DECREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer = __pyx_v_buf;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":759
 * 
 *         self.buffer = buf
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def __add__(self, other):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":761
 *         self.len_changed = 1
 * 
 *     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":762
 * 
 *     def __add__(self, other):
 *         cdef long old_pos = <long>self.tell()             # <<<<<<<<<<<<<<
 *         cdef long old_other_pos = <long>other.tell()
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_tell); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  /* __pyx_t_2 allocated */
  __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 = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /* __pyx_t_1 released */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = __pyx_PyInt_long(__pyx_t_2); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */
  __pyx_v_old_pos = ((long)__pyx_t_3);
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":763
 *     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 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_tell); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_1 allocated */
  __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 = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */
  /* __pyx_t_3 allocated */
  __pyx_t_3 = __pyx_PyInt_long(__pyx_t_1); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /* __pyx_t_1 released */
  __pyx_v_old_other_pos = ((long)__pyx_t_3);
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":765
 *         cdef long old_other_pos = <long>other.tell()
 * 
 *         new = BufferedByteStream(self)             # <<<<<<<<<<<<<<
 * 
 *         other.seek(0)
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __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 allocated */
  __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 = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  /* __pyx_t_1 released */
  __Pyx_DECREF(__pyx_v_new);
  __pyx_v_new = __pyx_t_2;
  __pyx_t_2 = 0;
  /* __pyx_t_2 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":767
 *         new = BufferedByteStream(self)
 * 
 *         other.seek(0)             # <<<<<<<<<<<<<<
 *         new.seek(0, 2)
 *         new.write(other.read())
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __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 allocated */
  __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 = 767; __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_t_2 released */
  /* __pyx_t_1 released */
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":768
 * 
 *         other.seek(0)
 *         new.seek(0, 2)             # <<<<<<<<<<<<<<
 *         new.write(other.read())
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __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 allocated */
  __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 = 768; __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_t_4 released */
  /* __pyx_t_1 released */
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":769
 *         other.seek(0)
 *         new.seek(0, 2)
 *         new.write(other.read())             # <<<<<<<<<<<<<<
 * 
 *         self.seek(old_pos)
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  /* __pyx_t_4 allocated */
  __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 = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /* __pyx_t_1 released */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __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 released */
  /* __pyx_t_4 allocated */
  __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 = 769; __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_t_2 released */
  /* __pyx_t_1 released */
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":771
 *         new.write(other.read())
 * 
 *         self.seek(old_pos)             # <<<<<<<<<<<<<<
 *         other.seek(old_other_pos)
 *         new.seek(0)
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_old_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __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 released */
  /* __pyx_t_1 allocated */
  __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 = 771; __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_t_4 released */
  /* __pyx_t_2 released */
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /* __pyx_t_1 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":772
 * 
 *         self.seek(old_pos)
 *         other.seek(old_other_pos)             # <<<<<<<<<<<<<<
 *         new.seek(0)
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_other, __pyx_kp_seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyInt_FromLong(__pyx_v_old_other_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __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 released */
  /* __pyx_t_2 allocated */
  __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 = 772; __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_t_1 released */
  /* __pyx_t_4 released */
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  /* __pyx_t_2 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":773
 *         self.seek(old_pos)
 *         other.seek(old_other_pos)
 *         new.seek(0)             # <<<<<<<<<<<<<<
 * 
 *         return new
 */
  /* __pyx_t_2 allocated */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new, __pyx_kp_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __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 allocated */
  __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 = 773; __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_t_2 released */
  /* __pyx_t_4 released */
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /* __pyx_t_1 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":775
 *         new.seek(0)
 * 
 *         return new             # <<<<<<<<<<<<<<
 * 
 *     def close(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":777
 *         return new
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_close(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_close(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("close");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":778
 * 
 *     def close(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":779
 *     def close(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         self.buffer.close()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_76);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_76);
    __Pyx_GIVEREF(__pyx_kp_76);
    /* __pyx_t_4 allocated */
    __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 = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":781
 *             raise ValueError('buffer is closed')
 * 
 *         self.buffer.close()             # <<<<<<<<<<<<<<
 *         self.buffer = None
 *         self.length = 0
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_close); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":782
 * 
 *         self.buffer.close()
 *         self.buffer = None             # <<<<<<<<<<<<<<
 *         self.length = 0
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  __Pyx_DECREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer = Py_None;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":783
 *         self.buffer.close()
 *         self.buffer = None
 *         self.length = 0             # <<<<<<<<<<<<<<
 * 
 *     def flush(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->length = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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":785
 *         self.length = 0
 * 
 *     def flush(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

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;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("flush");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":786
 * 
 *     def flush(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":787
 *     def flush(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         self.buffer.flush()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_77);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_77);
    __Pyx_GIVEREF(__pyx_kp_77);
    /* __pyx_t_4 allocated */
    __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 = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":789
 *             raise ValueError('buffer is closed')
 * 
 *         self.buffer.flush()             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_flush); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /* __pyx_t_3 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":790
 * 
 *         self.buffer.flush()
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def readline(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":792
 *         self.len_changed = 1
 * 
 *     def readline(self):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_readline(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_readline(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("readline");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":793
 * 
 *     def readline(self):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":794
 *     def readline(self):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return self.buffer.readline()
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_78);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_78);
    __Pyx_GIVEREF(__pyx_kp_78);
    /* __pyx_t_4 allocated */
    __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 = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":796
 *             raise ValueError('buffer is closed')
 * 
 *         return self.buffer.readline()             # <<<<<<<<<<<<<<
 * 
 *     def readlines(self, sizehint=0):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_readline); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __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 = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  /* __pyx_t_4 released */
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  /* __pyx_t_3 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":798
 *         return self.buffer.readline()
 * 
 *     def readlines(self, sizehint=0):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_readlines(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_readlines(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sizehint = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_sizehint,0};
  __Pyx_SetupRefcountContext("readlines");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = __pyx_int_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_sizehint);
        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), "readlines") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_sizehint = values[0];
  } else {
    __pyx_v_sizehint = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_sizehint = 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("readlines", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.readlines");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":799
 * 
 *     def readlines(self, sizehint=0):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":800
 *     def readlines(self, sizehint=0):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         return self.buffer.readlines(sizehint)
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_79);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_79);
    __Pyx_GIVEREF(__pyx_kp_79);
    /* __pyx_t_4 allocated */
    __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 = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":802
 *             raise ValueError('buffer is closed')
 * 
 *         return self.buffer.readlines(sizehint)             # <<<<<<<<<<<<<<
 * 
 *     def writelines(self, iterable):
 */
  __Pyx_XDECREF(__pyx_r);
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_v_sizehint);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_sizehint);
  __Pyx_GIVEREF(__pyx_v_sizehint);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_3 released */
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  /* __pyx_t_5 released */
  goto __pyx_L0;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":804
 *         return self.buffer.readlines(sizehint)
 * 
 *     def writelines(self, iterable):             # <<<<<<<<<<<<<<
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')
 */

static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_writelines(PyObject *__pyx_v_self, PyObject *__pyx_v_iterable); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_writelines(PyObject *__pyx_v_self, PyObject *__pyx_v_iterable) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_SetupRefcountContext("writelines");

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":805
 * 
 *     def writelines(self, iterable):
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":806
 *     def writelines(self, iterable):
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         self.buffer.writelines(iterable)
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_80);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_80);
    __Pyx_GIVEREF(__pyx_kp_80);
    /* __pyx_t_4 allocated */
    __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 = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":808
 *             raise ValueError('buffer is closed')
 * 
 *         self.buffer.writelines(iterable)             # <<<<<<<<<<<<<<
 *         self.len_changed = 1
 * 
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_writelines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_v_iterable);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_iterable);
  __Pyx_GIVEREF(__pyx_v_iterable);
  /* __pyx_t_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_3 released */
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":809
 * 
 *         self.buffer.writelines(iterable)
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 *     def consume(self):
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

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

/* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":811
 *         self.len_changed = 1
 * 
 *     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\n        @since: 0.4\n        ";
static PyObject *__pyx_pf_6cpyamf_4util_18BufferedByteStream_consume(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_buf;
  unsigned int __pyx_v_chars_read;
  PyObject *__pyx_v_new_buffer;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_SetupRefcountContext("consume");
  __pyx_v_new_buffer = Py_None; __Pyx_INCREF(Py_None);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":818
 *         @since: 0.4
 *         """
 *         if not self.buffer:             # <<<<<<<<<<<<<<
 *             raise ValueError('buffer is closed')
 * 
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /* __pyx_t_2 allocated */
  __pyx_t_2 = (!__pyx_t_1);
  /* __pyx_t_1 released */
  if (__pyx_t_2) {
    /* __pyx_t_2 released */

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":819
 *         """
 *         if not self.buffer:
 *             raise ValueError('buffer is closed')             # <<<<<<<<<<<<<<
 * 
 *         # read the entire buffer
 */
    /* __pyx_t_3 allocated */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_81);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_81);
    __Pyx_GIVEREF(__pyx_kp_81);
    /* __pyx_t_4 allocated */
    __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 = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    /* __pyx_t_3 released */
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* __pyx_t_4 released */
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":822
 * 
 *         # read the entire buffer
 *         cdef char *buf = NULL             # <<<<<<<<<<<<<<
 *         cdef unsigned int chars_read = StringIO_cread(self.buffer, &buf, -1)
 * 
 */
  __pyx_v_buf = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":823
 *         # read the entire buffer
 *         cdef char *buf = NULL
 *         cdef unsigned int chars_read = StringIO_cread(self.buffer, &buf, -1)             # <<<<<<<<<<<<<<
 * 
 *         # quick truncate
 */
  __pyx_v_chars_read = PycStringIO->cread(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, (&__pyx_v_buf), -1);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":826
 * 
 *         # quick truncate
 *         new_buffer = StringIO_NewOutput(128)             # <<<<<<<<<<<<<<
 * 
 *         StringIO_cwrite(new_buffer, buf, chars_read)
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PycStringIO->NewOutput(128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_v_new_buffer);
  __pyx_v_new_buffer = __pyx_t_4;
  __pyx_t_4 = 0;
  /* __pyx_t_4 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":828
 *         new_buffer = StringIO_NewOutput(128)
 * 
 *         StringIO_cwrite(new_buffer, buf, chars_read)             # <<<<<<<<<<<<<<
 *         self.buffer = new_buffer
 *         self.buffer.seek(0)
 */
  PycStringIO->cwrite(__pyx_v_new_buffer, __pyx_v_buf, __pyx_v_chars_read);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":829
 * 
 *         StringIO_cwrite(new_buffer, buf, chars_read)
 *         self.buffer = new_buffer             # <<<<<<<<<<<<<<
 *         self.buffer.seek(0)
 * 
 */
  __Pyx_INCREF(__pyx_v_new_buffer);
  __Pyx_GIVEREF(__pyx_v_new_buffer);
  __Pyx_GOTREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  __Pyx_DECREF(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer);
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer = __pyx_v_new_buffer;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":830
 *         StringIO_cwrite(new_buffer, buf, chars_read)
 *         self.buffer = new_buffer
 *         self.buffer.seek(0)             # <<<<<<<<<<<<<<
 * 
 *         self.len_changed = 1
 */
  /* __pyx_t_4 allocated */
  __pyx_t_4 = PyObject_GetAttr(((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->buffer, __pyx_kp_seek); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  /* __pyx_t_3 allocated */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __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_5 allocated */
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  /* __pyx_t_4 released */
  /* __pyx_t_3 released */
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  /* __pyx_t_5 released */

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":832
 *         self.buffer.seek(0)
 * 
 *         self.len_changed = 1             # <<<<<<<<<<<<<<
 * 
 * # init module here:
 */
  ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)__pyx_v_self)->len_changed = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpyamf.util.BufferedByteStream.consume");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_new_buffer);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}
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 = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)o);
  p->__pyx_vtab = __pyx_vtabptr_6cpyamf_4util_BufferedByteStream;
  p->buffer = Py_None; Py_INCREF(Py_None);
  if (__pyx_pf_6cpyamf_4util_18BufferedByteStream___new__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_6cpyamf_4util_BufferedByteStream(PyObject *o) {
  struct __pyx_obj_6cpyamf_4util_BufferedByteStream *p = (struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)o;
  Py_XDECREF(p->buffer);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6cpyamf_4util_BufferedByteStream(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6cpyamf_4util_BufferedByteStream *p = (struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)o;
  if (p->buffer) {
    e = (*v)(p->buffer, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6cpyamf_4util_BufferedByteStream(PyObject *o) {
  struct __pyx_obj_6cpyamf_4util_BufferedByteStream *p = (struct __pyx_obj_6cpyamf_4util_BufferedByteStream *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->buffer);
  p->buffer = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

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("tell"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_tell, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("at_eof"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_at_eof, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("remaining"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_remaining, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("getvalue"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_getvalue, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_uchar"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_uchar, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_char"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_char, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_ushort"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ushort, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_short"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_short, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_ulong"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_ulong, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_long"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_long, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__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"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_uchar"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_uchar, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_char"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_char, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_ushort"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ushort, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_short"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_short, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_ulong"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_ulong, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_long"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_long, METH_O, __Pyx_DOCSTR(0)},
  {__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(0)},
  {__Pyx_NAMESTR("write_utf8_string"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_utf8_string, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_double"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_double, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_double"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_double, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("read_float"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_read_float, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write_float"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_write_float, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("peek"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_peek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("truncate"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_truncate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__add__"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream___add__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_close, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_flush, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("readline"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_readline, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("readlines"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_readlines, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("writelines"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_writelines, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("consume"), (PyCFunction)__pyx_pf_6cpyamf_4util_18BufferedByteStream_consume, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6cpyamf_4util_18BufferedByteStream_consume)},
  {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*/
  0, /*nb_long*/
  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_BufferedByteStream, /*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*/
  0, /*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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6cpyamf_4util_BufferedByteStream, /*tp_traverse*/
  __pyx_tp_clear_6cpyamf_4util_BufferedByteStream, /*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___cinit__, __pyx_k___cinit__, sizeof(__pyx_k___cinit__), 1, 1, 1},
  {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1},
  {&__pyx_kp_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 1, 1, 1},
  {&__pyx_kp_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 1, 1, 1},
  {&__pyx_kp_at_eof, __pyx_k_at_eof, sizeof(__pyx_k_at_eof), 1, 1, 1},
  {&__pyx_kp_remaining, __pyx_k_remaining, sizeof(__pyx_k_remaining), 1, 1, 1},
  {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1},
  {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 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, __pyx_k_write, sizeof(__pyx_k_write), 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___len__, __pyx_k___len__, sizeof(__pyx_k___len__), 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___add__, __pyx_k___add__, sizeof(__pyx_k___add__), 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_readline, __pyx_k_readline, sizeof(__pyx_k_readline), 1, 1, 1},
  {&__pyx_kp_readlines, __pyx_k_readlines, sizeof(__pyx_k_readlines), 1, 1, 1},
  {&__pyx_kp_writelines, __pyx_k_writelines, sizeof(__pyx_k_writelines), 1, 1, 1},
  {&__pyx_kp_consume, __pyx_k_consume, sizeof(__pyx_k_consume), 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_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_n, __pyx_k_n, sizeof(__pyx_k_n), 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_l, __pyx_k_l, sizeof(__pyx_k_l), 1, 1, 1},
  {&__pyx_kp_s, __pyx_k_s, sizeof(__pyx_k_s), 1, 1, 1},
  {&__pyx_kp_c, __pyx_k_c, sizeof(__pyx_k_c), 1, 1, 1},
  {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 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_sizehint, __pyx_k_sizehint, sizeof(__pyx_k_sizehint), 1, 1, 1},
  {&__pyx_kp_iterable, __pyx_k_iterable, sizeof(__pyx_k_iterable), 1, 1, 1},
  {&__pyx_kp_fpconst, __pyx_k_fpconst, sizeof(__pyx_k_fpconst), 1, 1, 1},
  {&__pyx_kp_basestring, __pyx_k_basestring, sizeof(__pyx_k_basestring), 1, 1, 1},
  {&__pyx_kp_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 1, 0},
  {&__pyx_kp_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 1, 0},
  {&__pyx_kp_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 1, 0},
  {&__pyx_kp_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 1, 0},
  {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 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_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 1, 1, 1},
  {&__pyx_kp_EOFError, __pyx_k_EOFError, sizeof(__pyx_k_EOFError), 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_isNaN, __pyx_k_isNaN, sizeof(__pyx_k_isNaN), 1, 1, 1},
  {&__pyx_kp_isNegInf, __pyx_k_isNegInf, sizeof(__pyx_k_isNegInf), 1, 1, 1},
  {&__pyx_kp_isPosInf, __pyx_k_isPosInf, sizeof(__pyx_k_isPosInf), 1, 1, 1},
  {&__pyx_kp_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 1, 1, 1},
  {&__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_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 0},
  {&__pyx_kp_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 0},
  {&__pyx_kp_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 0},
  {&__pyx_kp_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 0},
  {&__pyx_kp_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 0},
  {&__pyx_kp_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 0},
  {&__pyx_kp_33, __pyx_k_33, sizeof(__pyx_k_33), 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},
  {&__pyx_kp_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 0},
  {&__pyx_kp_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 0},
  {&__pyx_kp_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 0},
  {&__pyx_kp_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 0},
  {&__pyx_kp_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 0},
  {&__pyx_kp_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 0},
  {&__pyx_kp_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 0},
  {&__pyx_kp_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 0},
  {&__pyx_kp_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 0},
  {&__pyx_kp_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 0},
  {&__pyx_kp_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 0},
  {&__pyx_kp_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 0},
  {&__pyx_kp_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 0},
  {&__pyx_kp_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 0},
  {&__pyx_kp_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 0},
  {&__pyx_kp_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 0},
  {&__pyx_kp_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 0},
  {&__pyx_kp_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 0},
  {&__pyx_kp_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 0},
  {&__pyx_kp_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 0},
  {&__pyx_kp_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 0},
  {&__pyx_kp_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 0},
  {&__pyx_kp_73, __pyx_k_73, sizeof(__pyx_k_73), 0, 0, 0},
  {&__pyx_kp_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 0},
  {&__pyx_kp_75, __pyx_k_75, sizeof(__pyx_k_75), 0, 0, 0},
  {&__pyx_kp_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 0},
  {&__pyx_kp_77, __pyx_k_77, sizeof(__pyx_k_77), 0, 0, 0},
  {&__pyx_kp_78, __pyx_k_78, sizeof(__pyx_k_78), 0, 0, 0},
  {&__pyx_kp_79, __pyx_k_79, sizeof(__pyx_k_79), 0, 0, 0},
  {&__pyx_kp_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 0, 0},
  {&__pyx_kp_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 0},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_basestring = __Pyx_GetName(__pyx_b, __pyx_kp_basestring); if (!__pyx_builtin_basestring) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __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 = 162; __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 = 172; __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 = 245; __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 = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_EOFError = __Pyx_GetName(__pyx_b, __pyx_kp_EOFError); if (!__pyx_builtin_EOFError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_kp_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __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_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__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_neg_2147483648 = PyInt_FromLong(-2147483648); if (unlikely(!__pyx_int_neg_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2147483647 = PyInt_FromLong(2147483647); if (unlikely(!__pyx_int_2147483647)) {__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
{
  PyObject *__pyx_1 = 0;
  #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();
  /*--- 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;};
  /*--- 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 ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_6cpyamf_4util_BufferedByteStream = &__pyx_vtable_6cpyamf_4util_BufferedByteStream;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.c_length = (long (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_length;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.unpack_int = (long (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, char *, long))__pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_int;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.unpack_uint = (unsigned long (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, char *, long))__pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_uint;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.pack_int = (void (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, long, long))__pyx_f_6cpyamf_4util_18BufferedByteStream_pack_int;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.pack_uint = (void (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *, unsigned long, long))__pyx_f_6cpyamf_4util_18BufferedByteStream_pack_uint;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.c_at_eof = (int (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_at_eof;
  __pyx_vtable_6cpyamf_4util_BufferedByteStream.c_remaining = (long (*)(struct __pyx_obj_6cpyamf_4util_BufferedByteStream *))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_remaining;
  #else
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.c_length = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_length;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.unpack_int = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.unpack_uint = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_unpack_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.pack_int = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_pack_int;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.pack_uint = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_pack_uint;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.c_at_eof = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_at_eof;
  *(void(**)(void))&__pyx_vtable_6cpyamf_4util_BufferedByteStream.c_remaining = (void(*)(void))__pyx_f_6cpyamf_4util_18BufferedByteStream_c_remaining;
  #endif
  if (PyType_Ready(&__pyx_type_6cpyamf_4util_BufferedByteStream) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __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 = 122; __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 = 122; __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":53
 *     object StringIO_cgetvalue "PycStringIO->cgetvalue" (obj)
 * 
 * import fpconst             # <<<<<<<<<<<<<<
 * 
 * # module constant declarations
 */
  __pyx_1 = __Pyx_Import(__pyx_kp_fpconst, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_fpconst, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":63
 * # forward declarations for module
 * cdef char SYSTEM_ENDIAN
 * cdef int float_broken = -1             # <<<<<<<<<<<<<<
 * 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'
 */
  __pyx_v_6cpyamf_4util_float_broken = -1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":64
 * cdef char SYSTEM_ENDIAN
 * cdef int float_broken = -1
 * 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":65
 * cdef int float_broken = -1
 * 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":66
 * 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 inline char _get_native_endian():
 */
  __pyx_v_6cpyamf_4util_PosInf = ((unsigned char *)__pyx_k_11);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":835
 * 
 * # init module here:
 * PycString_IMPORT             # <<<<<<<<<<<<<<
 * 
 * SYSTEM_ENDIAN = _get_native_endian()
 */
  PycString_IMPORT;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":837
 * PycString_IMPORT
 * 
 * SYSTEM_ENDIAN = _get_native_endian()             # <<<<<<<<<<<<<<
 * float_broken = is_broken_float()
 */
  __pyx_v_6cpyamf_4util_SYSTEM_ENDIAN = __pyx_f_6cpyamf_4util__get_native_endian();

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/util.pyx":838
 * 
 * SYSTEM_ENDIAN = _get_native_endian()
 * float_broken = is_broken_float()             # <<<<<<<<<<<<<<
 */
  __pyx_v_6cpyamf_4util_float_broken = __pyx_f_6cpyamf_4util_is_broken_float();

  /* "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/Cython-0.11-py2.5-macosx-10.3-i386.egg/Cython/Includes/python_object.pxd":1
 * cdef extern from "Python.h":             # <<<<<<<<<<<<<<
 *     ctypedef void PyObject
 *     ctypedef void PyTypeObject
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __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;
}

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 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 INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
     while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
     return *s1 == *s2;
}

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 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* b) {
   unsigned PY_LONG_LONG val = __pyx_PyInt_AsUnsignedLongLong(b);
   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 val;
}

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 PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (PyInt_CheckExact(x)) {
        return PyInt_AS_LONG(x);
    }
    else
#endif
    if (PyLong_CheckExact(x)) {
        return PyLong_AsLongLong(x);
    }
    else {
        PY_LONG_LONG val;
#if PY_VERSION_HEX < 0x03000000
        PyObject* tmp = PyNumber_Int(x);  if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsLongLong(tmp);
#else
        PyObject* tmp = PyNumber_Long(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = PyLong_AsLongLong(tmp);
#endif
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (PyInt_CheckExact(x)) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long long");
            return (unsigned PY_LONG_LONG)-1;
        }
        return val;
    }
    else
#endif
    if (PyLong_CheckExact(x)) {
        return PyLong_AsUnsignedLongLong(x);
    }
    else {
        unsigned PY_LONG_LONG val;
#if PY_VERSION_HEX < 0x03000000
        PyObject* tmp = PyNumber_Int(x);  if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsUnsignedLongLong(tmp);
#else
        PyObject* tmp = PyNumber_Long(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = PyLong_AsUnsignedLongLong(tmp);
#endif
        Py_DECREF(tmp);
        return val;
    }
}


static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x) {
    if (sizeof(unsigned char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        unsigned char val = (unsigned char)long_val;
        if (unlikely((val != long_val)  || (long_val < 0))) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned char");
            return (unsigned char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x) {
    if (sizeof(unsigned short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        unsigned short val = (unsigned short)long_val;
        if (unlikely((val != long_val)  || (long_val < 0))) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned short");
            return (unsigned short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE char __pyx_PyInt_char(PyObject* x) {
    if (sizeof(char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        char val = (char)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to char");
            return (char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE short __pyx_PyInt_short(PyObject* x) {
    if (sizeof(short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        short val = (short)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to short");
            return (short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE int __pyx_PyInt_int(PyObject* x) {
    if (sizeof(int) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        int val = (int)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to int");
            return (int)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE long __pyx_PyInt_long(PyObject* x) {
    if (sizeof(long) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        long val = (long)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to long");
            return (long)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed char __pyx_PyInt_signed_char(PyObject* x) {
    if (sizeof(signed char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed char val = (signed char)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed char");
            return (signed char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed short __pyx_PyInt_signed_short(PyObject* x) {
    if (sizeof(signed short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed short val = (signed short)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed short");
            return (signed short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed int __pyx_PyInt_signed_int(PyObject* x) {
    if (sizeof(signed int) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed int val = (signed int)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed int");
            return (signed int)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed long __pyx_PyInt_signed_long(PyObject* x) {
    if (sizeof(signed long) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed long val = (signed long)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed long");
            return (signed long)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE long double __pyx_PyInt_long_double(PyObject* x) {
    if (sizeof(long double) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        long double val = (long double)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to long double");
            return (long double)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

