/* Generated by Cython 0.10.3 on Tue Feb 10 10:33:14 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
#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_LOCK 0x0002
  #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 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
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__cpyamf__amf3


#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_AsString   PyString_AsString
#else
#define __Pyx_PyBytes_FromString PyBytes_FromString
#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);
static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b);

#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";

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

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 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_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 void __Pyx_WriteUnraisable(const char *name); /*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/amf3.pyx":68
 *     return size
 * 
 * cdef long _decode_int(object stream, int sign=0):             # <<<<<<<<<<<<<<
 *     cdef int n = 0
 *     cdef long result = 0
 */

struct __pyx_opt_args_6cpyamf_4amf3__decode_int {
  int __pyx_n;
  int sign;
};
/* Module declarations from cpyamf.amf3 */

static PyObject *__pyx_k_1;
static Py_ssize_t __pyx_f_6cpyamf_4amf3__encode_int(long, char **); /*proto*/
static long __pyx_f_6cpyamf_4amf3__decode_int(PyObject *, struct __pyx_opt_args_6cpyamf_4amf3__decode_int *__pyx_optional_args); /*proto*/


/* Implementation of cpyamf.amf3 */
static char __pyx_k_n[] = "n";
static PyObject *__pyx_kp_n;
static char __pyx_k_stream[] = "stream";
static PyObject *__pyx_kp_stream;
static char __pyx_k_sign[] = "sign";
static PyObject *__pyx_kp_sign;
static char __pyx_k_read_uchar[] = "read_uchar";
static PyObject *__pyx_kp_read_uchar;
static char __pyx_k_OverflowError[] = "OverflowError";
static PyObject *__pyx_kp_OverflowError;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_kp_2;
static char __pyx_k_2[] = "Out of range";

/* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":17
 *     object PyInt_FromLong(long v)
 * 
 * cdef Py_ssize_t _encode_int(long n, char **buf):             # <<<<<<<<<<<<<<
 *     if n < 0:
 *         n += 0x20000000
 */

static  Py_ssize_t __pyx_f_6cpyamf_4amf3__encode_int(long __pyx_v_n, char **__pyx_v_buf) {
  Py_ssize_t __pyx_v_size;
  long __pyx_v_real_value;
  char __pyx_v_changed;
  unsigned char __pyx_v_count;
  char *__pyx_v_bytes;
  Py_ssize_t __pyx_r;
  int __pyx_1;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":18
 * 
 * cdef Py_ssize_t _encode_int(long n, char **buf):
 *     if n < 0:             # <<<<<<<<<<<<<<
 *         n += 0x20000000
 * 
 */
  __pyx_1 = (__pyx_v_n < 0);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":19
 * cdef Py_ssize_t _encode_int(long n, char **buf):
 *     if n < 0:
 *         n += 0x20000000             # <<<<<<<<<<<<<<
 * 
 *     cdef Py_ssize_t size = 0
 */
    __pyx_v_n += 0x20000000;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":21
 *         n += 0x20000000
 * 
 *     cdef Py_ssize_t size = 0             # <<<<<<<<<<<<<<
 *     cdef long real_value = n
 *     cdef char changed = 0
 */
  __pyx_v_size = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":22
 * 
 *     cdef Py_ssize_t size = 0
 *     cdef long real_value = n             # <<<<<<<<<<<<<<
 *     cdef char changed = 0
 *     cdef unsigned char count = 0
 */
  __pyx_v_real_value = __pyx_v_n;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":23
 *     cdef Py_ssize_t size = 0
 *     cdef long real_value = n
 *     cdef char changed = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned char count = 0
 *     cdef char *bytes = NULL
 */
  __pyx_v_changed = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":24
 *     cdef long real_value = n
 *     cdef char changed = 0
 *     cdef unsigned char count = 0             # <<<<<<<<<<<<<<
 *     cdef char *bytes = NULL
 * 
 */
  __pyx_v_count = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":25
 *     cdef char changed = 0
 *     cdef unsigned char count = 0
 *     cdef char *bytes = NULL             # <<<<<<<<<<<<<<
 * 
 *     if n > 0x1fffff:
 */
  __pyx_v_bytes = NULL;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":27
 *     cdef char *bytes = NULL
 * 
 *     if n > 0x1fffff:             # <<<<<<<<<<<<<<
 *         size = 4
 *         bytes = <char *>PyMem_Malloc(size)
 */
  __pyx_1 = (__pyx_v_n > 0x1fffff);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":28
 * 
 *     if n > 0x1fffff:
 *         size = 4             # <<<<<<<<<<<<<<
 *         bytes = <char *>PyMem_Malloc(size)
 *         changed = 1
 */
    __pyx_v_size = 4;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":29
 *     if n > 0x1fffff:
 *         size = 4
 *         bytes = <char *>PyMem_Malloc(size)             # <<<<<<<<<<<<<<
 *         changed = 1
 *         n = n >> 1
 */
    __pyx_v_bytes = ((char *)PyMem_Malloc(__pyx_v_size));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":30
 *         size = 4
 *         bytes = <char *>PyMem_Malloc(size)
 *         changed = 1             # <<<<<<<<<<<<<<
 *         n = n >> 1
 *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
 */
    __pyx_v_changed = 1;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":31
 *         bytes = <char *>PyMem_Malloc(size)
 *         changed = 1
 *         n = n >> 1             # <<<<<<<<<<<<<<
 *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
 *         count += 1
 */
    __pyx_v_n = (__pyx_v_n >> 1);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":32
 *         changed = 1
 *         n = n >> 1
 *         bytes[count] = 0x80 | ((n >> 21) & 0xff)             # <<<<<<<<<<<<<<
 *         count += 1
 * 
 */
    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 21) & 0xff));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":33
 *         n = n >> 1
 *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
 *         count += 1             # <<<<<<<<<<<<<<
 * 
 *     if n > 0x3fff:
 */
    __pyx_v_count += 1;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":35
 *         count += 1
 * 
 *     if n > 0x3fff:             # <<<<<<<<<<<<<<
 *         if size == 0:
 *             size = 3
 */
  __pyx_1 = (__pyx_v_n > 0x3fff);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":36
 * 
 *     if n > 0x3fff:
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             size = 3
 *             bytes = <char *>PyMem_Malloc(size)
 */
    __pyx_1 = (__pyx_v_size == 0);
    if (__pyx_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":37
 *     if n > 0x3fff:
 *         if size == 0:
 *             size = 3             # <<<<<<<<<<<<<<
 *             bytes = <char *>PyMem_Malloc(size)
 * 
 */
      __pyx_v_size = 3;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":38
 *         if size == 0:
 *             size = 3
 *             bytes = <char *>PyMem_Malloc(size)             # <<<<<<<<<<<<<<
 * 
 *         bytes[count] = 0x80 | ((n >> 14) & 0xff)
 */
      __pyx_v_bytes = ((char *)PyMem_Malloc(__pyx_v_size));
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":40
 *             bytes = <char *>PyMem_Malloc(size)
 * 
 *         bytes[count] = 0x80 | ((n >> 14) & 0xff)             # <<<<<<<<<<<<<<
 *         count += 1
 * 
 */
    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 14) & 0xff));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":41
 * 
 *         bytes[count] = 0x80 | ((n >> 14) & 0xff)
 *         count += 1             # <<<<<<<<<<<<<<
 * 
 *     if n > 0x7f:
 */
    __pyx_v_count += 1;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":43
 *         count += 1
 * 
 *     if n > 0x7f:             # <<<<<<<<<<<<<<
 *         if size == 0:
 *             size = 2
 */
  __pyx_1 = (__pyx_v_n > 0x7f);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":44
 * 
 *     if n > 0x7f:
 *         if size == 0:             # <<<<<<<<<<<<<<
 *             size = 2
 *             bytes = <char *>PyMem_Malloc(size)
 */
    __pyx_1 = (__pyx_v_size == 0);
    if (__pyx_1) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":45
 *     if n > 0x7f:
 *         if size == 0:
 *             size = 2             # <<<<<<<<<<<<<<
 *             bytes = <char *>PyMem_Malloc(size)
 * 
 */
      __pyx_v_size = 2;

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":46
 *         if size == 0:
 *             size = 2
 *             bytes = <char *>PyMem_Malloc(size)             # <<<<<<<<<<<<<<
 * 
 *         bytes[count] = 0x80 | ((n >> 7) & 0xff)
 */
      __pyx_v_bytes = ((char *)PyMem_Malloc(__pyx_v_size));
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":48
 *             bytes = <char *>PyMem_Malloc(size)
 * 
 *         bytes[count] = 0x80 | ((n >> 7) & 0xff)             # <<<<<<<<<<<<<<
 *         count += 1
 * 
 */
    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 7) & 0xff));

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":49
 * 
 *         bytes[count] = 0x80 | ((n >> 7) & 0xff)
 *         count += 1             # <<<<<<<<<<<<<<
 * 
 *     if changed == 1:
 */
    __pyx_v_count += 1;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":51
 *         count += 1
 * 
 *     if changed == 1:             # <<<<<<<<<<<<<<
 *         n = real_value
 * 
 */
  __pyx_1 = (__pyx_v_changed == 1);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":52
 * 
 *     if changed == 1:
 *         n = real_value             # <<<<<<<<<<<<<<
 * 
 *     if size == 0:
 */
    __pyx_v_n = __pyx_v_real_value;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":54
 *         n = real_value
 * 
 *     if size == 0:             # <<<<<<<<<<<<<<
 *         size = 1
 * 
 */
  __pyx_1 = (__pyx_v_size == 0);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":55
 * 
 *     if size == 0:
 *         size = 1             # <<<<<<<<<<<<<<
 * 
 *         bytes = <char *>PyMem_Malloc(size)
 */
    __pyx_v_size = 1;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":57
 *         size = 1
 * 
 *         bytes = <char *>PyMem_Malloc(size)             # <<<<<<<<<<<<<<
 * 
 *     if n > 0x1fffff:
 */
    __pyx_v_bytes = ((char *)PyMem_Malloc(__pyx_v_size));
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":59
 *         bytes = <char *>PyMem_Malloc(size)
 * 
 *     if n > 0x1fffff:             # <<<<<<<<<<<<<<
 *         bytes[count] = n & 0xff
 *     else:
 */
  __pyx_1 = (__pyx_v_n > 0x1fffff);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":60
 * 
 *     if n > 0x1fffff:
 *         bytes[count] = n & 0xff             # <<<<<<<<<<<<<<
 *     else:
 *         bytes[count] = n & 0x7f
 */
    (__pyx_v_bytes[__pyx_v_count]) = (__pyx_v_n & 0xff);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":62
 *         bytes[count] = n & 0xff
 *     else:
 *         bytes[count] = n & 0x7f             # <<<<<<<<<<<<<<
 * 
 *     buf[0] = bytes
 */
    (__pyx_v_bytes[__pyx_v_count]) = (__pyx_v_n & 0x7f);
  }
  __pyx_L11:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":64
 *         bytes[count] = n & 0x7f
 * 
 *     buf[0] = bytes             # <<<<<<<<<<<<<<
 * 
 *     return size
 */
  (__pyx_v_buf[0]) = __pyx_v_bytes;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":66
 *     buf[0] = bytes
 * 
 *     return size             # <<<<<<<<<<<<<<
 * 
 * cdef long _decode_int(object stream, int sign=0):
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":68
 *     return size
 * 
 * cdef long _decode_int(object stream, int sign=0):             # <<<<<<<<<<<<<<
 *     cdef int n = 0
 *     cdef long result = 0
 */

static  long __pyx_f_6cpyamf_4amf3__decode_int(PyObject *__pyx_v_stream, struct __pyx_opt_args_6cpyamf_4amf3__decode_int *__pyx_optional_args) {
  int __pyx_v_sign = 0;
  int __pyx_v_n;
  long __pyx_v_result;
  unsigned char __pyx_v_b;
  long __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  unsigned char __pyx_3;
  int __pyx_4;
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_sign = __pyx_optional_args->sign;
    }
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":69
 * 
 * cdef long _decode_int(object stream, int sign=0):
 *     cdef int n = 0             # <<<<<<<<<<<<<<
 *     cdef long result = 0
 *     cdef unsigned char b = <unsigned char>stream.read_uchar()
 */
  __pyx_v_n = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":70
 * cdef long _decode_int(object stream, int sign=0):
 *     cdef int n = 0
 *     cdef long result = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned char b = <unsigned char>stream.read_uchar()
 * 
 */
  __pyx_v_result = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":71
 *     cdef int n = 0
 *     cdef long result = 0
 *     cdef unsigned char b = <unsigned char>stream.read_uchar()             # <<<<<<<<<<<<<<
 * 
 *     while b & 0x80 != 0 and n < 3:
 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read_uchar); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = __pyx_PyInt_unsigned_char(__pyx_2); if (unlikely((__pyx_3 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_v_b = ((unsigned char)__pyx_3);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":73
 *     cdef unsigned char b = <unsigned char>stream.read_uchar()
 * 
 *     while b & 0x80 != 0 and n < 3:             # <<<<<<<<<<<<<<
 *         result <<= 7
 *         result |= b & 0x7f
 */
  while (1) {
    __pyx_4 = ((__pyx_v_b & 0x80) != 0);
    if (__pyx_4) {
      __pyx_4 = (__pyx_v_n < 3);
    }
    if (!__pyx_4) break;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":74
 * 
 *     while b & 0x80 != 0 and n < 3:
 *         result <<= 7             # <<<<<<<<<<<<<<
 *         result |= b & 0x7f
 *         b = <unsigned char>stream.read_uchar()
 */
    __pyx_v_result <<= 7;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":75
 *     while b & 0x80 != 0 and n < 3:
 *         result <<= 7
 *         result |= b & 0x7f             # <<<<<<<<<<<<<<
 *         b = <unsigned char>stream.read_uchar()
 *         n += 1
 */
    __pyx_v_result |= (__pyx_v_b & 0x7f);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":76
 *         result <<= 7
 *         result |= b & 0x7f
 *         b = <unsigned char>stream.read_uchar()             # <<<<<<<<<<<<<<
 *         n += 1
 * 
 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read_uchar); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_3 = __pyx_PyInt_unsigned_char(__pyx_2); if (unlikely((__pyx_3 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_v_b = ((unsigned char)__pyx_3);

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":77
 *         result |= b & 0x7f
 *         b = <unsigned char>stream.read_uchar()
 *         n += 1             # <<<<<<<<<<<<<<
 * 
 *     if n < 3:
 */
    __pyx_v_n += 1;
  }

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":79
 *         n += 1
 * 
 *     if n < 3:             # <<<<<<<<<<<<<<
 *         result <<= 7
 *         result |= b
 */
  __pyx_4 = (__pyx_v_n < 3);
  if (__pyx_4) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":80
 * 
 *     if n < 3:
 *         result <<= 7             # <<<<<<<<<<<<<<
 *         result |= b
 *     else:
 */
    __pyx_v_result <<= 7;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":81
 *     if n < 3:
 *         result <<= 7
 *         result |= b             # <<<<<<<<<<<<<<
 *     else:
 *         result <<= 8
 */
    __pyx_v_result |= __pyx_v_b;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":83
 *         result |= b
 *     else:
 *         result <<= 8             # <<<<<<<<<<<<<<
 *         result |= b
 * 
 */
    __pyx_v_result <<= 8;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":84
 *     else:
 *         result <<= 8
 *         result |= b             # <<<<<<<<<<<<<<
 * 
 *         if result & 0x10000000 != 0:
 */
    __pyx_v_result |= __pyx_v_b;

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":86
 *         result |= b
 * 
 *         if result & 0x10000000 != 0:             # <<<<<<<<<<<<<<
 *             if sign == 1:
 *                 result -= 0x20000000
 */
    __pyx_4 = ((__pyx_v_result & 0x10000000) != 0);
    if (__pyx_4) {

      /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":87
 * 
 *         if result & 0x10000000 != 0:
 *             if sign == 1:             # <<<<<<<<<<<<<<
 *                 result -= 0x20000000
 *             else:
 */
      __pyx_4 = (__pyx_v_sign == 1);
      if (__pyx_4) {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":88
 *         if result & 0x10000000 != 0:
 *             if sign == 1:
 *                 result -= 0x20000000             # <<<<<<<<<<<<<<
 *             else:
 *                 result <<= 1
 */
        __pyx_v_result -= 0x20000000;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":90
 *                 result -= 0x20000000
 *             else:
 *                 result <<= 1             # <<<<<<<<<<<<<<
 *                 result += 1
 * 
 */
        __pyx_v_result <<= 1;

        /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":91
 *             else:
 *                 result <<= 1
 *                 result += 1             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
        __pyx_v_result += 1;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":93
 *                 result += 1
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * def encode_int(long n):
 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_WriteUnraisable("cpyamf.amf3._decode_int");
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":95
 *     return result
 * 
 * def encode_int(long n):             # <<<<<<<<<<<<<<
 *     if n >= 0x40000000:
 *         raise OverflowError("Out of range")
 */

static PyObject *__pyx_pf_6cpyamf_4amf3_encode_int(PyObject *__pyx_self, PyObject *__pyx_arg_n); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4amf3_encode_int(PyObject *__pyx_self, PyObject *__pyx_arg_n) {
  long __pyx_v_n;
  char *__pyx_v_buf;
  Py_ssize_t __pyx_v_size;
  PyObject *__pyx_v_o = 0;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  __pyx_self = __pyx_self;
  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 = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.amf3.encode_int");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":96
 * 
 * def encode_int(long n):
 *     if n >= 0x40000000:             # <<<<<<<<<<<<<<
 *         raise OverflowError("Out of range")
 * 
 */
  __pyx_1 = (__pyx_v_n >= 0x40000000);
  if (__pyx_1) {

    /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":97
 * def encode_int(long n):
 *     if n >= 0x40000000:
 *         raise OverflowError("Out of range")             # <<<<<<<<<<<<<<
 * 
 *     cdef char *buf
 */
    __pyx_2 = PyTuple_New(1); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    Py_INCREF(__pyx_kp_2);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_kp_2);
    __pyx_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_2), NULL); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    Py_DECREF(((PyObject *)__pyx_2)); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":100
 * 
 *     cdef char *buf
 *     cdef Py_ssize_t size = _encode_int(n, &buf)             # <<<<<<<<<<<<<<
 *     cdef object o = PyString_FromStringAndSize(buf, size)
 * 
 */
  __pyx_v_size = __pyx_f_6cpyamf_4amf3__encode_int(__pyx_v_n, (&__pyx_v_buf));

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":101
 *     cdef char *buf
 *     cdef Py_ssize_t size = _encode_int(n, &buf)
 *     cdef object o = PyString_FromStringAndSize(buf, size)             # <<<<<<<<<<<<<<
 * 
 *     PyMem_Free(buf)
 */
  __pyx_2 = PyString_FromStringAndSize(__pyx_v_buf, __pyx_v_size); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_o = __pyx_2;
  __pyx_2 = 0;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":103
 *     cdef object o = PyString_FromStringAndSize(buf, size)
 * 
 *     PyMem_Free(buf)             # <<<<<<<<<<<<<<
 * 
 *     return o
 */
  PyMem_Free(__pyx_v_buf);

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":105
 *     PyMem_Free(buf)
 * 
 *     return o             # <<<<<<<<<<<<<<
 * 
 * def decode_int(stream, sign=False):
 */
  Py_INCREF(__pyx_v_o);
  __pyx_r = __pyx_v_o;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("cpyamf.amf3.encode_int");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_XDECREF(__pyx_v_o);
  return __pyx_r;
}

/* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":107
 *     return o
 * 
 * def decode_int(stream, sign=False):             # <<<<<<<<<<<<<<
 *     return PyInt_FromLong(_decode_int(stream, <int>sign))
 */

static PyObject *__pyx_pf_6cpyamf_4amf3_decode_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6cpyamf_4amf3_decode_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_stream = 0;
  PyObject *__pyx_v_sign = 0;
  PyObject *__pyx_r;
  struct __pyx_opt_args_6cpyamf_4amf3__decode_int __pyx_1;
  int __pyx_2;
  long __pyx_3;
  PyObject *__pyx_4 = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_stream,&__pyx_kp_sign,0};
  __pyx_self = __pyx_self;
  __pyx_v_sign = __pyx_k_1;
  if (unlikely(__pyx_kwds)) {
    PyObject* values[2] = {0,0};
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    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_stream);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "decode_int") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_stream = values[0];
    if (values[1]) {
      __pyx_v_sign = values[1];
    }
  } else {
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_sign = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("decode_int", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpyamf.amf3.decode_int");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":108
 * 
 * def decode_int(stream, sign=False):
 *     return PyInt_FromLong(_decode_int(stream, <int>sign))             # <<<<<<<<<<<<<<
 */
  __pyx_2 = __pyx_PyInt_int(__pyx_v_sign); if (unlikely((__pyx_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_1.__pyx_n = 1;
  __pyx_1.sign = ((int)__pyx_2);
  __pyx_3 = __pyx_f_6cpyamf_4amf3__decode_int(__pyx_v_stream, &__pyx_1); 
  __pyx_4 = PyInt_FromLong(__pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_4;
  __pyx_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("cpyamf.amf3.decode_int");
  __pyx_r = NULL;
  __pyx_L0:;
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {"encode_int", (PyCFunction)__pyx_pf_6cpyamf_4amf3_encode_int, METH_O, 0},
  {"decode_int", (PyCFunction)__pyx_pf_6cpyamf_4amf3_decode_int, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "amf3",
    __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_n, __pyx_k_n, sizeof(__pyx_k_n), 1, 1, 1},
  {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1},
  {&__pyx_kp_sign, __pyx_k_sign, sizeof(__pyx_k_sign), 1, 1, 1},
  {&__pyx_kp_read_uchar, __pyx_k_read_uchar, sizeof(__pyx_k_read_uchar), 1, 1, 1},
  {&__pyx_kp_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 1, 1, 1},
  {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 0},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_kp_OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  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 initamf3(void); /*proto*/
PyMODINIT_FUNC initamf3(void)
#else
PyMODINIT_FUNC PyInit_amf3(void); /*proto*/
PyMODINIT_FUNC PyInit_amf3(void)
#endif
{
  PyObject *__pyx_1 = 0;
  __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("amf3", __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_BUILTIN_MODULE_NAME);
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (PyObject_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 ---*/
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/Users/nick/projects/pyamf/trunk/cpyamf/amf3.pyx":107
 *     return o
 * 
 * def decode_int(stream, sign=False):             # <<<<<<<<<<<<<<
 *     return PyInt_FromLong(_decode_int(stream, <int>sign))
 */
  __pyx_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_k_1 = __pyx_1;
  __pyx_1 = 0;
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("cpyamf.amf3");
  #if PY_MAJOR_VERSION >= 3
  return NULL;
  #endif
}

static const char *__pyx_filenames[] = {
  "amf3.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

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 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 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)) {
        #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 {
            name = argnames;
            while (*name && (**name != key)) name++;
            if (*name) {
                if (name < first_kw_arg) goto arg_passed_twice;
                values[name-argnames] = value;
            } 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) &&
                        strcmp(PyString_AS_STRING(**name),
                               PyString_AS_STRING(key)) == 0) 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) &&
                            strcmp(PyString_AS_STRING(**name),
                                   PyString_AS_STRING(key)) == 0) 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_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();

    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 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);
    }
}

#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 int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if (x == Py_False) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x) {
    if (PyInt_CheckExact(x)) {
        return PyInt_AS_LONG(x);
    }
    else if (PyLong_CheckExact(x)) {
        return PyLong_AsLongLong(x);
    }
    else {
        PY_LONG_LONG val;
        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    if (PyInt_CheckExact(x)) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_TypeError, "Negative assignment to unsigned type.");
            return (unsigned PY_LONG_LONG)-1;
        }
        return val;
    }
    else if (PyLong_CheckExact(x)) {
        return PyLong_AsUnsignedLongLong(x);
    }
    else {
        PY_LONG_LONG val;
        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsUnsignedLongLong(tmp);
        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);
    }
}

