public function getReadCode(CodeField $field)
 {
     $tmpFieldName = 'tmp' . ucwords($field->getName());
     $code = 'long ' . $tmpFieldName . ' = in.readLong();' . "\n";
     $code .= $field->getName() . ' = ' . $tmpFieldName . ' != -1 ? new Date(' . $tmpFieldName . ') : null;';
     return $code;
 }
 public function getReadCode(CodeField $field)
 {
     $code = 'if (in.readByte() == 0x01) {' . "\n";
     $code .= '    ' . $field->getName() . ' = new ' . $this->mTypeSuffix . '<' . $field->getTypeParam() . '>' . '();' . "\n";
     $code .= '    in.readList(' . $field->getName() . ', ' . $field->getTypeParam() . '.class.getClassLoader());' . "\n";
     $code .= '} else {' . "\n";
     $code .= '    ' . $field->getName() . ' = null;' . "\n";
     $code .= '}';
     return $code;
 }
 public function getReadCode(CodeField $field)
 {
     $code = 'byte ' . $field->getName() . 'Val = in.readByte();' . "\n";
     $code .= $field->getName() . ' = ' . $field->getName() . 'Val == 0x02 ? null : ' . $field->getName() . 'Val != 0x00;';
     return $code;
 }
 public function getReadCode(CodeField $field)
 {
     return $field->getName() . ' = in.readByte() != 0x00;';
 }
 public function getReadCode(CodeField $field)
 {
     return $field->getName() . ' = in.readByte() == 0x00 ? null : new JSON' . $this->mTypeSuffix . '(in.readString());';
 }
 public function getReadCode(CodeField $field)
 {
     return $field->getName() . ' = in.read' . $this->mTypeSuffix . '();';
 }
 public function getReadCode(CodeField $field)
 {
     return $field->getName() . ' = (' . $field->getType() . ') in.readValue(' . $field->getType() . '.class.getClassLoader());';
 }
 private function parse($input)
 {
     $this->mInput = $input;
     // Remove single-line comments
     $input = preg_replace('/\\/\\/.*/', '', $input);
     $input = preg_replace('/[\\s]{2,}/m', ' ', $input);
     $input = preg_replace('/\\{[\\s]+/', '{', $input);
     $input = preg_replace('/^[ ]+/m', '', $input);
     $input = str_replace(array("\n", "\r", "\t"), '', $input);
     $this->mClass = null;
     if (preg_match('/class (?<class>([a-zA-Z_$][a-zA-Z\\d_$]*\\.)*[a-zA-Z_$][a-zA-Z\\d_$]*)/', $input, $matches)) {
         $this->mClass = $matches['class'];
     }
     $commentStart = null;
     $c = null;
     $record = true;
     $newFile = '';
     for ($i = 0; $i < strlen($input); $i++) {
         $pc = $c;
         $c = substr($input, $i, 1);
         $fc = substr($input, $i + 1, 1);
         if ($record === true && $c == '/' && $fc == '*') {
             $record = false;
         }
         if ($record === true) {
             $newFile .= $c;
         }
         if ($record === false && $pc == '*' && $c == '/') {
             $record = true;
         }
     }
     $input = $newFile;
     $input = str_replace('}', '};', $input);
     $input = preg_replace('/^[^{]+{/', '', $input);
     $input = implode(";\n", explode(';', $input));
     $level = 0;
     $newFile = '';
     $newFileI = 0;
     for ($i = 0; $i < strlen($input); $i++) {
         $c = substr($input, $i, 1);
         if ($c == '{') {
             if ($level === 0) {
                 $newFile = substr($newFile, 0, strrpos($newFile, ";"));
             }
             $level += 1;
         }
         if ($level === 0) {
             $newFile .= $c;
             $newFileI++;
         }
         if ($c == '}') {
             $level -= 1;
         }
     }
     $input = $newFile;
     // Remove static variable references
     $input = preg_replace('/^.* static .*$\\n/m', '', $input);
     // Trim trailing slashes
     $input = preg_replace('/}+$/m', '', $input);
     // Remove final modifier
     $input = preg_replace('/final /m', '', $input);
     // Remove scope modifiers
     $input = preg_replace('/^(public|protected|private) /m', '', $input);
     // Remove annotations
     $input = preg_replace('/^@[^ ]+/', '', $input);
     // Remove assignments
     $input = preg_replace('/=.*$/m', '', $input);
     $input = str_replace(';', '', $input);
     $input = trim($input);
     if ($input && $this->mClass) {
         $lines = explode("\n", $input);
         foreach ($lines as $line) {
             if (preg_match('/([\\w\\d_.]+)(<([^>]+)>)?\\s+([\\w\\d_]+)\\s*$/i', $line, $output_array)) {
                 $field = new CodeField($output_array[4], $output_array[1], $output_array[3]);
                 $this->mFields[$field->getName()] = $field;
             } else {
                 array_push($this->mUnrecognizedFields, $line);
             }
         }
     }
 }