Skip to content

Commit

Permalink
field mask and reset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brat-vseznamus committed Dec 28, 2024
1 parent 032f719 commit af5012d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
3 changes: 1 addition & 2 deletions internal/tlcodegen/helpers_php.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tlcodegen
const BasicTlPathPhp = "basictl.php"
const BasicTLCodePHP = `
<?php
include "run.php";
class tl_constants {
const tinyStringLen = 253;
Expand Down Expand Up @@ -117,7 +116,7 @@ class tl_input_stream {
return ["", false];
}
$l64 = (ord($this->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;
Expand Down
14 changes: 7 additions & 7 deletions internal/tlcodegen/tlgen_lang_php.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import (
"strings"
)

const (
PHPFileStart = "<?php\n"
PHPRPCFunctionMock = "__RPC_FUNCTION_MOCK"
PHPRPCFunctionResultMock = "__RPC_FUNCTION_RESULT_MOCK"
PHPRPCResponseMock = "__RPC_RESPONSE_MOCK"
)

type TypeRWPHPData interface {
PhpClassName(withPath bool, bare bool) string
PhpClassNameReplaced() bool
Expand All @@ -24,13 +31,6 @@ type PhpClassMeta struct {
UsedInFunctions bool
}

const (
PHPFileStart = "<?php\n"
PHPRPCFunctionMock = "__RPC_FUNCTION_MOCK"
PHPRPCFunctionResultMock = "__RPC_FUNCTION_RESULT_MOCK"
PHPRPCResponseMock = "__RPC_RESPONSE_MOCK"
)

func (gen *Gen2) generateCodePHP(generateByteVersions []string) error {
if err := gen.addCodeFile(BasicTlPathPhp, BasicTLCodePHP); err != nil {
return err
Expand Down
38 changes: 27 additions & 11 deletions internal/tlcodegen/type_rw_struct_php.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,6 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) {
))
const tab = " "
for i, field := range trw.Fields {
//fmt.Printf("\tfield \"%s\" with fieldMask \"%s\" and deps %v\n", field.originalName, trw.PHPGetFieldMask(i), trw.PHPGetFieldNatDependenciesValues(i))
if field.originalName == "x" && trw.PhpClassName(false, true) == "test_gigi" {
print("debug")
}

fieldMask := trw.PHPGetFieldMask(i)
shift := 2
textTab := func() string { return strings.Repeat(tab, shift) }
Expand All @@ -362,12 +357,17 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) {
}
if fieldMask != "" {
shift -= 1
code.WriteString(
fmt.Sprintf(
"%[1]s}\n",
textTab(),
),
)
code.WriteString(fmt.Sprintf("%[1]s} else {\n", textTab()))
shift += 1
_, defaultValue := fieldTypeAndDefaultValue(field)
code.WriteString(fmt.Sprintf(
"%[1]s%[2]s = %[3]s;\n",
textTab(),
"$this->"+field.originalName,
defaultValue,
))
shift -= 1
code.WriteString(fmt.Sprintf("%[1]s}\n", textTab()))
}
}

Expand Down Expand Up @@ -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;",
Expand Down

0 comments on commit af5012d

Please sign in to comment.