diff --git a/internal/tlcodegen/helpers_php.go b/internal/tlcodegen/helpers_php.go index 64ea7dc..47b598f 100644 --- a/internal/tlcodegen/helpers_php.go +++ b/internal/tlcodegen/helpers_php.go @@ -3,7 +3,6 @@ package tlcodegen const BasicTlPathPhp = "basictl.php" const BasicTLCodePHP = ` data[$this->offset + 7]) << 48) + (ord($this->data[$this->offset + 6]) << 40) + (ord($this->data[$this->offset + 5]) << 32) + (ord($this->data[$this->offset + 4]) << 24) + (ord($this->data[$this->offset + 3]) << 16) + (ord($this->data[$this->offset + 2]) << 8) + (ord($this->data[$this->offset + 1]) << 0); - // TODO: check l64 > maxint + // TODO: check l64 > max int $l = $l64; $this->offset += 8; $p = $l; diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 89c42a8..596c99a 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -6,6 +6,13 @@ import ( "strings" ) +const ( + PHPFileStart = ""+field.originalName, + defaultValue, + )) + shift -= 1 + code.WriteString(fmt.Sprintf("%[1]s}\n", textTab())) } } @@ -797,12 +797,28 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, args)...) return result } + if trw.ResultType == nil && trw.wr.PHPIsTrueType() { + var result []string + if !bare { + result = append(result, + "[$magic, $success] = $stream->read_uint32();", + fmt.Sprintf("if (!$success || $magic != 0x%08[1]x) {", trw.wr.tlTag), + " return false;", + "}", + ) + } + result = append(result, fmt.Sprintf("%[1]s = true;", targetName)) + return result + } //isDict, _, _, valueType := isDictionaryElement(trw.wr) //if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... // return valueType.t.trw.PhpTypeName(withPath, bare) //} } return []string{ + fmt.Sprintf("if (%[1]s == null) {", targetName), + fmt.Sprintf(" %[1]s = %[2]s", targetName, trw.PhpDefaultInit()), + "}", fmt.Sprintf("$success = %[2]s->read%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), "if ($success) {", " return false;",