public function serialize($v)
 {
     $_g = Type::typeof($v);
     switch ($_g->index) {
         case 0:
             $this->buf->add("n");
             break;
         case 1:
             $v1 = $v;
             if ($v1 === 0) {
                 $this->buf->add("z");
                 return;
             }
             $this->buf->add("i");
             $this->buf->add($v1);
             break;
         case 2:
             $v2 = $v;
             if (Math::isNaN($v2)) {
                 $this->buf->add("k");
             } else {
                 if (!Math::isFinite($v2)) {
                     $this->buf->add($v2 < 0 ? "m" : "p");
                 } else {
                     $this->buf->add("d");
                     $this->buf->add($v2);
                 }
             }
             break;
         case 3:
             $this->buf->add($v ? "t" : "f");
             break;
         case 6:
             $c = _hx_deref($_g)->params[0];
             if (is_object($_t = $c) && !$_t instanceof Enum ? $_t === _hx_qtype("String") : $_t == _hx_qtype("String")) {
                 $this->serializeString($v);
                 return;
             }
             if ($this->useCache && $this->serializeRef($v)) {
                 return;
             }
             switch ($c) {
                 case _hx_qtype("Array"):
                     $ucount = 0;
                     $this->buf->add("a");
                     $l = _hx_len($v);
                     $_g1 = 0;
                     while ($_g1 < $l) {
                         $i = $_g1++;
                         if ($v[$i] === null) {
                             $ucount++;
                         } else {
                             if ($ucount > 0) {
                                 if ($ucount === 1) {
                                     $this->buf->add("n");
                                 } else {
                                     $this->buf->add("u");
                                     $this->buf->add($ucount);
                                 }
                                 $ucount = 0;
                             }
                             $this->serialize($v[$i]);
                         }
                         unset($i);
                     }
                     if ($ucount > 0) {
                         if ($ucount === 1) {
                             $this->buf->add("n");
                         } else {
                             $this->buf->add("u");
                             $this->buf->add($ucount);
                         }
                     }
                     $this->buf->add("h");
                     break;
                 case _hx_qtype("List"):
                     $this->buf->add("l");
                     $v3 = $v;
                     if (null == $v3) {
                         throw new HException('null iterable');
                     }
                     $__hx__it = $v3->iterator();
                     while ($__hx__it->hasNext()) {
                         unset($i1);
                         $i1 = $__hx__it->next();
                         $this->serialize($i1);
                     }
                     $this->buf->add("h");
                     break;
                 case _hx_qtype("Date"):
                     $d = $v;
                     $this->buf->add("v");
                     $this->buf->add($d->getTime());
                     break;
                 case _hx_qtype("haxe.ds.StringMap"):
                     $this->buf->add("b");
                     $v4 = $v;
                     if (null == $v4) {
                         throw new HException('null iterable');
                     }
                     $__hx__it = $v4->keys();
                     while ($__hx__it->hasNext()) {
                         unset($k);
                         $k = $__hx__it->next();
                         $this->serializeString($k);
                         $this->serialize($v4->get($k));
                     }
                     $this->buf->add("h");
                     break;
                 case _hx_qtype("haxe.ds.IntMap"):
                     $this->buf->add("q");
                     $v5 = $v;
                     if (null == $v5) {
                         throw new HException('null iterable');
                     }
                     $__hx__it = $v5->keys();
                     while ($__hx__it->hasNext()) {
                         unset($k1);
                         $k1 = $__hx__it->next();
                         $this->buf->add(":");
                         $this->buf->add($k1);
                         $this->serialize($v5->get($k1));
                     }
                     $this->buf->add("h");
                     break;
                 case _hx_qtype("haxe.ds.ObjectMap"):
                     $this->buf->add("M");
                     $v6 = $v;
                     $__hx__it = new _hx_array_iterator(array_values($v6->hk));
                     while ($__hx__it->hasNext()) {
                         unset($k2);
                         $k2 = $__hx__it->next();
                         $this->serialize($k2);
                         $this->serialize($v6->get($k2));
                     }
                     $this->buf->add("h");
                     break;
                 case _hx_qtype("haxe.io.Bytes"):
                     $v7 = $v;
                     $i2 = 0;
                     $max = $v7->length - 2;
                     $charsBuf = new StringBuf();
                     $b64 = haxe_Serializer::$BASE64;
                     while ($i2 < $max) {
                         $b1 = null;
                         $pos = $i2++;
                         $b1 = ord($v7->b[$pos]);
                         unset($pos);
                         $b2 = null;
                         $pos1 = $i2++;
                         $b2 = ord($v7->b[$pos1]);
                         unset($pos1);
                         $b3 = null;
                         $pos2 = $i2++;
                         $b3 = ord($v7->b[$pos2]);
                         unset($pos2);
                         $charsBuf->add(_hx_char_at($b64, $b1 >> 2));
                         $charsBuf->add(_hx_char_at($b64, ($b1 << 4 | $b2 >> 4) & 63));
                         $charsBuf->add(_hx_char_at($b64, ($b2 << 2 | $b3 >> 6) & 63));
                         $charsBuf->add(_hx_char_at($b64, $b3 & 63));
                         unset($b3, $b2, $b1);
                     }
                     if ($i2 === $max) {
                         $b11 = null;
                         $pos3 = $i2++;
                         $b11 = ord($v7->b[$pos3]);
                         $b21 = null;
                         $pos4 = $i2++;
                         $b21 = ord($v7->b[$pos4]);
                         $charsBuf->add(_hx_char_at($b64, $b11 >> 2));
                         $charsBuf->add(_hx_char_at($b64, ($b11 << 4 | $b21 >> 4) & 63));
                         $charsBuf->add(_hx_char_at($b64, $b21 << 2 & 63));
                     } else {
                         if ($i2 === $max + 1) {
                             $b12 = null;
                             $pos5 = $i2++;
                             $b12 = ord($v7->b[$pos5]);
                             $charsBuf->add(_hx_char_at($b64, $b12 >> 2));
                             $charsBuf->add(_hx_char_at($b64, $b12 << 4 & 63));
                         }
                     }
                     $chars = $charsBuf->b;
                     $this->buf->add("s");
                     $this->buf->add(strlen($chars));
                     $this->buf->add(":");
                     $this->buf->add($chars);
                     break;
                 default:
                     if ($this->useCache) {
                         $this->cache->pop();
                     }
                     if (_hx_field($v, "hxSerialize") !== null) {
                         $this->buf->add("C");
                         $this->serializeString(Type::getClassName($c));
                         if ($this->useCache) {
                             $this->cache->push($v);
                         }
                         $v->hxSerialize($this);
                         $this->buf->add("g");
                     } else {
                         $this->buf->add("c");
                         $this->serializeString(Type::getClassName($c));
                         if ($this->useCache) {
                             $this->cache->push($v);
                         }
                         $this->serializeFields($v);
                     }
                     break;
             }
             break;
         case 4:
             if (Std::is($v, _hx_qtype("Class"))) {
                 $className = Type::getClassName($v);
                 $this->buf->add("A");
                 $this->serializeString($className);
             } else {
                 if (Std::is($v, _hx_qtype("Enum"))) {
                     $this->buf->add("B");
                     $this->serializeString(Type::getEnumName($v));
                 } else {
                     if ($this->useCache && $this->serializeRef($v)) {
                         return;
                     }
                     $this->buf->add("o");
                     $this->serializeFields($v);
                 }
             }
             break;
         case 7:
             $e = _hx_deref($_g)->params[0];
             if ($this->useCache) {
                 if ($this->serializeRef($v)) {
                     return;
                 }
                 $this->cache->pop();
             }
             $this->buf->add($this->useEnumIndex ? "j" : "w");
             $this->serializeString(Type::getEnumName($e));
             if ($this->useEnumIndex) {
                 $this->buf->add(":");
                 $this->buf->add($v->index);
             } else {
                 $this->serializeString($v->tag);
             }
             $this->buf->add(":");
             $l1 = count($v->params);
             if ($l1 === 0 || _hx_field($v, "params") === null) {
                 $this->buf->add(0);
             } else {
                 $this->buf->add($l1);
                 $_g11 = 0;
                 while ($_g11 < $l1) {
                     $i3 = $_g11++;
                     $this->serialize($v->params[$i3]);
                     unset($i3);
                 }
             }
             if ($this->useCache) {
                 $this->cache->push($v);
             }
             break;
         case 5:
             throw new HException("Cannot serialize function");
             break;
         default:
             throw new HException("Cannot serialize " . Std::string($v));
             break;
     }
 }
 public function write($k, $v)
 {
     if ($this->replacer !== null) {
         $v = $this->replacer($k, $v);
     }
     $_g = Type::typeof($v);
     switch ($_g->index) {
         case 8:
             $this->buf->add("\"???\"");
             break;
         case 4:
             $this->fieldsString($v, Reflect::fields($v));
             break;
         case 1:
             $v1 = $v;
             $this->buf->add($v1);
             break;
         case 2:
             $v2 = null;
             if (Math::isFinite($v)) {
                 $v2 = $v;
             } else {
                 $v2 = "null";
             }
             $this->buf->add($v2);
             break;
         case 5:
             $this->buf->add("\"<fun>\"");
             break;
         case 6:
             $c = _hx_deref($_g)->params[0];
             if (is_object($_t = $c) && !$_t instanceof Enum ? $_t === _hx_qtype("String") : $_t == _hx_qtype("String")) {
                 $this->quote($v);
             } else {
                 if (is_object($_t2 = $c) && !$_t2 instanceof Enum ? $_t2 === _hx_qtype("Array") : $_t2 == _hx_qtype("Array")) {
                     $v3 = $v;
                     $this->buf->b .= "[";
                     $len = $v3->length;
                     $last = $len - 1;
                     $_g1 = 0;
                     while ($_g1 < $len) {
                         $i = $_g1++;
                         if ($i > 0) {
                             $this->buf->b .= ",";
                         } else {
                             $this->nind++;
                         }
                         if ($this->pretty) {
                             $this->buf->b .= "\n";
                         }
                         if ($this->pretty) {
                             $v4 = null;
                             $c1 = $this->indent;
                             $l = $this->nind * strlen($this->indent);
                             if (strlen($c1) === 0 || strlen("") >= $l) {
                                 $v4 = "";
                             } else {
                                 $v4 = str_pad("", Math::ceil(($l - strlen("")) / strlen($c1)) * strlen($c1) + strlen(""), $c1, STR_PAD_LEFT);
                             }
                             unset($l, $c1);
                             $this->buf->add($v4);
                             unset($v4);
                         }
                         $this->write($i, $v3[$i]);
                         if ($i === $last) {
                             $this->nind--;
                             if ($this->pretty) {
                                 $this->buf->b .= "\n";
                             }
                             if ($this->pretty) {
                                 $v5 = null;
                                 $c2 = $this->indent;
                                 $l1 = $this->nind * strlen($this->indent);
                                 if (strlen($c2) === 0 || strlen("") >= $l1) {
                                     $v5 = "";
                                 } else {
                                     $v5 = str_pad("", Math::ceil(($l1 - strlen("")) / strlen($c2)) * strlen($c2) + strlen(""), $c2, STR_PAD_LEFT);
                                 }
                                 unset($l1, $c2);
                                 $this->buf->add($v5);
                                 unset($v5);
                             }
                         }
                         unset($i);
                     }
                     $this->buf->b .= "]";
                 } else {
                     if (is_object($_t3 = $c) && !$_t3 instanceof Enum ? $_t3 === _hx_qtype("haxe.ds.StringMap") : $_t3 == _hx_qtype("haxe.ds.StringMap")) {
                         $v6 = $v;
                         $o = _hx_anonymous(array());
                         if (null == $v6) {
                             throw new HException('null iterable');
                         }
                         $__hx__it = $v6->keys();
                         while ($__hx__it->hasNext()) {
                             unset($k1);
                             $k1 = $__hx__it->next();
                             $value = $v6->get($k1);
                             $o->{$k1} = $value;
                             unset($value);
                         }
                         $this->fieldsString($o, Reflect::fields($o));
                     } else {
                         if (is_object($_t4 = $c) && !$_t4 instanceof Enum ? $_t4 === _hx_qtype("Date") : $_t4 == _hx_qtype("Date")) {
                             $v7 = $v;
                             $this->quote($v7->toString());
                         } else {
                             $this->fieldsString($v, Reflect::fields($v));
                         }
                     }
                 }
             }
             break;
         case 7:
             $i1 = null;
             $e = $v;
             $i1 = $e->index;
             $v8 = $i1;
             $this->buf->add($v8);
             break;
         case 3:
             $this->buf->add($v ? "true" : "false");
             break;
         case 0:
             $this->buf->add("null");
             break;
     }
 }