From 259cb2ebf9c95b8c93febce33f9c79f5e6bf3f16 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 23 Dec 2024 15:22:27 +0300 Subject: [PATCH 01/37] add new flag + moved files to _php --- cmd/tlgen/main2.go | 4 + internal/tlcodegen/tlgen.go | 3 + internal/tlcodegen/type_rw_bool.go | 24 - internal/tlcodegen/type_rw_bool_php.go | 29 + internal/tlcodegen/type_rw_maybe.go | 35 -- internal/tlcodegen/type_rw_maybe_php.go | 40 ++ internal/tlcodegen/type_rw_primitive.go | 41 -- internal/tlcodegen/type_rw_primitive_php.go | 46 ++ internal/tlcodegen/type_rw_struct.go | 615 ------------------- internal/tlcodegen/type_rw_struct_php.go | 621 ++++++++++++++++++++ internal/tlcodegen/type_rw_tuple.go | 36 -- internal/tlcodegen/type_rw_tuple_php.go | 42 ++ internal/tlcodegen/type_rw_union.go | 79 --- internal/tlcodegen/type_rw_union_php.go | 84 +++ 14 files changed, 869 insertions(+), 830 deletions(-) create mode 100644 internal/tlcodegen/type_rw_bool_php.go create mode 100644 internal/tlcodegen/type_rw_maybe_php.go create mode 100644 internal/tlcodegen/type_rw_primitive_php.go create mode 100644 internal/tlcodegen/type_rw_struct_php.go create mode 100644 internal/tlcodegen/type_rw_tuple_php.go create mode 100644 internal/tlcodegen/type_rw_union_php.go diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index 2687ddb..bdb9093 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -76,6 +76,10 @@ func parseFlags(opt *tlcodegen.Gen2Options) { flag.StringVar(&opt.RootCPPNamespace, "cpp-namespace", "", `c++ root namespace, separated by '::' if more than 1 element`) + // PHP + flag.BoolVar(&opt.AddFunctionBodies, "php-serialization-bodies", false, + `whether to generate body to write/read generated structs and functions`) + // .tlo flag.StringVar(&opt.TLOPath, "tloPath", "", "whether to serialize TL schema in binary form") diff --git a/internal/tlcodegen/tlgen.go b/internal/tlcodegen/tlgen.go index 9001243..ab905ce 100644 --- a/internal/tlcodegen/tlgen.go +++ b/internal/tlcodegen/tlgen.go @@ -331,6 +331,9 @@ type Gen2Options struct { RootCPPNamespace string SeparateFiles bool + // PHP + AddFunctionBodies bool + // .tlo TLOPath string CanonicalFormPath string // combinators in canonical form, with comment of source schema file path diff --git a/internal/tlcodegen/type_rw_bool.go b/internal/tlcodegen/type_rw_bool.go index 4a3e085..5093806 100644 --- a/internal/tlcodegen/type_rw_bool.go +++ b/internal/tlcodegen/type_rw_bool.go @@ -8,7 +8,6 @@ package tlcodegen import ( "fmt" - "strings" ) type TypeRWBool struct { @@ -110,26 +109,3 @@ func (trw *TypeRWBool) typeJSONReadingCode(bytesVersion bool, directImports *Dir func (trw *TypeRWBool) typeJSON2ReadingCode(bytesVersion bool, directImports *DirectImports, ins *InternalNamespace, jvalue string, val string, natArgs []string, ref bool) string { return wrapLast(false, fmt.Sprintf("%sJson2ReadBool(%s, %s)", trw.wr.gen.InternalPrefix(), jvalue, addAmpersand(ref, val))) } - -func (trw *TypeRWBool) PhpClassName(withPath bool, bare bool) string { - return "boolean" -} - -func (trw *TypeRWBool) PhpClassNameReplaced() bool { - return true -} - -func (trw *TypeRWBool) PhpTypeName(withPath bool, bare bool) string { - return trw.PhpClassName(withPath, true) -} - -func (trw *TypeRWBool) PhpGenerateCode(code *strings.Builder, bytes bool) error { - return fmt.Errorf("boolean doesn't have php code") -} - -func (trw *TypeRWBool) PhpDefaultValue() string { - return "false" -} - -func (trw *TypeRWBool) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { -} diff --git a/internal/tlcodegen/type_rw_bool_php.go b/internal/tlcodegen/type_rw_bool_php.go new file mode 100644 index 0000000..1a2097b --- /dev/null +++ b/internal/tlcodegen/type_rw_bool_php.go @@ -0,0 +1,29 @@ +package tlcodegen + +import ( + "fmt" + "strings" +) + +func (trw *TypeRWBool) PhpClassName(withPath bool, bare bool) string { + return "boolean" +} + +func (trw *TypeRWBool) PhpClassNameReplaced() bool { + return true +} + +func (trw *TypeRWBool) PhpTypeName(withPath bool, bare bool) string { + return trw.PhpClassName(withPath, true) +} + +func (trw *TypeRWBool) PhpGenerateCode(code *strings.Builder, bytes bool) error { + return fmt.Errorf("boolean doesn't have php code") +} + +func (trw *TypeRWBool) PhpDefaultValue() string { + return "false" +} + +func (trw *TypeRWBool) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { +} diff --git a/internal/tlcodegen/type_rw_maybe.go b/internal/tlcodegen/type_rw_maybe.go index d9e4ee0..b2068e4 100644 --- a/internal/tlcodegen/type_rw_maybe.go +++ b/internal/tlcodegen/type_rw_maybe.go @@ -8,7 +8,6 @@ package tlcodegen import ( "fmt" - "strings" ) type TypeRWMaybe struct { @@ -119,37 +118,3 @@ func (trw *TypeRWMaybe) typeJSONReadingCode(bytesVersion bool, directImports *Di func (trw *TypeRWMaybe) typeJSON2ReadingCode(bytesVersion bool, directImports *DirectImports, ins *InternalNamespace, jvalue string, val string, natArgs []string, ref bool) string { return fmt.Sprintf("if err := %s.ReadJSON(legacyTypeNames, %s %s); err != nil { return err }", val, jvalue, joinWithCommas(natArgs)) } - -func (trw *TypeRWMaybe) PhpClassName(withPath bool, bare bool) string { - target := trw.getInnerTarget() - return "maybe_" + target.t.trw.PhpClassName(withPath, target.bare) -} - -func (trw *TypeRWMaybe) PhpClassNameReplaced() bool { - return true -} - -func (trw *TypeRWMaybe) PhpTypeName(withPath bool, bare bool) string { - target := trw.getInnerTarget() - return target.t.trw.PhpTypeName(withPath, target.t.PHPIsBare()) + "|null" -} - -func (trw *TypeRWMaybe) getInnerTarget() Field { - if inner, ok := trw.element.t.trw.(*TypeRWMaybe); ok { - return inner.getInnerTarget() - } else { - return trw.element - } -} - -func (trw *TypeRWMaybe) PhpGenerateCode(code *strings.Builder, bytes bool) error { - return fmt.Errorf("maybe doesn't have php code") -} - -func (trw *TypeRWMaybe) PhpDefaultValue() string { - return "null" -} - -func (trw *TypeRWMaybe) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { - trw.element.t.PhpIterateReachableTypes(reachableTypes) -} diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go new file mode 100644 index 0000000..b3805cc --- /dev/null +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -0,0 +1,40 @@ +package tlcodegen + +import ( + "fmt" + "strings" +) + +func (trw *TypeRWMaybe) PhpClassName(withPath bool, bare bool) string { + target := trw.getInnerTarget() + return "maybe_" + target.t.trw.PhpClassName(withPath, target.bare) +} + +func (trw *TypeRWMaybe) PhpClassNameReplaced() bool { + return true +} + +func (trw *TypeRWMaybe) PhpTypeName(withPath bool, bare bool) string { + target := trw.getInnerTarget() + return target.t.trw.PhpTypeName(withPath, target.t.PHPIsBare()) + "|null" +} + +func (trw *TypeRWMaybe) getInnerTarget() Field { + if inner, ok := trw.element.t.trw.(*TypeRWMaybe); ok { + return inner.getInnerTarget() + } else { + return trw.element + } +} + +func (trw *TypeRWMaybe) PhpGenerateCode(code *strings.Builder, bytes bool) error { + return fmt.Errorf("maybe doesn't have php code") +} + +func (trw *TypeRWMaybe) PhpDefaultValue() string { + return "null" +} + +func (trw *TypeRWMaybe) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { + trw.element.t.PhpIterateReachableTypes(reachableTypes) +} diff --git a/internal/tlcodegen/type_rw_primitive.go b/internal/tlcodegen/type_rw_primitive.go index 526524d..b789a0a 100644 --- a/internal/tlcodegen/type_rw_primitive.go +++ b/internal/tlcodegen/type_rw_primitive.go @@ -9,7 +9,6 @@ package tlcodegen import ( "fmt" "log" - "strings" ) type TypeRWPrimitive struct { @@ -171,43 +170,3 @@ func (trw *TypeRWPrimitive) typeJSON2ReadingCode(bytesVersion bool, directImport func (trw *TypeRWPrimitive) GenerateCode(byteVersion bool, directImports *DirectImports) string { return "" } - -func (trw *TypeRWPrimitive) PhpClassName(withPath bool, bare bool) string { - switch trw.goType { - case "int32", "int64", "uint32": - return "int" - case "string": - return "string" - case "float32", "float64": - return "float" - default: - return fmt.Sprintf("", trw.tlType) - } -} - -func (trw *TypeRWPrimitive) PhpClassNameReplaced() bool { - return true -} - -func (trw *TypeRWPrimitive) PhpTypeName(withPath bool, bare bool) string { - return trw.PhpClassName(withPath, true) -} - -func (trw *TypeRWPrimitive) PhpGenerateCode(code *strings.Builder, bytes bool) error { - return fmt.Errorf("primitives don't have php code") -} - -func (trw *TypeRWPrimitive) PhpDefaultValue() string { - switch trw.goType { - case "int32", "int64", "uint32": - return "0" - case "string": - return "''" - case "float32", "float64": - return "0.0" - default: - return fmt.Sprintf("", trw.tlType) - } -} - -func (trw *TypeRWPrimitive) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) {} diff --git a/internal/tlcodegen/type_rw_primitive_php.go b/internal/tlcodegen/type_rw_primitive_php.go new file mode 100644 index 0000000..81438f6 --- /dev/null +++ b/internal/tlcodegen/type_rw_primitive_php.go @@ -0,0 +1,46 @@ +package tlcodegen + +import ( + "fmt" + "strings" +) + +func (trw *TypeRWPrimitive) PhpClassName(withPath bool, bare bool) string { + switch trw.goType { + case "int32", "int64", "uint32": + return "int" + case "string": + return "string" + case "float32", "float64": + return "float" + default: + return fmt.Sprintf("", trw.tlType) + } +} + +func (trw *TypeRWPrimitive) PhpClassNameReplaced() bool { + return true +} + +func (trw *TypeRWPrimitive) PhpTypeName(withPath bool, bare bool) string { + return trw.PhpClassName(withPath, true) +} + +func (trw *TypeRWPrimitive) PhpGenerateCode(code *strings.Builder, bytes bool) error { + return fmt.Errorf("primitives don't have php code") +} + +func (trw *TypeRWPrimitive) PhpDefaultValue() string { + switch trw.goType { + case "int32", "int64", "uint32": + return "0" + case "string": + return "''" + case "float32", "float64": + return "0.0" + default: + return fmt.Sprintf("", trw.tlType) + } +} + +func (trw *TypeRWPrimitive) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) {} diff --git a/internal/tlcodegen/type_rw_struct.go b/internal/tlcodegen/type_rw_struct.go index 01cf477..8d4f505 100644 --- a/internal/tlcodegen/type_rw_struct.go +++ b/internal/tlcodegen/type_rw_struct.go @@ -8,10 +8,8 @@ package tlcodegen import ( "fmt" - "github.com/vkcom/tl/internal/utils" "log" "sort" - "strings" ) type TypeRWStruct struct { @@ -566,616 +564,3 @@ func (trw *TypeRWStruct) typeJSON2ReadingCode(bytesVersion bool, directImports * } return fmt.Sprintf("if err := %s.ReadJSON(legacyTypeNames, %s %s); err != nil { return err }", val, jvalue, joinWithCommas(natArgs)) } - -func (trw *TypeRWStruct) PhpClassNameReplaced() bool { - unionParent := trw.PhpConstructorNeedsUnion() - if unionParent == nil { - if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { - return true - } - - if trw.ResultType == nil && trw.wr.PHPIsTrueType() { - return true - } - - isDict, _, _, _ := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... - return true - } - } - return false -} - -func (trw *TypeRWStruct) PhpClassName(withPath bool, bare bool) string { - if PHPSpecialMembersTypes(trw.wr) != "" { - return "" - } - unionParent := trw.PhpConstructorNeedsUnion() - if unionParent == nil { - if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { - return trw.Fields[0].t.trw.PhpClassName(withPath, bare) - } - - if trw.ResultType == nil && trw.wr.PHPIsTrueType() { - return "boolean" - } - - isDict, _, _, valueType := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... - return valueType.t.trw.PhpClassName(withPath, bare) - } - } - - name := trw.wr.tlName.Name - if !bare { - name = trw.wr.origTL[0].TypeDecl.Name.Name - } - if trw.wr.tlName.Namespace != "" { - name = fmt.Sprintf("%s_%s", trw.wr.tlName.Namespace, name) - } - - elems := make([]string, 0, len(trw.wr.arguments)) - for _, arg := range trw.wr.arguments { - if arg.tip != nil { - argText := arg.tip.trw.PhpClassName(false, false) - if argText != "" { - elems = append(elems, "__", argText) - } - } - } - - name += strings.Join(elems, "") - if withPath { - name = trw.wr.PHPTypePath() + name - } - return name -} - -func (trw *TypeRWStruct) PhpTypeName(withPath bool, bare bool) string { - if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { - return specialCase - } - unionParent := trw.PhpConstructorNeedsUnion() - if unionParent == nil { - if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { - return trw.Fields[0].t.trw.PhpTypeName(withPath, trw.Fields[0].bare) - } - isDict, _, _, valueType := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... - return valueType.t.trw.PhpTypeName(withPath, bare) - } - } - return trw.PhpClassName(withPath, bare) -} - -func (trw *TypeRWStruct) PhpGenerateCode(code *strings.Builder, bytes bool) error { - trw.PHPStructHeader(code) - trw.PHPStructFieldMasks(code) - trw.PHPStructFields(code) - trw.PHPStructResultType(code) - - necessaryFieldsInConstructor := make([]Field, 0) - usedFieldMasksIndecies := make([]int, 0) - usedFieldMasks := make(map[int][]Field) - for _, f := range trw.Fields { - if f.fieldMask == nil { - necessaryFieldsInConstructor = append(necessaryFieldsInConstructor, f) - } else { - index := f.fieldMask.FieldIndex - if !f.fieldMask.isField { - for i, argument := range trw.wr.origTL[0].TemplateArguments { - if argument.IsNat && argument.FieldName == f.fieldMask.name { - index = -(i + 1) - break - } - } - } - if usedFieldMasks[index] == nil { - usedFieldMasksIndecies = append(usedFieldMasksIndecies, index) - } - usedFieldMasks[index] = append(usedFieldMasks[index], f) - } - } - - trw.PHPStructConstructor(code, necessaryFieldsInConstructor) - trw.PHPStructRPCSpecialGetters(code) - trw.PHPStructFieldMaskCalculators(code, usedFieldMasksIndecies, usedFieldMasks) - trw.PHPStructFunctionSpecificMethods(code) - - code.WriteString("\n}\n") - - trw.PHPStructFunctionSpecificTypes(code) - return nil -} - -func (trw *TypeRWStruct) PHPStructFunctionSpecificTypes(code *strings.Builder) { - if trw.ResultType != nil { - code.WriteString( - fmt.Sprintf( - ` -/** - * @kphp-tl-class - */ -class %[1]s_result implements TL\RpcFunctionReturnResult { - - /** @var %[2]s */ - public $value = %[3]s; - -} -`, - trw.PhpClassName(false, true), - phpResultType(trw), - trw.ResultType.trw.PhpDefaultValue(), - ), - ) - } -} - -func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder) { - // print function specific methods and types - if trw.ResultType != nil { - kphpSpecialCode := "" - if trw.wr.HasAnnotation("kphp") { - kphpSpecialCode = fmt.Sprintf( - ` - - /** - * @param %[1]s $value - * @return %[2]s_result - */ - public static function createRpcServerResponse($value) { - $response = new %[2]s_result(); - $response->value = $value; - return $response; - }`, - trw.ResultType.trw.PhpTypeName(true, true), - trw.PhpClassName(true, true), - ) - } - - code.WriteString( - fmt.Sprintf( - ` - /** - * @param TL\RpcFunctionReturnResult $function_return_result - * @return %[4]s - */ - public static function functionReturnValue($function_return_result) { - if ($function_return_result instanceof %[1]s_result) { - return $function_return_result->value; - } - warning('Unexpected result type in functionReturnValue: ' . ($function_return_result ? get_class($function_return_result) : 'null')); - return (new %[1]s_result())->value; - } - - /** - * @kphp-inline - * - * @param TL\RpcResponse $response - * @return %[4]s - */ - public static function result(TL\RpcResponse $response) { - return self::functionReturnValue($response->getResult()); - }%[5]s - - /** - * @kphp-inline - * - * @return string - */ - public function getTLFunctionName() { - return '%[3]s'; - } -`, - trw.PhpClassName(false, true), - trw.PhpClassName(true, true), - trw.wr.tlName.String(), - phpResultType(trw), - kphpSpecialCode, - ), - ) - - } -} - -func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, usedFieldMasksIndecies []int, usedFieldMasks map[int][]Field) { - // print methods to calculate fieldmasks - // fix order - names := utils.MapSlice(usedFieldMasksIndecies, func(natIndex int) string { - natName := "" - if natIndex < 0 { - natName = trw.wr.origTL[0].TemplateArguments[-(natIndex + 1)].FieldName - } else { - natName = trw.Fields[natIndex].originalName - } - return natName - }) - - namesToIndices := make(map[string]int) - for i := range names { - namesToIndices[names[i]] = usedFieldMasksIndecies[i] - } - sort.Strings(names) - - fieldNameToFieldOrder := make(map[string]int) - for i := range trw.Fields { - fieldNameToFieldOrder[trw.Fields[i].originalName] = i - } - - for _, name := range names { - natIndex := namesToIndices[name] - natName := name - code.WriteString(` - /**`) - additionalArgs := make([]string, 0) - // arguments with ambiguous existence - for _, dependentField := range usedFieldMasks[natIndex] { - if _, isMaybe := dependentField.t.PHPGenCoreType().trw.(*TypeRWMaybe); isMaybe { - additionalArgs = append(additionalArgs, fmt.Sprintf("$has_%s", dependentField.originalName)) - code.WriteString(fmt.Sprintf("\n * @param bool $has_%s", dependentField.originalName)) - } - } - code.WriteString(` - * @return int - */ -`, - ) - code.WriteString( - fmt.Sprintf( - " public function calculate%[1]s(%[2]s) {\n $mask = 0;\n", - toPhpFieldMaskName(natName), - strings.Join(additionalArgs, ", "), - ), - ) - - fields := usedFieldMasks[natIndex] - sort.Slice(fields, func(i, j int) bool { - if fields[i].BitNumber == fields[j].BitNumber { - return i < j - } - return fields[i].BitNumber < fields[j].BitNumber - }) - - fieldsGroupedByBitNumber := make([][]Field, 0) - for _, dependentField := range fields { - if len(fieldsGroupedByBitNumber) == 0 || - fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1][0].BitNumber != dependentField.BitNumber { - fieldsGroupedByBitNumber = append(fieldsGroupedByBitNumber, make([]Field, 0)) - } - fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1] = append(fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1], dependentField) - } - - for _, dependentFields := range fieldsGroupedByBitNumber { - conditions := make([]string, 0) - bitConstants := make([]string, 0) - sort.Slice(dependentFields, func(i, j int) bool { - return fieldNameToFieldOrder[dependentFields[i].originalName] < fieldNameToFieldOrder[dependentFields[j].originalName] - }) - for _, dependentField := range dependentFields { - condition := "" - if dependentField.t.PHPIsTrueType() || dependentField.t.PHPNeedsCode() { - condition = fmt.Sprintf( - "$this->%[1]s", - dependentField.originalName, - ) - } else if _, isMaybe := dependentField.t.PHPGenCoreType().trw.(*TypeRWMaybe); isMaybe { - condition = fmt.Sprintf("$has_%s", dependentField.originalName) - } else { - condition = fmt.Sprintf( - "$this->%[1]s !== null", - dependentField.originalName, - ) - } - conditions = append(conditions, condition) - bitConstants = append(bitConstants, fmt.Sprintf( - "self::BIT_%[1]s_%[2]d", - strings.ToUpper(dependentField.originalName), - dependentField.BitNumber)) - } - - finalCondition := conditions[0] - finalMask := bitConstants[0] - - if len(conditions) > 1 { - finalCondition = strings.Join(conditions, " && ") - finalMask = "(" + strings.Join(bitConstants, " | ") + ")" - } - - code.WriteString( - fmt.Sprintf( - ` - if (%[1]s) { - $mask |= %[2]s; - } -`, - finalCondition, - finalMask, - ), - ) - } - - code.WriteString("\n return $mask;\n") - code.WriteString(" }\n") - } -} - -func (trw *TypeRWStruct) PHPStructConstructor(code *strings.Builder, necessaryFieldsInConstructor []Field) { - // print constructor - code.WriteString(` - /** -`) - for _, f := range necessaryFieldsInConstructor { - fieldType, _ := fieldTypeAndDefaultValue(f) - code.WriteString(fmt.Sprintf(" * @param %[1]s $%[2]s\n", fieldType, f.originalName)) - } - if len(necessaryFieldsInConstructor) == 0 { - code.WriteString(" * @kphp-inline\n") - } - - code.WriteString(` */ -`) - code.WriteString(" public function __construct(") - - for i, f := range necessaryFieldsInConstructor { - _, defaultValue := fieldTypeAndDefaultValue(f) - if i != 0 { - code.WriteString(", ") - } - code.WriteString(fmt.Sprintf("$%[1]s = %[2]s", f.originalName, defaultValue)) - } - - code.WriteString(") {\n") - for _, f := range necessaryFieldsInConstructor { - code.WriteString(fmt.Sprintf(" $this->%[1]s = $%[1]s;\n", f.originalName)) - } - code.WriteString(" }\n") -} - -func (trw *TypeRWStruct) PHPStructRPCSpecialGetters(code *strings.Builder) { - if unionParent := trw.wr.PHPUnionParent(); unionParent == nil || PHPSpecialMembersTypes(unionParent) == "" { - return - } - - const ThisType = "__this" - type SpecialField struct { - Name string - Type string - Default string - NullTypeIfNullValue bool - AddHasMethod bool - } - - fields := []SpecialField{ - { - "result", - "TL\\RpcFunctionReturnResult", - "null", - true, - false, - }, - { - "header", - ThisType, - "null", - true, - false, - }, - { - "error", - ThisType, - "null", - true, - true, - }, - } - - containsSuchField := func(name, ifTrue, ifFalse string) string { - for _, field := range trw.Fields { - if field.originalName == name { - return ifTrue - } - } - return ifFalse - } - - for _, field := range fields { - returnObject := field.Default - returnType := field.Default - if field.Type == ThisType && - strings.Contains(strings.ToLower(trw.PhpClassName(false, true)), strings.ToLower(field.Name)) { - returnObject = "$this" - returnType = trw.PhpTypeName(true, true) - } else { - if field.Type != ThisType { - returnObject = "$this->" + field.Name - returnType = field.Type - } - if field.NullTypeIfNullValue { - returnType = containsSuchField(field.Name, returnType, "null") - returnObject = containsSuchField(field.Name, returnObject, "null") - } - } - if field.AddHasMethod { - code.WriteString( - fmt.Sprintf( - ` - /** - * @return bool - */ - public function is%[1]s() { - return %[2]s; - } -`, - ToUpperFirst(field.Name), - containsSuchField(field.Name, "true", "false"), - ), - ) - } - code.WriteString( - fmt.Sprintf( - ` - /** - * @return %[3]s - */ - public function get%[1]s() { - return %[2]s; - } -`, - ToUpperFirst(field.Name), - returnObject, - returnType, - ), - ) - } -} - -func (trw *TypeRWStruct) PHPStructResultType(code *strings.Builder) { - // print result type for function - if trw.ResultType != nil { - code.WriteString( - fmt.Sprintf( - ` - /** Allows kphp implicitly load function result class */ - private const RESULT = %s_result::class; -`, - trw.PhpClassName(true, true), - ), - ) - } -} - -func (trw *TypeRWStruct) PHPStructFields(code *strings.Builder) { - // print fields declarations - for _, f := range trw.Fields { - fieldType, defaultValue := fieldTypeAndDefaultValue(f) - code.WriteString( - fmt.Sprintf( - ` - /** @var %[1]s */ - public $%[2]s = %[3]s; -`, - fieldType, - f.originalName, - defaultValue, - ), - ) - } -} - -func (trw *TypeRWStruct) PHPStructFieldMasks(code *strings.Builder) { - // print fieldmasks - for _, f := range trw.Fields { - if f.fieldMask == nil { - continue - } - code.WriteString( - fmt.Sprintf( - ` - /** Field mask for $%[1]s field */ - const BIT_%[2]s_%[3]d = (1 << %[3]d); -`, - f.originalName, - strings.ToUpper(f.originalName), - f.BitNumber, - ), - ) - } -} - -func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { - unionParent := trw.PhpConstructorNeedsUnion() - - if isUsingTLImport(trw) || - trw.ResultType != nil || - unionParent != nil { - code.WriteString("\nuse VK\\TL;\n") - } - code.WriteString(` -/** - * @kphp-tl-class - */ -`) - code.WriteString(fmt.Sprintf("class %s ", trw.PhpClassName(false, true))) - if unionParent != nil { - code.WriteString(fmt.Sprintf("implements %s ", unionParent.trw.PhpClassName(true, false))) - } - if trw.ResultType != nil { - code.WriteString("implements TL\\RpcFunction ") - } - code.WriteString("{\n") -} - -func phpResultType(trw *TypeRWStruct) string { - return trw.ResultType.trw.PhpTypeName(true, trw.ResultType.PHPIsBare()) -} - -func toPhpFieldMaskName(natName string) string { - parts := strings.Split(natName, "_") - for i := range parts { - parts[i] = ToUpperFirst(parts[i]) - } - return strings.Join(parts, "") -} - -func isUsingTLImport(trw *TypeRWStruct) bool { - for _, field := range trw.Fields { - fieldType, _ := fieldTypeAndDefaultValue(field) - if strings.Contains(fieldType, "TL\\") { - return true - } - } - return false -} - -func fieldTypeAndDefaultValue(f Field) (string, string) { - fieldType := f.t.trw.PhpTypeName(true, f.t.PHPIsBare()) - defaultValue := f.t.trw.PhpDefaultValue() - if f.t.PHPIsTrueType() { - fieldType = "boolean" - defaultValue = "true" - if f.fieldMask != nil { - defaultValue = "false" - } - } else { - if f.fieldMask != nil { - defaultValue = "null" - if _, isMaybe := f.t.PHPGenCoreType().trw.(*TypeRWMaybe); !isMaybe { - fieldType = fieldType + "|null" - } - } - } - return fieldType, defaultValue -} - -func (trw *TypeRWStruct) PhpDefaultValue() string { - core := trw.wr.PHPGenCoreType() - if core != trw.wr { - return core.PHPDefaultValue() - } - if core.PHPIsTrueType() { - return "true" - } - return "null" -} - -func (trw *TypeRWStruct) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { - for _, field := range trw.Fields { - field.t.PhpIterateReachableTypes(reachableTypes) - } - if trw.ResultType != nil { - trw.ResultType.PhpIterateReachableTypes(reachableTypes) - } -} - -func (trw *TypeRWStruct) PhpConstructorNeedsUnion() (unionParent *TypeRWWrapper) { - if trw.ResultType == nil { - if trw.wr.unionParent != nil { - return trw.wr.unionParent.wr - } else if !strings.EqualFold(trw.wr.tlName.Name, trw.wr.origTL[0].TypeDecl.Name.Name) { - // NOTE: constructor name is not same as type => type can become union in future? - return trw.wr - } - } - - return nil -} diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go new file mode 100644 index 0000000..95b7cf0 --- /dev/null +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -0,0 +1,621 @@ +package tlcodegen + +import ( + "fmt" + "github.com/vkcom/tl/internal/utils" + "sort" + "strings" +) + +func (trw *TypeRWStruct) PhpClassNameReplaced() bool { + unionParent := trw.PhpConstructorNeedsUnion() + if unionParent == nil { + if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { + return true + } + + if trw.ResultType == nil && trw.wr.PHPIsTrueType() { + return true + } + + isDict, _, _, _ := isDictionaryElement(trw.wr) + if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + return true + } + } + return false +} + +func (trw *TypeRWStruct) PhpClassName(withPath bool, bare bool) string { + if PHPSpecialMembersTypes(trw.wr) != "" { + return "" + } + unionParent := trw.PhpConstructorNeedsUnion() + if unionParent == nil { + if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { + return trw.Fields[0].t.trw.PhpClassName(withPath, bare) + } + + if trw.ResultType == nil && trw.wr.PHPIsTrueType() { + return "boolean" + } + + isDict, _, _, valueType := isDictionaryElement(trw.wr) + if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + return valueType.t.trw.PhpClassName(withPath, bare) + } + } + + name := trw.wr.tlName.Name + if !bare { + name = trw.wr.origTL[0].TypeDecl.Name.Name + } + if trw.wr.tlName.Namespace != "" { + name = fmt.Sprintf("%s_%s", trw.wr.tlName.Namespace, name) + } + + elems := make([]string, 0, len(trw.wr.arguments)) + for _, arg := range trw.wr.arguments { + if arg.tip != nil { + argText := arg.tip.trw.PhpClassName(false, false) + if argText != "" { + elems = append(elems, "__", argText) + } + } + } + + name += strings.Join(elems, "") + if withPath { + name = trw.wr.PHPTypePath() + name + } + return name +} + +func (trw *TypeRWStruct) PhpTypeName(withPath bool, bare bool) string { + if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { + return specialCase + } + unionParent := trw.PhpConstructorNeedsUnion() + if unionParent == nil { + if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { + return trw.Fields[0].t.trw.PhpTypeName(withPath, trw.Fields[0].bare) + } + isDict, _, _, valueType := isDictionaryElement(trw.wr) + if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + return valueType.t.trw.PhpTypeName(withPath, bare) + } + } + return trw.PhpClassName(withPath, bare) +} + +func (trw *TypeRWStruct) PhpGenerateCode(code *strings.Builder, bytes bool) error { + trw.PHPStructHeader(code) + trw.PHPStructFieldMasks(code) + trw.PHPStructFields(code) + trw.PHPStructResultType(code) + + necessaryFieldsInConstructor := make([]Field, 0) + usedFieldMasksIndecies := make([]int, 0) + usedFieldMasks := make(map[int][]Field) + for _, f := range trw.Fields { + if f.fieldMask == nil { + necessaryFieldsInConstructor = append(necessaryFieldsInConstructor, f) + } else { + index := f.fieldMask.FieldIndex + if !f.fieldMask.isField { + for i, argument := range trw.wr.origTL[0].TemplateArguments { + if argument.IsNat && argument.FieldName == f.fieldMask.name { + index = -(i + 1) + break + } + } + } + if usedFieldMasks[index] == nil { + usedFieldMasksIndecies = append(usedFieldMasksIndecies, index) + } + usedFieldMasks[index] = append(usedFieldMasks[index], f) + } + } + + trw.PHPStructConstructor(code, necessaryFieldsInConstructor) + trw.PHPStructRPCSpecialGetters(code) + trw.PHPStructFieldMaskCalculators(code, usedFieldMasksIndecies, usedFieldMasks) + trw.PHPStructFunctionSpecificMethods(code) + + code.WriteString("\n}\n") + + trw.PHPStructFunctionSpecificTypes(code) + return nil +} + +func (trw *TypeRWStruct) PHPStructFunctionSpecificTypes(code *strings.Builder) { + if trw.ResultType != nil { + code.WriteString( + fmt.Sprintf( + ` +/** + * @kphp-tl-class + */ +class %[1]s_result implements TL\RpcFunctionReturnResult { + + /** @var %[2]s */ + public $value = %[3]s; + +} +`, + trw.PhpClassName(false, true), + phpResultType(trw), + trw.ResultType.trw.PhpDefaultValue(), + ), + ) + } +} + +func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder) { + // print function specific methods and types + if trw.ResultType != nil { + kphpSpecialCode := "" + if trw.wr.HasAnnotation("kphp") { + kphpSpecialCode = fmt.Sprintf( + ` + + /** + * @param %[1]s $value + * @return %[2]s_result + */ + public static function createRpcServerResponse($value) { + $response = new %[2]s_result(); + $response->value = $value; + return $response; + }`, + trw.ResultType.trw.PhpTypeName(true, true), + trw.PhpClassName(true, true), + ) + } + + code.WriteString( + fmt.Sprintf( + ` + /** + * @param TL\RpcFunctionReturnResult $function_return_result + * @return %[4]s + */ + public static function functionReturnValue($function_return_result) { + if ($function_return_result instanceof %[1]s_result) { + return $function_return_result->value; + } + warning('Unexpected result type in functionReturnValue: ' . ($function_return_result ? get_class($function_return_result) : 'null')); + return (new %[1]s_result())->value; + } + + /** + * @kphp-inline + * + * @param TL\RpcResponse $response + * @return %[4]s + */ + public static function result(TL\RpcResponse $response) { + return self::functionReturnValue($response->getResult()); + }%[5]s + + /** + * @kphp-inline + * + * @return string + */ + public function getTLFunctionName() { + return '%[3]s'; + } +`, + trw.PhpClassName(false, true), + trw.PhpClassName(true, true), + trw.wr.tlName.String(), + phpResultType(trw), + kphpSpecialCode, + ), + ) + + } +} + +func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, usedFieldMasksIndecies []int, usedFieldMasks map[int][]Field) { + // print methods to calculate fieldmasks + // fix order + names := utils.MapSlice(usedFieldMasksIndecies, func(natIndex int) string { + natName := "" + if natIndex < 0 { + natName = trw.wr.origTL[0].TemplateArguments[-(natIndex + 1)].FieldName + } else { + natName = trw.Fields[natIndex].originalName + } + return natName + }) + + namesToIndices := make(map[string]int) + for i := range names { + namesToIndices[names[i]] = usedFieldMasksIndecies[i] + } + sort.Strings(names) + + fieldNameToFieldOrder := make(map[string]int) + for i := range trw.Fields { + fieldNameToFieldOrder[trw.Fields[i].originalName] = i + } + + for _, name := range names { + natIndex := namesToIndices[name] + natName := name + code.WriteString(` + /**`) + additionalArgs := make([]string, 0) + // arguments with ambiguous existence + for _, dependentField := range usedFieldMasks[natIndex] { + if _, isMaybe := dependentField.t.PHPGenCoreType().trw.(*TypeRWMaybe); isMaybe { + additionalArgs = append(additionalArgs, fmt.Sprintf("$has_%s", dependentField.originalName)) + code.WriteString(fmt.Sprintf("\n * @param bool $has_%s", dependentField.originalName)) + } + } + code.WriteString(` + * @return int + */ +`, + ) + code.WriteString( + fmt.Sprintf( + " public function calculate%[1]s(%[2]s) {\n $mask = 0;\n", + toPhpFieldMaskName(natName), + strings.Join(additionalArgs, ", "), + ), + ) + + fields := usedFieldMasks[natIndex] + sort.Slice(fields, func(i, j int) bool { + if fields[i].BitNumber == fields[j].BitNumber { + return i < j + } + return fields[i].BitNumber < fields[j].BitNumber + }) + + fieldsGroupedByBitNumber := make([][]Field, 0) + for _, dependentField := range fields { + if len(fieldsGroupedByBitNumber) == 0 || + fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1][0].BitNumber != dependentField.BitNumber { + fieldsGroupedByBitNumber = append(fieldsGroupedByBitNumber, make([]Field, 0)) + } + fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1] = append(fieldsGroupedByBitNumber[len(fieldsGroupedByBitNumber)-1], dependentField) + } + + for _, dependentFields := range fieldsGroupedByBitNumber { + conditions := make([]string, 0) + bitConstants := make([]string, 0) + sort.Slice(dependentFields, func(i, j int) bool { + return fieldNameToFieldOrder[dependentFields[i].originalName] < fieldNameToFieldOrder[dependentFields[j].originalName] + }) + for _, dependentField := range dependentFields { + condition := "" + if dependentField.t.PHPIsTrueType() || dependentField.t.PHPNeedsCode() { + condition = fmt.Sprintf( + "$this->%[1]s", + dependentField.originalName, + ) + } else if _, isMaybe := dependentField.t.PHPGenCoreType().trw.(*TypeRWMaybe); isMaybe { + condition = fmt.Sprintf("$has_%s", dependentField.originalName) + } else { + condition = fmt.Sprintf( + "$this->%[1]s !== null", + dependentField.originalName, + ) + } + conditions = append(conditions, condition) + bitConstants = append(bitConstants, fmt.Sprintf( + "self::BIT_%[1]s_%[2]d", + strings.ToUpper(dependentField.originalName), + dependentField.BitNumber)) + } + + finalCondition := conditions[0] + finalMask := bitConstants[0] + + if len(conditions) > 1 { + finalCondition = strings.Join(conditions, " && ") + finalMask = "(" + strings.Join(bitConstants, " | ") + ")" + } + + code.WriteString( + fmt.Sprintf( + ` + if (%[1]s) { + $mask |= %[2]s; + } +`, + finalCondition, + finalMask, + ), + ) + } + + code.WriteString("\n return $mask;\n") + code.WriteString(" }\n") + } +} + +func (trw *TypeRWStruct) PHPStructConstructor(code *strings.Builder, necessaryFieldsInConstructor []Field) { + // print constructor + code.WriteString(` + /** +`) + for _, f := range necessaryFieldsInConstructor { + fieldType, _ := fieldTypeAndDefaultValue(f) + code.WriteString(fmt.Sprintf(" * @param %[1]s $%[2]s\n", fieldType, f.originalName)) + } + if len(necessaryFieldsInConstructor) == 0 { + code.WriteString(" * @kphp-inline\n") + } + + code.WriteString(` */ +`) + code.WriteString(" public function __construct(") + + for i, f := range necessaryFieldsInConstructor { + _, defaultValue := fieldTypeAndDefaultValue(f) + if i != 0 { + code.WriteString(", ") + } + code.WriteString(fmt.Sprintf("$%[1]s = %[2]s", f.originalName, defaultValue)) + } + + code.WriteString(") {\n") + for _, f := range necessaryFieldsInConstructor { + code.WriteString(fmt.Sprintf(" $this->%[1]s = $%[1]s;\n", f.originalName)) + } + code.WriteString(" }\n") +} + +func (trw *TypeRWStruct) PHPStructRPCSpecialGetters(code *strings.Builder) { + if unionParent := trw.wr.PHPUnionParent(); unionParent == nil || PHPSpecialMembersTypes(unionParent) == "" { + return + } + + const ThisType = "__this" + type SpecialField struct { + Name string + Type string + Default string + NullTypeIfNullValue bool + AddHasMethod bool + } + + fields := []SpecialField{ + { + "result", + "TL\\RpcFunctionReturnResult", + "null", + true, + false, + }, + { + "header", + ThisType, + "null", + true, + false, + }, + { + "error", + ThisType, + "null", + true, + true, + }, + } + + containsSuchField := func(name, ifTrue, ifFalse string) string { + for _, field := range trw.Fields { + if field.originalName == name { + return ifTrue + } + } + return ifFalse + } + + for _, field := range fields { + returnObject := field.Default + returnType := field.Default + if field.Type == ThisType && + strings.Contains(strings.ToLower(trw.PhpClassName(false, true)), strings.ToLower(field.Name)) { + returnObject = "$this" + returnType = trw.PhpTypeName(true, true) + } else { + if field.Type != ThisType { + returnObject = "$this->" + field.Name + returnType = field.Type + } + if field.NullTypeIfNullValue { + returnType = containsSuchField(field.Name, returnType, "null") + returnObject = containsSuchField(field.Name, returnObject, "null") + } + } + if field.AddHasMethod { + code.WriteString( + fmt.Sprintf( + ` + /** + * @return bool + */ + public function is%[1]s() { + return %[2]s; + } +`, + ToUpperFirst(field.Name), + containsSuchField(field.Name, "true", "false"), + ), + ) + } + code.WriteString( + fmt.Sprintf( + ` + /** + * @return %[3]s + */ + public function get%[1]s() { + return %[2]s; + } +`, + ToUpperFirst(field.Name), + returnObject, + returnType, + ), + ) + } +} + +func (trw *TypeRWStruct) PHPStructResultType(code *strings.Builder) { + // print result type for function + if trw.ResultType != nil { + code.WriteString( + fmt.Sprintf( + ` + /** Allows kphp implicitly load function result class */ + private const RESULT = %s_result::class; +`, + trw.PhpClassName(true, true), + ), + ) + } +} + +func (trw *TypeRWStruct) PHPStructFields(code *strings.Builder) { + // print fields declarations + for _, f := range trw.Fields { + fieldType, defaultValue := fieldTypeAndDefaultValue(f) + code.WriteString( + fmt.Sprintf( + ` + /** @var %[1]s */ + public $%[2]s = %[3]s; +`, + fieldType, + f.originalName, + defaultValue, + ), + ) + } +} + +func (trw *TypeRWStruct) PHPStructFieldMasks(code *strings.Builder) { + // print fieldmasks + for _, f := range trw.Fields { + if f.fieldMask == nil { + continue + } + code.WriteString( + fmt.Sprintf( + ` + /** Field mask for $%[1]s field */ + const BIT_%[2]s_%[3]d = (1 << %[3]d); +`, + f.originalName, + strings.ToUpper(f.originalName), + f.BitNumber, + ), + ) + } +} + +func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { + unionParent := trw.PhpConstructorNeedsUnion() + + if isUsingTLImport(trw) || + trw.ResultType != nil || + unionParent != nil { + code.WriteString("\nuse VK\\TL;\n") + } + code.WriteString(` +/** + * @kphp-tl-class + */ +`) + code.WriteString(fmt.Sprintf("class %s ", trw.PhpClassName(false, true))) + if unionParent != nil { + code.WriteString(fmt.Sprintf("implements %s ", unionParent.trw.PhpClassName(true, false))) + } + if trw.ResultType != nil { + code.WriteString("implements TL\\RpcFunction ") + } + code.WriteString("{\n") +} + +func phpResultType(trw *TypeRWStruct) string { + return trw.ResultType.trw.PhpTypeName(true, trw.ResultType.PHPIsBare()) +} + +func toPhpFieldMaskName(natName string) string { + parts := strings.Split(natName, "_") + for i := range parts { + parts[i] = ToUpperFirst(parts[i]) + } + return strings.Join(parts, "") +} + +func isUsingTLImport(trw *TypeRWStruct) bool { + for _, field := range trw.Fields { + fieldType, _ := fieldTypeAndDefaultValue(field) + if strings.Contains(fieldType, "TL\\") { + return true + } + } + return false +} + +func fieldTypeAndDefaultValue(f Field) (string, string) { + fieldType := f.t.trw.PhpTypeName(true, f.t.PHPIsBare()) + defaultValue := f.t.trw.PhpDefaultValue() + if f.t.PHPIsTrueType() { + fieldType = "boolean" + defaultValue = "true" + if f.fieldMask != nil { + defaultValue = "false" + } + } else { + if f.fieldMask != nil { + defaultValue = "null" + if _, isMaybe := f.t.PHPGenCoreType().trw.(*TypeRWMaybe); !isMaybe { + fieldType = fieldType + "|null" + } + } + } + return fieldType, defaultValue +} + +func (trw *TypeRWStruct) PhpDefaultValue() string { + core := trw.wr.PHPGenCoreType() + if core != trw.wr { + return core.PHPDefaultValue() + } + if core.PHPIsTrueType() { + return "true" + } + return "null" +} + +func (trw *TypeRWStruct) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { + for _, field := range trw.Fields { + field.t.PhpIterateReachableTypes(reachableTypes) + } + if trw.ResultType != nil { + trw.ResultType.PhpIterateReachableTypes(reachableTypes) + } +} + +func (trw *TypeRWStruct) PhpConstructorNeedsUnion() (unionParent *TypeRWWrapper) { + if trw.ResultType == nil { + if trw.wr.unionParent != nil { + return trw.wr.unionParent.wr + } else if !strings.EqualFold(trw.wr.tlName.Name, trw.wr.origTL[0].TypeDecl.Name.Name) { + // NOTE: constructor name is not same as type => type can become union in future? + return trw.wr + } + } + + return nil +} diff --git a/internal/tlcodegen/type_rw_tuple.go b/internal/tlcodegen/type_rw_tuple.go index 2dacc5d..7757855 100644 --- a/internal/tlcodegen/type_rw_tuple.go +++ b/internal/tlcodegen/type_rw_tuple.go @@ -210,39 +210,3 @@ func (trw *TypeRWBrackets) typeJSON2ReadingCode(bytesVersion bool, directImports goGlobalName := addBytes(trw.wr.goGlobalName, bytesVersion) return fmt.Sprintf("if err := %sReadJSON(legacyTypeNames, %s, %s%s); err != nil { return err }", trw.wr.ins.Prefix(directImports, ins)+goGlobalName, jvalue, addAmpersand(ref, val), joinWithCommas(natArgs)) } - -func (trw *TypeRWBrackets) PhpClassName(withPath bool, bare bool) string { - if strings.HasPrefix(trw.wr.tlName.String(), BuiltinTupleName) || - strings.HasPrefix(trw.wr.tlName.String(), BuiltinVectorName) { - return "array_" + trw.element.t.trw.PhpClassName(false, false) - } - return fmt.Sprintf("", trw.wr.goGlobalName) -} - -func (trw *TypeRWBrackets) PhpClassNameReplaced() bool { - return true -} - -func (trw *TypeRWBrackets) PhpTypeName(withPath bool, bare bool) string { - if strings.HasPrefix(trw.wr.tlName.String(), BuiltinTupleName) || - strings.HasPrefix(trw.wr.tlName.String(), BuiltinVectorName) { - elementText := trw.element.t.trw.PhpTypeName(withPath, trw.element.t.PHPIsBare()) - if _, ok := trw.element.t.trw.(*TypeRWMaybe); ok { - elementText = "(" + elementText + ")" - } - return elementText + "[]" - } - return fmt.Sprintf("", trw.wr.goGlobalName) -} - -func (trw *TypeRWBrackets) PhpGenerateCode(code *strings.Builder, bytes bool) error { - return fmt.Errorf("tuples don't have php code") -} - -func (trw *TypeRWBrackets) PhpDefaultValue() string { - return "[]" -} - -func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { - trw.element.t.PhpIterateReachableTypes(reachableTypes) -} diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go new file mode 100644 index 0000000..6e99c3c --- /dev/null +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -0,0 +1,42 @@ +package tlcodegen + +import ( + "fmt" + "strings" +) + +func (trw *TypeRWBrackets) PhpClassName(withPath bool, bare bool) string { + if strings.HasPrefix(trw.wr.tlName.String(), BuiltinTupleName) || + strings.HasPrefix(trw.wr.tlName.String(), BuiltinVectorName) { + return "array_" + trw.element.t.trw.PhpClassName(false, false) + } + return fmt.Sprintf("", trw.wr.goGlobalName) +} + +func (trw *TypeRWBrackets) PhpClassNameReplaced() bool { + return true +} + +func (trw *TypeRWBrackets) PhpTypeName(withPath bool, bare bool) string { + if strings.HasPrefix(trw.wr.tlName.String(), BuiltinTupleName) || + strings.HasPrefix(trw.wr.tlName.String(), BuiltinVectorName) { + elementText := trw.element.t.trw.PhpTypeName(withPath, trw.element.t.PHPIsBare()) + if _, ok := trw.element.t.trw.(*TypeRWMaybe); ok { + elementText = "(" + elementText + ")" + } + return elementText + "[]" + } + return fmt.Sprintf("", trw.wr.goGlobalName) +} + +func (trw *TypeRWBrackets) PhpGenerateCode(code *strings.Builder, bytes bool) error { + return fmt.Errorf("tuples don't have php code") +} + +func (trw *TypeRWBrackets) PhpDefaultValue() string { + return "[]" +} + +func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { + trw.element.t.PhpIterateReachableTypes(reachableTypes) +} diff --git a/internal/tlcodegen/type_rw_union.go b/internal/tlcodegen/type_rw_union.go index 89f9587..21e5bf1 100644 --- a/internal/tlcodegen/type_rw_union.go +++ b/internal/tlcodegen/type_rw_union.go @@ -8,8 +8,6 @@ package tlcodegen import ( "fmt" - "github.com/vkcom/tl/internal/utils" - "strings" ) type TypeRWUnion struct { @@ -190,80 +188,3 @@ func (trw *TypeRWUnion) HasShortFieldCollision(wr *TypeRWWrapper) bool { } return false } - -func (trw *TypeRWUnion) PhpClassNameReplaced() bool { - return false -} - -func (trw *TypeRWUnion) PhpClassName(withPath bool, bare bool) string { - if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { - return specialCase - } - name := trw.wr.tlName.Name - if len(trw.wr.tlName.Namespace) != 0 { - name = fmt.Sprintf("%s_%s", trw.wr.tlName.Namespace, name) - } - - elems := make([]string, 0, len(trw.wr.arguments)) - for _, arg := range trw.wr.arguments { - if arg.tip != nil { - argText := arg.tip.trw.PhpClassName(false, false) - if argText != "" { - elems = append(elems, "__", argText) - } - } - } - - name += strings.Join(elems, "") - if withPath { - name = trw.wr.PHPTypePath() + name - } - return name -} - -func (trw *TypeRWUnion) PhpTypeName(withPath bool, bare bool) string { - return trw.PhpClassName(withPath, true) -} - -func (trw *TypeRWUnion) PhpGenerateCode(code *strings.Builder, bytes bool) error { - return PhpGenerateInterfaceCode(code, bytes, trw.wr, utils.MapSlice(trw.Fields, func(f Field) *TypeRWWrapper { return f.t })) -} - -func PhpGenerateInterfaceCode(code *strings.Builder, bytes bool, targetType *TypeRWWrapper, itsConstructors []*TypeRWWrapper) error { - constructors := make([]string, len(itsConstructors)) - for i, constructor := range itsConstructors { - constructors[i] = fmt.Sprintf("%s::class", constructor.trw.PhpClassName(true, true)) - } - - code.WriteString(` -use VK\TL; - -/** - * @kphp-tl-class - */ -`) - code.WriteString(fmt.Sprintf( - `interface %[1]s { - - /** Allows kphp implicitly load all available constructors */ - const CONSTRUCTORS = [ - %[2]s - ]; - -} -`, - targetType.trw.PhpClassName(false, false), - strings.Join(constructors, ",\n "), - )) - return nil -} - -func (trw *TypeRWUnion) PhpDefaultValue() string { - return "null" -} - -func (trw *TypeRWUnion) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { - for _, field := range trw.Fields { - field.t.PhpIterateReachableTypes(reachableTypes) - } -} diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go new file mode 100644 index 0000000..561176d --- /dev/null +++ b/internal/tlcodegen/type_rw_union_php.go @@ -0,0 +1,84 @@ +package tlcodegen + +import ( + "fmt" + "github.com/vkcom/tl/internal/utils" + "strings" +) + +func (trw *TypeRWUnion) PhpClassNameReplaced() bool { + return false +} + +func (trw *TypeRWUnion) PhpClassName(withPath bool, bare bool) string { + if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { + return specialCase + } + name := trw.wr.tlName.Name + if len(trw.wr.tlName.Namespace) != 0 { + name = fmt.Sprintf("%s_%s", trw.wr.tlName.Namespace, name) + } + + elems := make([]string, 0, len(trw.wr.arguments)) + for _, arg := range trw.wr.arguments { + if arg.tip != nil { + argText := arg.tip.trw.PhpClassName(false, false) + if argText != "" { + elems = append(elems, "__", argText) + } + } + } + + name += strings.Join(elems, "") + if withPath { + name = trw.wr.PHPTypePath() + name + } + return name +} + +func (trw *TypeRWUnion) PhpTypeName(withPath bool, bare bool) string { + return trw.PhpClassName(withPath, true) +} + +func (trw *TypeRWUnion) PhpGenerateCode(code *strings.Builder, bytes bool) error { + return PhpGenerateInterfaceCode(code, bytes, trw.wr, utils.MapSlice(trw.Fields, func(f Field) *TypeRWWrapper { return f.t })) +} + +func PhpGenerateInterfaceCode(code *strings.Builder, bytes bool, targetType *TypeRWWrapper, itsConstructors []*TypeRWWrapper) error { + constructors := make([]string, len(itsConstructors)) + for i, constructor := range itsConstructors { + constructors[i] = fmt.Sprintf("%s::class", constructor.trw.PhpClassName(true, true)) + } + + code.WriteString(` +use VK\TL; + +/** + * @kphp-tl-class + */ +`) + code.WriteString(fmt.Sprintf( + `interface %[1]s { + + /** Allows kphp implicitly load all available constructors */ + const CONSTRUCTORS = [ + %[2]s + ]; + +} +`, + targetType.trw.PhpClassName(false, false), + strings.Join(constructors, ",\n "), + )) + return nil +} + +func (trw *TypeRWUnion) PhpDefaultValue() string { + return "null" +} + +func (trw *TypeRWUnion) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { + for _, field := range trw.Fields { + field.t.PhpIterateReachableTypes(reachableTypes) + } +} From 032f719aba3d39d4ead521b2b6d8c3bab106c6e8 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Sat, 28 Dec 2024 21:14:38 +0300 Subject: [PATCH 02/37] read draft --- internal/tlcodegen/tlgen_kernel.go | 4 + .../{tlgen_cpp.go => tlgen_lang_cpp.go} | 15 ++ .../{tlgen_go.go => tlgen_lang_go.go} | 0 .../{tlgen_php.go => tlgen_lang_php.go} | 32 ++- internal/tlcodegen/type_rw.go | 102 +++++++-- internal/tlcodegen/type_rw_bool_php.go | 21 ++ internal/tlcodegen/type_rw_maybe_php.go | 39 ++++ internal/tlcodegen/type_rw_primitive_php.go | 29 +++ internal/tlcodegen/type_rw_struct_php.go | 201 ++++++++++++++++++ internal/tlcodegen/type_rw_tuple_cpp.go | 1 + internal/tlcodegen/type_rw_tuple_php.go | 86 ++++++++ internal/tlcodegen/type_rw_union_php.go | 37 ++++ 12 files changed, 542 insertions(+), 25 deletions(-) rename internal/tlcodegen/{tlgen_cpp.go => tlgen_lang_cpp.go} (95%) rename internal/tlcodegen/{tlgen_go.go => tlgen_lang_go.go} (100%) rename internal/tlcodegen/{tlgen_php.go => tlgen_lang_php.go} (84%) diff --git a/internal/tlcodegen/tlgen_kernel.go b/internal/tlcodegen/tlgen_kernel.go index 8521826..38f3a78 100644 --- a/internal/tlcodegen/tlgen_kernel.go +++ b/internal/tlcodegen/tlgen_kernel.go @@ -205,6 +205,10 @@ func (gen *Gen2) getType(lrc LocalResolveContext, t tlast.TypeRef, unionParent * func (gen *Gen2) generateType(myWrapper *TypeRWWrapper) error { tlType := myWrapper.origTL + if tlType[0].Construct.Name.String() == "test.dataIgnoreFlags" { + print("debug") + } + lrc := LocalResolveContext{ localTypeArgs: map[string]LocalTypeArg{}, localNatArgs: map[string]LocalNatArg{}, diff --git a/internal/tlcodegen/tlgen_cpp.go b/internal/tlcodegen/tlgen_lang_cpp.go similarity index 95% rename from internal/tlcodegen/tlgen_cpp.go rename to internal/tlcodegen/tlgen_lang_cpp.go index b9aaa00..5aeb165 100644 --- a/internal/tlcodegen/tlgen_cpp.go +++ b/internal/tlcodegen/tlgen_lang_cpp.go @@ -15,6 +15,21 @@ import ( "strings" ) +type TypeRWCPPData interface { + CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) + cppTypeStringInNamespace(bytesVersion bool, hppInc *DirectIncludesCPP) string + cppTypeStringInNamespaceHalfResolved2(bytesVersion bool, typeReduction EvaluatedType) string + cppTypeStringInNamespaceHalfResolved(bytesVersion bool, hppInc *DirectIncludesCPP, halfResolved HalfResolvedArgument) string + cppDefaultInitializer(halfResolved HalfResolvedArgument, halfResolve bool) string + CPPHasBytesVersion() bool + CPPTypeResettingCode(bytesVersion bool, val string) string + CPPTypeWritingJsonCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string + CPPTypeWritingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string + CPPTypeReadingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string + CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string + CPPGenerateCode(hpp *strings.Builder, hppInc *DirectIncludesCPP, hppIncFwd *DirectIncludesCPP, hppDet *strings.Builder, hppDetInc *DirectIncludesCPP, cppDet *strings.Builder, cppDetInc *DirectIncludesCPP, bytesVersion bool, forwardDeclaration bool) +} + func cppStartNamespace(s *strings.Builder, ns []string) { for _, n := range ns { s.WriteString(fmt.Sprintf("namespace %s { ", n)) diff --git a/internal/tlcodegen/tlgen_go.go b/internal/tlcodegen/tlgen_lang_go.go similarity index 100% rename from internal/tlcodegen/tlgen_go.go rename to internal/tlcodegen/tlgen_lang_go.go diff --git a/internal/tlcodegen/tlgen_php.go b/internal/tlcodegen/tlgen_lang_php.go similarity index 84% rename from internal/tlcodegen/tlgen_php.go rename to internal/tlcodegen/tlgen_lang_php.go index 22a32f5..89c42a8 100644 --- a/internal/tlcodegen/tlgen_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -6,6 +6,19 @@ import ( "strings" ) +type TypeRWPHPData interface { + PhpClassName(withPath bool, bare bool) string + PhpClassNameReplaced() bool + PhpTypeName(withPath bool, bare bool) string + PhpGenerateCode(code *strings.Builder, bytes bool) error + // PhpDefaultInit return not null type initialization value + PhpDefaultInit() string + // PhpDefaultValue return default value for field of this type (can be null) + PhpDefaultValue() string + PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) + PhpReadMethodCall(targetName string, bare bool, args []string) []string +} + type PhpClassMeta struct { UsedOnlyInInternal bool UsedInFunctions bool @@ -33,15 +46,20 @@ func (gen *Gen2) generateCodePHP(generateByteVersions []string) error { createdTypes := make(map[string]bool) for _, wrapper := range gen.generatedTypesList { - if wrapper.trw.PhpClassName(false, true) == "logs2_dictionarySetInfo" { - print("debug") - } if createdTypes[wrapper.trw.PhpClassName(true, true)] { continue } if !wrapper.PHPNeedsCode() { continue } + fmt.Println(fmt.Sprintf( + "PHP{%[1]s} in GO{%[2]s}", + wrapper.trw.PhpClassName(false, true), + wrapper.goGlobalName, + wrapper.NatParams, + wrapper.origTL[0].TemplateArguments, + wrapper.arguments), + ) err := phpGenerateCodeForWrapper(gen, wrapper, createdTypes, true, wrapper.PHPGenerateCode) if err != nil { return err @@ -159,3 +177,11 @@ func PHPSpecialMembersTypes(wrapper *TypeRWWrapper) string { } return "" } + +func phpFormatArgs(args []string) string { + s := "" + for _, arg := range args { + s += ", " + arg + } + return s +} diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index c4f99a5..c2e4113 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -8,6 +8,7 @@ package tlcodegen import ( "fmt" + "github.com/vkcom/tl/internal/utils" "golang.org/x/exp/slices" "regexp" "strconv" @@ -633,6 +634,84 @@ func (w *TypeRWWrapper) PHPNeedsCode() bool { return !w.trw.PhpClassNameReplaced() } +type TypeArgumentsTree struct { + value string + leaf bool + children []*TypeArgumentsTree +} + +func (t *TypeArgumentsTree) IsEmpty() bool { + if t.leaf { + return false + } + for _, child := range t.children { + if child != nil && !child.IsEmpty() { + return false + } + } + return true +} + +func (t *TypeArgumentsTree) EnumerateWithPrefixes() []string { + const natPrefix = "" + values := make([]string, 0) + t.enumerateWithPrefixes(&values, "") + values = utils.MapSlice(values, func(s string) string { return natPrefix + s }) + return values +} + +func (t *TypeArgumentsTree) EnumerateSubTreeWithPrefixes(childIndex int) []string { + if !(0 <= childIndex && childIndex < len(t.children)) { + panic("no such subtree") + } + ct := *t + ct.children = []*TypeArgumentsTree{t.children[childIndex]} + return ct.EnumerateWithPrefixes() +} + +func (t *TypeArgumentsTree) enumerateWithPrefixes(values *[]string, curPrefix string) { + const delimiter = "_" + if t.leaf { + *values = append(*values, curPrefix) + } else { + for _, child := range t.children { + if child != nil { + prefix := curPrefix + child.value + if !child.leaf { + prefix += delimiter + } + child.enumerateWithPrefixes(values, prefix) + } + } + } +} + +func (w *TypeRWWrapper) PHPGetNatTypeDependenciesDeclAsArray() []string { + t := TypeArgumentsTree{} + w.PHPGetNatTypeDependenciesDecl(&t) + return t.EnumerateWithPrefixes() +} + +func (w *TypeRWWrapper) PHPGetNatTypeDependenciesDecl(tree *TypeArgumentsTree) { + for i, template := range w.origTL[0].TemplateArguments { + tree.children = append(tree.children, nil) + actualArg := w.arguments[i] + if template.IsNat { + tree.children[i] = &TypeArgumentsTree{} + tree.children[i].leaf = true + tree.children[i].value = template.FieldName + } else { + tree.children[i] = &TypeArgumentsTree{} + tree.children[i].leaf = false + tree.children[i].value = template.FieldName + actualArg.tip.PHPGetNatTypeDependenciesDecl(tree.children[i]) + if tree.children[i].IsEmpty() { + tree.children[i] = nil + } + } + } +} + func (w *TypeRWWrapper) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { if (*reachableTypes)[w] { return @@ -877,15 +956,6 @@ outer: return result } -type TypeRWPHPData interface { - PhpClassName(withPath bool, bare bool) string - PhpClassNameReplaced() bool - PhpTypeName(withPath bool, bare bool) string - PhpGenerateCode(code *strings.Builder, bytes bool) error - PhpDefaultValue() string - PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) -} - // TODO remove skipAlias after we start generating go code like we do for C++ type TypeRW interface { // methods below are target language independent @@ -918,19 +988,7 @@ type TypeRW interface { typeJSON2ReadingCode(bytesVersion bool, directImports *DirectImports, ins *InternalNamespace, jvalue string, val string, natArgs []string, ref bool) string GenerateCode(bytesVersion bool, directImports *DirectImports) string - CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) - cppTypeStringInNamespace(bytesVersion bool, hppInc *DirectIncludesCPP) string - cppTypeStringInNamespaceHalfResolved2(bytesVersion bool, typeReduction EvaluatedType) string - cppTypeStringInNamespaceHalfResolved(bytesVersion bool, hppInc *DirectIncludesCPP, halfResolved HalfResolvedArgument) string - cppDefaultInitializer(halfResolved HalfResolvedArgument, halfResolve bool) string - CPPHasBytesVersion() bool - CPPTypeResettingCode(bytesVersion bool, val string) string - CPPTypeWritingJsonCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string - CPPTypeWritingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string - CPPTypeReadingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string - CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string - CPPGenerateCode(hpp *strings.Builder, hppInc *DirectIncludesCPP, hppIncFwd *DirectIncludesCPP, hppDet *strings.Builder, hppDetInc *DirectIncludesCPP, cppDet *strings.Builder, cppDetInc *DirectIncludesCPP, bytesVersion bool, forwardDeclaration bool) - + TypeRWCPPData TypeRWPHPData } diff --git a/internal/tlcodegen/type_rw_bool_php.go b/internal/tlcodegen/type_rw_bool_php.go index 1a2097b..cfcff5a 100644 --- a/internal/tlcodegen/type_rw_bool_php.go +++ b/internal/tlcodegen/type_rw_bool_php.go @@ -27,3 +27,24 @@ func (trw *TypeRWBool) PhpDefaultValue() string { func (trw *TypeRWBool) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { } + +func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + return []string{ + fmt.Sprintf( + "[%[1]s, $success] = $stream->read_bool(0x%08[2]x, 0x%08[3]x);", + targetName, + trw.falseTag, + trw.trueTag, + ), + "if (!$success) {", + " return false;", + "}", + } + } + return nil +} + +func (trw *TypeRWBool) PhpDefaultInit() string { + return "false" +} diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index b3805cc..9841237 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -38,3 +38,42 @@ func (trw *TypeRWMaybe) PhpDefaultValue() string { func (trw *TypeRWMaybe) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { trw.element.t.PhpIterateReachableTypes(reachableTypes) } + +func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + result := []string{ + fmt.Sprintf( + "[$maybeContainsValue, $success] = $stream->read_bool(0x%08[1]x, 0x%08[2]x)", + trw.emptyTag, + trw.okTag, + ), + "if (!$success) {", + " return false;", + "}", + "if ($maybeContainsValue) {", + } + if trw.element.t == trw.getInnerTarget().t { + result = append(result, + fmt.Sprintf(" if (%[1]s == null) {", targetName), + fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.element.t.trw.PhpDefaultInit()), + " }", + ) + } + bodyReader := trw.element.t.trw.PhpReadMethodCall(targetName, trw.element.bare, args) + for i, _ := range bodyReader { + bodyReader[i] = " " + bodyReader[i] + } + result = append(result, bodyReader...) + result = append(result, + "} else {", + fmt.Sprintf(" %[1]s = null;", targetName), + "}", + ) + return result + } + return nil +} + +func (trw *TypeRWMaybe) PhpDefaultInit() string { + return trw.element.t.trw.PhpDefaultInit() +} diff --git a/internal/tlcodegen/type_rw_primitive_php.go b/internal/tlcodegen/type_rw_primitive_php.go index 81438f6..a5b0bba 100644 --- a/internal/tlcodegen/type_rw_primitive_php.go +++ b/internal/tlcodegen/type_rw_primitive_php.go @@ -44,3 +44,32 @@ func (trw *TypeRWPrimitive) PhpDefaultValue() string { } func (trw *TypeRWPrimitive) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) {} + +func (trw *TypeRWPrimitive) phpIOMethodsSuffix() string { + switch trw.goType { + case "int32", "int64", "uint32", "string": + return trw.goType + case "float32": + return "float" + case "float64": + return "double" + default: + return fmt.Sprintf("", trw.tlType) + } +} + +func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + panic("can't be boxed") + } + return []string{ + fmt.Sprintf("[%[1]s, $success] = $stream->read_%[2]s();", targetName, trw.phpIOMethodsSuffix()), + "if (!$success) {", + " return false;", + "}", + } +} + +func (trw *TypeRWPrimitive) PhpDefaultInit() string { + return trw.PhpDefaultValue() +} diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 95b7cf0..64a4cb5 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -2,11 +2,84 @@ package tlcodegen import ( "fmt" + "github.com/vkcom/tl/internal/tlast" "github.com/vkcom/tl/internal/utils" "sort" + "strconv" "strings" ) +func (trw *TypeRWStruct) PHPFindNatByName(name string) (localNat bool, indexInDeps int) { + for i, field := range trw.Fields { + if field.originalName == name { + return true, i + } + } + for i, argument := range trw.wr.origTL[0].TemplateArguments { + if argument.FieldName == name { + return false, i + } + } + panic(fmt.Sprintf("no such nat \"%s\"", name)) +} + +func (trw *TypeRWStruct) PHPGetFieldNatDependenciesValues(fieldIndex int) []string { + field := trw.Fields[fieldIndex] + argsValues := make([]string, 0) + currentType := field.t + trw.phpGetFieldArgs(currentType, &field.origTL.FieldType, &argsValues) + return argsValues +} + +func (trw *TypeRWStruct) PHPGetFieldMask(fieldIndex int) string { + fieldMask := trw.Fields[fieldIndex].fieldMask + if fieldMask != nil { + if fieldMask.isField { + return fmt.Sprintf("$this->%s", trw.Fields[fieldMask.FieldIndex].originalName) + } + return "$" + fieldMask.name + } + + return "" +} + +func (trw *TypeRWStruct) phpGetFieldArgs(currentType *TypeRWWrapper, currentTypeRef *tlast.TypeRef, argsValues *[]string) { + if len(currentTypeRef.Args) != len(currentType.origTL[0].TemplateArguments) { + generic := currentTypeRef.Type.String() + index := -1 + for i, arg := range trw.wr.origTL[0].TemplateArguments { + if arg.FieldName == generic { + index = i + break + } + } + var args TypeArgumentsTree + trw.wr.PHPGetNatTypeDependenciesDecl(&args) + for _, arg := range args.EnumerateSubTreeWithPrefixes(index) { + *argsValues = append(*argsValues, fmt.Sprintf("$%s", arg)) + } + return + } + for i, _ := range currentType.origTL[0].TemplateArguments { + actualArg := currentType.arguments[i] + if actualArg.isNat { + if actualArg.isArith { + *argsValues = append(*argsValues, strconv.FormatUint(uint64(actualArg.Arith.Res), 10)) + } else { + isLocal, index := trw.PHPFindNatByName(currentTypeRef.Args[i].T.String()) + if isLocal { + *argsValues = append(*argsValues, fmt.Sprintf("$this->%s", trw.Fields[index].originalName)) + } else { + *argsValues = append(*argsValues, "$"+trw.wr.origTL[0].TemplateArguments[index].FieldName) + } + } + } else { + trw.phpGetFieldArgs(actualArg.tip, ¤tTypeRef.Args[i].T, argsValues) + } + } + return +} + func (trw *TypeRWStruct) PhpClassNameReplaced() bool { unionParent := trw.PhpConstructorNeedsUnion() if unionParent == nil { @@ -119,6 +192,7 @@ func (trw *TypeRWStruct) PhpGenerateCode(code *strings.Builder, bytes bool) erro trw.PHPStructConstructor(code, necessaryFieldsInConstructor) trw.PHPStructRPCSpecialGetters(code) + trw.PHPReadMethods(code) trw.PHPStructFieldMaskCalculators(code, usedFieldMasksIndecies, usedFieldMasks) trw.PHPStructFunctionSpecificMethods(code) @@ -218,6 +292,90 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder) } } +func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { + if trw.wr.gen.options.AddFunctionBodies { + natParamsComment := strings.Join( + utils.MapSlice( + trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + "", + ) + natParamsDecl := strings.Join( + utils.MapSlice( + trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return ", $" + s }), + "", + ) + code.WriteString(fmt.Sprintf(` + /** + * @param tl_input_stream $stream%[1]s + * @return bool + */ + public function read_boxed($stream%[2]s) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x%08[3]x) { + return false; + } + return $this->read($stream%[2]s); + } +`, + natParamsComment, + natParamsDecl, + trw.wr.tlTag, + )) + + code.WriteString(fmt.Sprintf(` + /** + * @param tl_input_stream $stream%[1]s + * @return bool + */ + public function read($stream%[2]s) { +`, + natParamsComment, + natParamsDecl, + trw.wr.tlTag, + )) + 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) } + if fieldMask != "" { + code.WriteString( + fmt.Sprintf( + "%[1]sif (%[2]s & (1 << %[3]d) != 0) {\n", + textTab(), + fieldMask, + field.BitNumber, + ), + ) + shift += 1 + } + fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) + for _, line := range fieldRead { + code.WriteString(textTab() + line + "\n") + } + if fieldMask != "" { + shift -= 1 + code.WriteString( + fmt.Sprintf( + "%[1]s}\n", + textTab(), + ), + ) + } + } + + code.WriteString(" return true;\n") + code.WriteString(" }\n") + } +} + func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, usedFieldMasksIndecies []int, usedFieldMasks map[int][]Field) { // print methods to calculate fieldmasks // fix order @@ -619,3 +777,46 @@ func (trw *TypeRWStruct) PhpConstructorNeedsUnion() (unionParent *TypeRWWrapper) return nil } + +func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { + return []string{fmt.Sprintf("$success = RPC_READ%s($stream, %s);", ifString(bare, "", "_boxed"), targetName)} + } + unionParent := trw.PhpConstructorNeedsUnion() + if unionParent == nil { + if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { + 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, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, args)...) + 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("$success = %[2]s->read%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), + "if ($success) {", + " return false;", + "}", + } +} + +func (trw *TypeRWStruct) PhpDefaultInit() string { + core := trw.wr.PHPGenCoreType() + if core != trw.wr { + return core.trw.PhpDefaultInit() + } + if core.PHPIsTrueType() { + return "true" + } + return fmt.Sprintf("new %s()", core.trw.PhpClassName(true, true)) +} diff --git a/internal/tlcodegen/type_rw_tuple_cpp.go b/internal/tlcodegen/type_rw_tuple_cpp.go index 2d5502d..fd3b72d 100644 --- a/internal/tlcodegen/type_rw_tuple_cpp.go +++ b/internal/tlcodegen/type_rw_tuple_cpp.go @@ -168,6 +168,7 @@ bool %[8]s::%[1]sWrite(::basictl::tl_ostream & s, const std::array<%[2]s, %[3]d> // valueFieldName := "" switch { // TODO - does not work yet + // REAL TODO CPP /* case trw.dictLike && !bytesVersion: keyTypeString = trw.dictKeyField.t.TypeString(bytesVersion) diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index 6e99c3c..29c2a4d 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -40,3 +40,89 @@ func (trw *TypeRWBrackets) PhpDefaultValue() string { func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { trw.element.t.PhpIterateReachableTypes(reachableTypes) } + +func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + //fmt.Println(">>>>>", trw.wr.goGlobalName, trw.dictLike, trw.vectorLike, trw.dynamicSize, trw.size) + //fmt.Println(">>>>> >>>>>", args) + result := make([]string, 0) + switch { + // actual vector + case trw.vectorLike && !trw.dictLike: + elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) + elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, args) + for i := range elementRead { + elementRead[i] = " " + elementRead[i] + } + result = append(result, + "[$vector_size, $success] = $stream->read_uint32();", + "if (!$success) {", + " return false;", + "}", + // TODO MAKE MORE EFFICIENT + fmt.Sprintf("%[1]s = [];", targetName), + "for($i = 0; $i < $vector_size; $i++) {", + fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), + ) + result = append(result, elementRead...) + result = append(result, + fmt.Sprintf(" %[1]s[] = %[2]s;", targetName, elementName), + "}", + ) + return result + // tuple with size as last argument + case !trw.vectorLike && !trw.dictLike: + elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) + tupleSize := args[len(args)-1] + elementArgs := args[:len(args)-1] + elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, elementArgs) + for i := range elementRead { + elementRead[i] = " " + elementRead[i] + } + result = append(result, + // TODO MAKE MORE EFFICIENT + fmt.Sprintf("%[1]s = [];", targetName), + fmt.Sprintf("for($i = 0; $i < %[1]s; $i++) {", tupleSize), + fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), + ) + result = append(result, elementRead...) + result = append(result, + fmt.Sprintf(" %[1]s[] = %[2]s;", targetName, elementName), + "}", + ) + return result + // actual map / dictionary + case trw.dictLike: + keyElement := fmt.Sprintf("$%s___key", trw.PhpClassName(false, true)) + valueElement := fmt.Sprintf("$%s___value", trw.PhpClassName(false, true)) + keyRead := trw.dictKeyField.t.trw.PhpReadMethodCall(keyElement, trw.dictKeyField.bare, args) + for i := range keyRead { + keyRead[i] = " " + keyRead[i] + } + valueRead := trw.dictValueField.t.trw.PhpReadMethodCall(valueElement, trw.dictValueField.bare, args) + for i := range valueRead { + valueRead[i] = " " + valueRead[i] + } + + result = append(result, + "[$dict_size, $success] = $stream->read_uint32();", + "if (!$success) {", + " return false;", + "}", + // TODO MAKE MORE EFFICIENT + fmt.Sprintf("%[1]s = [];", targetName), + "for($i = 0; $i < $dict_size; $i++) {", + ) + result = append(result, keyRead...) + result = append(result, valueRead...) + result = append(result, + fmt.Sprintf(" %[1]s[%[2]s] = %[3]s;", targetName, keyElement, valueElement), + "}", + ) + return result + } + return []string{fmt.Sprintf("", trw.wr.goGlobalName)} +} + +func (trw *TypeRWBrackets) PhpDefaultInit() string { + return "[]" +} diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 561176d..94dca19 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -82,3 +82,40 @@ func (trw *TypeRWUnion) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrap field.t.PhpIterateReachableTypes(reachableTypes) } } + +func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + if bare { + panic("union can't be bare") + } + var result []string + result = append(result, + "[$tag, $success] = $stream->read_uint32();", + "if (!$success) {", + " return false;", + "}", + "switch ($tag) {", + ) + for _, field := range trw.Fields { + curType := field.t + result = append(result, + fmt.Sprintf(" case 0x%08[1]x:", curType.tlTag), + fmt.Sprintf(" $variant = new %s();", curType.trw.PhpTypeName(false, true)), + fmt.Sprintf(" $success = $variant->read($stream%s);", phpFormatArgs(args)), + " if (!$success) {", + " return false;", + " }", + fmt.Sprintf(" %[1]s = $variant", targetName), + " break;", + ) + } + result = append(result, + " default:", + " return false;", + "}", + ) + return result +} + +func (trw *TypeRWUnion) PhpDefaultInit() string { + return trw.Fields[0].t.trw.PhpDefaultInit() +} From af5012d74b0886b12cf6c61040c9916ed2e3fe55 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Sun, 29 Dec 2024 00:32:59 +0300 Subject: [PATCH 03/37] field mask and reset fix --- internal/tlcodegen/helpers_php.go | 3 +- internal/tlcodegen/tlgen_lang_php.go | 14 ++++----- internal/tlcodegen/type_rw_struct_php.go | 38 +++++++++++++++++------- 3 files changed, 35 insertions(+), 20 deletions(-) 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;", From be0e7119183eb712c0d1813503a29c4a3004736f Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Thu, 9 Jan 2025 15:19:42 +0300 Subject: [PATCH 04/37] fix basictl location --- internal/tlcodegen/helpers_php.go | 5 +++-- internal/tlcodegen/tlgen_lang_php.go | 2 +- internal/tlcodegen/type_rw_struct_php.go | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/internal/tlcodegen/helpers_php.go b/internal/tlcodegen/helpers_php.go index 47b598f..a0f2b81 100644 --- a/internal/tlcodegen/helpers_php.go +++ b/internal/tlcodegen/helpers_php.go @@ -1,8 +1,9 @@ package tlcodegen const BasicTlPathPhp = "basictl.php" -const BasicTLCodePHP = ` -read_uint32(); - if (!$success || $magic != 0x%08[3]x) { + if (!$success || $magic != 0x%08[3]x) { return false; - } + } return $this->read($stream%[2]s); } `, @@ -326,9 +326,9 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { code.WriteString(fmt.Sprintf(` /** - * @param tl_input_stream $stream%[1]s - * @return bool - */ + * @param TL\tl_input_stream $stream%[1]s + * @return bool + */ public function read($stream%[2]s) { `, natParamsComment, @@ -685,7 +685,8 @@ func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { if isUsingTLImport(trw) || trw.ResultType != nil || - unionParent != nil { + unionParent != nil || + trw.wr.gen.options.AddFunctionBodies { code.WriteString("\nuse VK\\TL;\n") } code.WriteString(` From 97cb123e3397b2c4aed26cb3ab3533a236c3d5eb Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Thu, 9 Jan 2025 16:22:37 +0300 Subject: [PATCH 05/37] union and maybe fix in read --- internal/tlcodegen/type_rw_maybe_php.go | 2 +- internal/tlcodegen/type_rw_struct_php.go | 16 ++++++++-------- internal/tlcodegen/type_rw_union_php.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index 9841237..886598a 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -43,7 +43,7 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []s if !bare { result := []string{ fmt.Sprintf( - "[$maybeContainsValue, $success] = $stream->read_bool(0x%08[1]x, 0x%08[2]x)", + "[$maybeContainsValue, $success] = $stream->read_bool(0x%08[1]x, 0x%08[2]x);", trw.emptyTag, trw.okTag, ), diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 6786c81..434fde1 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -297,7 +297,7 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { natParamsComment := strings.Join( utils.MapSlice( trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), - func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), "", ) natParamsDecl := strings.Join( @@ -308,9 +308,9 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { ) code.WriteString(fmt.Sprintf(` /** - * @param TL\tl_input_stream $stream%[1]s - * @return bool - */ + * @param TL\tl_input_stream $stream%[1]s + * @return bool + */ public function read_boxed($stream%[2]s) { [$magic, $success] = $stream->read_uint32(); if (!$success || $magic != 0x%08[3]x) { @@ -326,9 +326,9 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { code.WriteString(fmt.Sprintf(` /** - * @param TL\tl_input_stream $stream%[1]s - * @return bool - */ + * @param TL\tl_input_stream $stream%[1]s + * @return bool + */ public function read($stream%[2]s) { `, natParamsComment, @@ -818,7 +818,7 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] } return []string{ fmt.Sprintf("if (%[1]s == null) {", targetName), - fmt.Sprintf(" %[1]s = %[2]s", targetName, trw.PhpDefaultInit()), + 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) {", diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 94dca19..37cc45b 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -99,12 +99,12 @@ func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []s curType := field.t result = append(result, fmt.Sprintf(" case 0x%08[1]x:", curType.tlTag), - fmt.Sprintf(" $variant = new %s();", curType.trw.PhpTypeName(false, true)), + fmt.Sprintf(" $variant = new %s();", curType.trw.PhpTypeName(true, true)), fmt.Sprintf(" $success = $variant->read($stream%s);", phpFormatArgs(args)), " if (!$success) {", " return false;", " }", - fmt.Sprintf(" %[1]s = $variant", targetName), + fmt.Sprintf(" %[1]s = $variant;", targetName), " break;", ) } From 77d4e8258b1cc95e55f472eb2587d740c8ef237f Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Sun, 12 Jan 2025 15:14:00 +0300 Subject: [PATCH 06/37] add meta support --- cmd/tlgen/main2.go | 4 + internal/tlcodegen/helpers_php.go | 40 ++++++++- internal/tlcodegen/tlgen.go | 2 + internal/tlcodegen/tlgen_lang_php.go | 108 ++++++++++++++++++++++- internal/tlcodegen/type_rw_struct_php.go | 17 +++- 5 files changed, 166 insertions(+), 5 deletions(-) diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index bdb9093..d1a98f6 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -79,6 +79,10 @@ func parseFlags(opt *tlcodegen.Gen2Options) { // PHP flag.BoolVar(&opt.AddFunctionBodies, "php-serialization-bodies", false, `whether to generate body to write/read generated structs and functions`) + flag.BoolVar(&opt.AddMetaData, "php-generate-meta", false, + `whether to generate methods to get meta information about tl objects`) + flag.BoolVar(&opt.AddFactoryData, "php-generate-factory", false, + `whether to generate factory of tl objects`) // .tlo flag.StringVar(&opt.TLOPath, "tloPath", "", diff --git a/internal/tlcodegen/helpers_php.go b/internal/tlcodegen/helpers_php.go index a0f2b81..2b79250 100644 --- a/internal/tlcodegen/helpers_php.go +++ b/internal/tlcodegen/helpers_php.go @@ -1,6 +1,6 @@ package tlcodegen -const BasicTlPathPhp = "basictl.php" +const BasicTlPathPHP = "tl_streams.php" const BasicTLCodePHP = `tag = $tag; + $this->annotations = $annotations; + $this->tl_name = $tl_name; + } +} + +class tl_meta { + /** @var tl_item[] */ + private $tl_item_by_tag = null; + + /** @var tl_item[] */ + private $tl_item_by_name = null; + + /** + * @param string $tl_name + * @return tl_item|null + */ + function tl_item_by_name($tl_name) { + if (array_key_exists($tl_name, $this->tl_item_by_name)) { + return $this->tl_item_by_name[$tl_name]; + } + return null; + } + + /** + * @param int $tl_name + * @return tl_item|null + */ + function tl_item_by_tag($tl_tag) { + if (array_key_exists($tl_tag, $this->tl_item_by_tag)) { + return $this->tl_item_by_tag[$tl_tag]; + } + return null; + } + + function __construct() {`) + + createdTypes := make(map[string]bool) + + for _, wr := range gen.generatedTypesList { + if createdTypes[wr.trw.PhpClassName(true, true)] { + continue + } + if !wr.PHPNeedsCode() { + continue + } + if _, iStruct := wr.trw.(*TypeRWStruct); iStruct && len(wr.origTL[0].TemplateArguments) == 0 { + code.WriteString(fmt.Sprintf(` + $item%08[1]x = new tl_item(0x%08[1]x, 0x%[2]x, "%[3]s"); + $this->tl_item_by_name["%[3]s"] = $item%08[1]x; + $this->tl_item_by_tag[0x%08[1]x] = $item%08[1]x;`, + wr.tlTag, + wr.AnnotationsMask(), + wr.tlName.String(), + )) + } + } + + code.WriteString(` + } +} +`) + if err := gen.addCodeFile(filepath.Join("VK", "TL", "meta.php"), code.String()); err != nil { + return err + } + return nil +} + func PHPGetAllReachableTypes(startTypes []*TypeRWWrapper) map[*TypeRWWrapper]bool { reachable := make(map[*TypeRWWrapper]bool) for _, startType := range startTypes { diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 434fde1..dec099a 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -695,11 +695,24 @@ func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { */ `) code.WriteString(fmt.Sprintf("class %s ", trw.PhpClassName(false, true))) + implementingInterfaces := make([]string, 0) + if unionParent != nil { - code.WriteString(fmt.Sprintf("implements %s ", unionParent.trw.PhpClassName(true, false))) + implementingInterfaces = append(implementingInterfaces, unionParent.trw.PhpClassName(true, false)) } + if trw.ResultType != nil { - code.WriteString("implements TL\\RpcFunction ") + implementingInterfaces = append(implementingInterfaces, "TL\\RpcFunction") + } + + if len(trw.wr.origTL[0].TemplateArguments) == 0 { + implementingInterfaces = append(implementingInterfaces, "TL\\Readable") + } + + if trw.wr.gen.options.AddFunctionBodies && len(implementingInterfaces) != 0 { + code.WriteString("implements ") + code.WriteString(strings.Join(implementingInterfaces, ", ")) + code.WriteString(" ") } code.WriteString("{\n") } From 5c219205acdcdaecb47cc7d2fa0cdc6221c04b9d Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Sun, 12 Jan 2025 17:28:46 +0300 Subject: [PATCH 07/37] add factory --- cmd/tlgen/main2.go | 3 + internal/tlcodegen/tlgen_lang_php.go | 168 ++++++++++++++++++++------- internal/tlcodegen/type_rw.go | 7 ++ 3 files changed, 135 insertions(+), 43 deletions(-) diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index d1a98f6..93cd4c4 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -84,6 +84,9 @@ func parseFlags(opt *tlcodegen.Gen2Options) { flag.BoolVar(&opt.AddFactoryData, "php-generate-factory", false, `whether to generate factory of tl objects`) + if opt.AddFactoryData { + opt.AddFunctionBodies = true + } // .tlo flag.StringVar(&opt.TLOPath, "tloPath", "", "whether to serialize TL schema in binary form") diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index e143dc8..7e2078a 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -32,31 +32,15 @@ type PhpClassMeta struct { } func (gen *Gen2) generateCodePHP(generateByteVersions []string) error { - if gen.options.AddFunctionBodies { - if err := gen.addCodeFile(filepath.Join("VK", "TL", BasicTlPathPHP), BasicTLCodePHP); err != nil { - return err - } - if err := gen.addCodeFile(filepath.Join("VK", "TL", TLInterfacesPathPHP), TLInterfacesCodePHP); err != nil { - return err - } - } - // select files where to write code gen.PhpMarkAllInternalTypes() gen.PhpChoosePaths() + if err := gen.PhpAdditionalFiles(); err != nil { return err } - createdTypes := make(map[string]bool) - - for _, wrapper := range gen.generatedTypesList { - if createdTypes[wrapper.trw.PhpClassName(true, true)] { - continue - } - if !wrapper.PHPNeedsCode() { - continue - } + for _, wrapper := range gen.PhpSelectTypesForGeneration() { fmt.Println(fmt.Sprintf( "PHP{%[1]s} in GO{%[2]s}", wrapper.trw.PhpClassName(false, true), @@ -65,7 +49,7 @@ func (gen *Gen2) generateCodePHP(generateByteVersions []string) error { wrapper.origTL[0].TemplateArguments, wrapper.arguments), ) - err := phpGenerateCodeForWrapper(gen, wrapper, createdTypes, true, wrapper.PHPGenerateCode) + err := phpGenerateCodeForWrapper(gen, wrapper, true, wrapper.PHPGenerateCode) if err != nil { return err } @@ -73,7 +57,7 @@ func (gen *Gen2) generateCodePHP(generateByteVersions []string) error { return nil } -func phpGenerateCodeForWrapper(gen *Gen2, wrapper *TypeRWWrapper, createdTypes map[string]bool, createInterfaceIfNeeded bool, codeGenerator func(code *strings.Builder, bytes bool) error) error { +func phpGenerateCodeForWrapper(gen *Gen2, wrapper *TypeRWWrapper, createInterfaceIfNeeded bool, codeGenerator func(code *strings.Builder, bytes bool) error) error { var code strings.Builder // add start symbol code.WriteString(PHPFileStart) @@ -90,7 +74,7 @@ func phpGenerateCodeForWrapper(gen *Gen2, wrapper *TypeRWWrapper, createdTypes m if strct, isStruct := wrapper.trw.(*TypeRWStruct); isStruct { unionParent := strct.PhpConstructorNeedsUnion() if unionParent != nil && unionParent == wrapper { - err := phpGenerateCodeForWrapper(gen, wrapper, createdTypes, false, func(code *strings.Builder, bytes bool) error { + err := phpGenerateCodeForWrapper(gen, wrapper, false, func(code *strings.Builder, bytes bool) error { return PhpGenerateInterfaceCode(code, bytes, wrapper, []*TypeRWWrapper{wrapper}) }) if err != nil { @@ -100,15 +84,10 @@ func phpGenerateCodeForWrapper(gen *Gen2, wrapper *TypeRWWrapper, createdTypes m } } - filepathParts := []string{"VK"} - //filepathParts = append(filepathParts, wrapper.PHPTypePathElements()...) - path := fmt.Sprintf("%s.php", wrapper.trw.PhpClassName(true, createInterfaceIfNeeded)) - filepathParts = append(filepathParts, strings.Split(path, "\\")...) - filepathName := filepath.Join(filepathParts...) + filepathName := filepath.Join(wrapper.PHPFilePath(createInterfaceIfNeeded)...) if err := gen.addCodeFile(filepathName, code.String()); err != nil { return err } - createdTypes[wrapper.trw.PhpClassName(true, createInterfaceIfNeeded)] = true return nil } @@ -116,7 +95,32 @@ func (gen *Gen2) PhpChoosePaths() { } +func (gen *Gen2) PhpSelectTypesForGeneration() []*TypeRWWrapper { + createdTypes := make(map[string]bool) + wrappers := make([]*TypeRWWrapper, 0) + + for _, wrapper := range gen.generatedTypesList { + if createdTypes[wrapper.trw.PhpClassName(true, true)] { + continue + } + if !wrapper.PHPNeedsCode() { + continue + } + createdTypes[wrapper.trw.PhpClassName(true, true)] = true + wrappers = append(wrappers, wrapper) + } + return wrappers +} + func (gen *Gen2) PhpAdditionalFiles() error { + if gen.options.AddFunctionBodies { + if err := gen.addCodeFile(filepath.Join("VK", "TL", BasicTlPathPHP), BasicTLCodePHP); err != nil { + return err + } + if err := gen.addCodeFile(filepath.Join("VK", "TL", TLInterfacesPathPHP), TLInterfacesCodePHP); err != nil { + return err + } + } if err := gen.addCodeFile(filepath.Join("VK", "TL", "RpcFunction.php"), fmt.Sprintf(RpcFunctionPHP, gen.copyrightText)); err != nil { return err } @@ -128,6 +132,11 @@ func (gen *Gen2) PhpAdditionalFiles() error { return err } } + if gen.options.AddFactoryData { + if err := gen.phpCreateFactory(); err != nil { + return err + } + } return nil } @@ -170,13 +179,12 @@ func (gen *Gen2) PhpMarkAllInternalTypes() { func (gen *Gen2) phpCreateMeta() error { var code strings.Builder - code.WriteString(`tl_factory_by_name)) { + return $this->tl_factory_by_name[$tl_name](); + } + return null; + } + + /** + * @param int $tl_tag + * @return TL\TL_Object|null + */ + function tl_object_by_tag($tl_tag) { + if (array_key_exists($tl_tag, $this->tl_factory_by_tag)) { + return $this->tl_factory_by_tag[$tl_tag](); + } + return null; + } + + function __construct() {`, gen.copyrightText, includes)) + + for _, wr := range gen.PhpSelectTypesForGeneration() { + if addFactory(wr) { + code.WriteString(fmt.Sprintf(` + $item%08[1]x = function () { return new %[4]s(); }; + $this->tl_factory_by_name["%[3]s"] = $item%08[1]x; + $this->tl_factory_by_tag[0x%08[1]x] = $item%08[1]x;`, + wr.tlTag, + wr.AnnotationsMask(), + wr.tlName.String(), + wr.trw.PhpClassName(true, true), + )) + } + } + + code.WriteString(` + } +} +`) + if err := gen.addCodeFile(filepath.Join("VK", "TL", "factory.php"), code.String()); err != nil { + return err + } + return nil +} + func PHPGetAllReachableTypes(startTypes []*TypeRWWrapper) map[*TypeRWWrapper]bool { reachable := make(map[*TypeRWWrapper]bool) for _, startType := range startTypes { diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index c2e4113..9d617c7 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -548,6 +548,13 @@ func (w *TypeRWWrapper) PHPTypePath() string { } } +func (w *TypeRWWrapper) PHPFilePath(bare bool) []string { + filepathParts := []string{"VK"} + path := fmt.Sprintf("%s.php", w.trw.PhpClassName(true, bare)) + filepathParts = append(filepathParts, strings.Split(path, "\\")...) + return filepathParts +} + func (w *TypeRWWrapper) PHPGenCoreType() *TypeRWWrapper { if w.PHPUnionParent() == nil { struct_, isStruct := w.trw.(*TypeRWStruct) From 901f63a6f39db3b6a80da0ccec720b99d393718b Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 13 Jan 2025 14:07:41 +0300 Subject: [PATCH 08/37] add write methods --- internal/tlcodegen/helpers_php.go | 14 ++- internal/tlcodegen/tlgen_lang_php.go | 1 + internal/tlcodegen/type_rw_bool_php.go | 17 +++ internal/tlcodegen/type_rw_maybe_php.go | 29 +++++ internal/tlcodegen/type_rw_primitive_php.go | 12 ++ internal/tlcodegen/type_rw_struct_php.go | 127 +++++++++++++++++++- internal/tlcodegen/type_rw_tuple_php.go | 67 ++++++++++- internal/tlcodegen/type_rw_union_php.go | 57 ++++++++- 8 files changed, 318 insertions(+), 6 deletions(-) diff --git a/internal/tlcodegen/helpers_php.go b/internal/tlcodegen/helpers_php.go index 2b79250..77c6af6 100644 --- a/internal/tlcodegen/helpers_php.go +++ b/internal/tlcodegen/helpers_php.go @@ -157,31 +157,42 @@ class tl_output_stream { public function get_data(): string { return $this->data; } - + + /** @return bool */ public function write_uint32(int $value) { $this->data .= pack('V', $value); + return true; } + /** @return bool */ public function write_int32(int $value) { $this->data .= pack('l', $value); + return true; } + /** @return bool */ public function write_bool(bool $value, int $false_tag, $true_tag) { if ($value) { $this->data .= pack('V', $true_tag); } else { $this->data .= pack('V', $false_tag); } + return true; } + /** @return bool */ public function write_float(float $value) { $this->data .= pack('f', $value); + return true; } + /** @return bool */ public function write_double(float $value) { $this->data .= pack('d', $value); + return true; } + /** @return bool */ public function write_string(string $value) { $l = strlen($value); $p = 0; @@ -220,6 +231,7 @@ class tl_output_stream { } else if ($p % 4 == 3) { $this->data .= chr(0); } + return true; } } ?> diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 7e2078a..752a229 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -24,6 +24,7 @@ type TypeRWPHPData interface { PhpDefaultValue() string PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) PhpReadMethodCall(targetName string, bare bool, args []string) []string + PhpWriteMethodCall(targetName string, bare bool, args []string) []string } type PhpClassMeta struct { diff --git a/internal/tlcodegen/type_rw_bool_php.go b/internal/tlcodegen/type_rw_bool_php.go index cfcff5a..fec4208 100644 --- a/internal/tlcodegen/type_rw_bool_php.go +++ b/internal/tlcodegen/type_rw_bool_php.go @@ -45,6 +45,23 @@ func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args []st return nil } +func (trw *TypeRWBool) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + return []string{ + fmt.Sprintf( + "$success = $stream->write_bool(%[1]s, 0x%08[2]x, 0x%08[3]x);", + targetName, + trw.falseTag, + trw.trueTag, + ), + "if (!$success) {", + " return false;", + "}", + } + } + return nil +} + func (trw *TypeRWBool) PhpDefaultInit() string { return "false" } diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index 886598a..5360d18 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -74,6 +74,35 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []s return nil } +func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + result := []string{ + fmt.Sprintf( + "$success = $stream->write_bool(%[1]s != null, 0x%08[1]x, 0x%08[2]x);", + targetName, + trw.emptyTag, + trw.okTag, + ), + "if (!$success) {", + " return false;", + "}", + fmt.Sprintf("if (%[1]s != null) {", targetName), + } + { + bodyWriter := trw.element.t.trw.PhpWriteMethodCall(targetName, trw.element.bare, args) + for i, _ := range bodyWriter { + bodyWriter[i] = " " + bodyWriter[i] + } + result = append(result, bodyWriter...) + } + result = append(result, + "}", + ) + return result + } + return nil +} + func (trw *TypeRWMaybe) PhpDefaultInit() string { return trw.element.t.trw.PhpDefaultInit() } diff --git a/internal/tlcodegen/type_rw_primitive_php.go b/internal/tlcodegen/type_rw_primitive_php.go index a5b0bba..3ff35f8 100644 --- a/internal/tlcodegen/type_rw_primitive_php.go +++ b/internal/tlcodegen/type_rw_primitive_php.go @@ -70,6 +70,18 @@ func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args } } +func (trw *TypeRWPrimitive) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + if !bare { + panic("can't be boxed") + } + return []string{ + fmt.Sprintf("$success = $stream->write_%[2]s(%[1]s);", targetName, trw.phpIOMethodsSuffix()), + "if (!$success) {", + " return false;", + "}", + } +} + func (trw *TypeRWPrimitive) PhpDefaultInit() string { return trw.PhpDefaultValue() } diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index dec099a..f76b9e1 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -192,7 +192,8 @@ func (trw *TypeRWStruct) PhpGenerateCode(code *strings.Builder, bytes bool) erro trw.PHPStructConstructor(code, necessaryFieldsInConstructor) trw.PHPStructRPCSpecialGetters(code) - trw.PHPReadMethods(code) + trw.PHPStructReadMethods(code) + trw.PHPStructWriteMethods(code) trw.PHPStructFieldMaskCalculators(code, usedFieldMasksIndecies, usedFieldMasks) trw.PHPStructFunctionSpecificMethods(code) @@ -292,7 +293,7 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder) } } -func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { +func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { if trw.wr.gen.options.AddFunctionBodies { natParamsComment := strings.Join( utils.MapSlice( @@ -376,6 +377,80 @@ func (trw *TypeRWStruct) PHPReadMethods(code *strings.Builder) { } } +func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { + if trw.wr.gen.options.AddFunctionBodies { + natParamsComment := strings.Join( + utils.MapSlice( + trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + "", + ) + natParamsDecl := strings.Join( + utils.MapSlice( + trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return ", $" + s }), + "", + ) + code.WriteString(fmt.Sprintf(` + /** + * @param TL\tl_output_stream $stream%[1]s + * @return bool + */ + public function write_boxed($stream%[2]s) { + $success = $stream->write_uint32(0x%08[3]x); + if (!$success) { + return false; + } + return $this->write($stream%[2]s); + } +`, + natParamsComment, + natParamsDecl, + trw.wr.tlTag, + )) + + code.WriteString(fmt.Sprintf(` + /** + * @param TL\tl_output_stream $stream%[1]s + * @return bool + */ + public function write($stream%[2]s) { +`, + natParamsComment, + natParamsDecl, + trw.wr.tlTag, + )) + const tab = " " + for i, field := range trw.Fields { + fieldMask := trw.PHPGetFieldMask(i) + shift := 2 + textTab := func() string { return strings.Repeat(tab, shift) } + if fieldMask != "" { + code.WriteString( + fmt.Sprintf( + "%[1]sif (%[2]s & (1 << %[3]d) != 0) {\n", + textTab(), + fieldMask, + field.BitNumber, + ), + ) + shift += 1 + } + fieldRead := field.t.trw.PhpWriteMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) + for _, line := range fieldRead { + code.WriteString(textTab() + line + "\n") + } + if fieldMask != "" { + shift -= 1 + code.WriteString(fmt.Sprintf("%[1]s}\n", textTab())) + } + } + + code.WriteString(" return true;\n") + code.WriteString(" }\n") + } +} + func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, usedFieldMasksIndecies []int, usedFieldMasks map[int][]Field) { // print methods to calculate fieldmasks // fix order @@ -707,6 +782,7 @@ func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { if len(trw.wr.origTL[0].TemplateArguments) == 0 { implementingInterfaces = append(implementingInterfaces, "TL\\Readable") + implementingInterfaces = append(implementingInterfaces, "TL\\Writeable") } if trw.wr.gen.options.AddFunctionBodies && len(implementingInterfaces) != 0 { @@ -840,6 +916,53 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] } } +func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { + return []string{fmt.Sprintf("$success = RPC_WRITE%s($stream, %s);", ifString(bare, "", "_boxed"), targetName)} + } + unionParent := trw.PhpConstructorNeedsUnion() + if unionParent == nil { + if len(trw.Fields) == 1 && trw.ResultType == nil && trw.Fields[0].fieldMask == nil { + var result []string + if !bare { + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(0x%08[1]x);", trw.wr.tlTag), + "if (!$success) {", + " return false;", + "}", + ) + } + result = append(result, trw.Fields[0].t.trw.PhpWriteMethodCall(targetName, trw.Fields[0].bare, args)...) + return result + } + if trw.ResultType == nil && trw.wr.PHPIsTrueType() { + var result []string + if !bare { + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(0x%08[1]x);", trw.wr.tlTag), + "if (!$success) {", + " return false;", + "}", + ) + } + 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->write%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), + "if ($success) {", + " return false;", + "}", + } +} + func (trw *TypeRWStruct) PhpDefaultInit() string { core := trw.wr.PHPGenCoreType() if core != trw.wr { diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index 29c2a4d..e50eb49 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -42,8 +42,6 @@ func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWW } func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args []string) []string { - //fmt.Println(">>>>>", trw.wr.goGlobalName, trw.dictLike, trw.vectorLike, trw.dynamicSize, trw.size) - //fmt.Println(">>>>> >>>>>", args) result := make([]string, 0) switch { // actual vector @@ -123,6 +121,71 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args return []string{fmt.Sprintf("", trw.wr.goGlobalName)} } +func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + result := make([]string, 0) + switch { + // actual vector + case trw.vectorLike && !trw.dictLike: + result = append(result, + fmt.Sprintf("$vector_size = count(%[1]s);", targetName), + // TODO MAKE MORE EFFICIENT + "for($i = 0; $i < $vector_size; $i++) {", + ) + { + elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[$i]", targetName), trw.element.bare, args) + for i := range elementRead { + elementRead[i] = " " + elementRead[i] + } + result = append(result, elementRead...) + } + result = append(result, + "}", + ) + return result + // tuple with size as last argument + case !trw.vectorLike && !trw.dictLike: + tupleSize := args[len(args)-1] + elementArgs := args[:len(args)-1] + result = append(result, + fmt.Sprintf("$tuple_size = %[1]s;", tupleSize), + // TODO MAKE MORE EFFICIENT + "for($i = 0; $i < $tuple_size; $i++) {", + ) + { + elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[$i]", targetName), trw.element.bare, elementArgs) + for i := range elementRead { + elementRead[i] = " " + elementRead[i] + } + result = append(result, elementRead...) + } + result = append(result, "}") + return result + // actual map / dictionary + case trw.dictLike: + keyElement := "$key" + valueElement := "$value" + result = append(result, + fmt.Sprintf("ksort(%[1]s);", targetName), + fmt.Sprintf("foreach(%[1]s as %[2]s => %[3]s) {", targetName, keyElement, valueElement), + ) + { + keyRead := trw.dictKeyField.t.trw.PhpWriteMethodCall(keyElement, trw.dictKeyField.bare, args) + for i := range keyRead { + keyRead[i] = " " + keyRead[i] + } + valueRead := trw.dictValueField.t.trw.PhpWriteMethodCall(valueElement, trw.dictValueField.bare, args) + for i := range valueRead { + valueRead[i] = " " + valueRead[i] + } + result = append(result, keyRead...) + result = append(result, valueRead...) + } + result = append(result, "}") + return result + } + return []string{fmt.Sprintf("", trw.wr.goGlobalName)} +} + func (trw *TypeRWBrackets) PhpDefaultInit() string { return "[]" } diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 37cc45b..21477d9 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -64,15 +64,52 @@ use VK\TL; const CONSTRUCTORS = [ %[2]s ]; - +%[3]s } `, targetType.trw.PhpClassName(false, false), strings.Join(constructors, ",\n "), + phpGenerateIOBoxedMethodsForInterface(bytes, targetType), )) + return nil } +func phpGenerateIOBoxedMethodsForInterface(bytes bool, targetType *TypeRWWrapper) string { + if !targetType.gen.options.AddFunctionBodies { + return "" + } + natParamsComment := strings.Join( + utils.MapSlice( + targetType.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + "", + ) + natParamsDecl := strings.Join( + utils.MapSlice( + targetType.PHPGetNatTypeDependenciesDeclAsArray(), + func(s string) string { return ", $" + s }), + "", + ) + ioCode := "" + ioCode += fmt.Sprintf(` + /** + * @param TL\tl_input_stream $stream%[1]s + * @return bool + */ + public function read_boxed($stream%[2]s); + + /** + * @param TL\tl_output_stream $stream%[1]s + * @return bool + */ + public function write_boxed($stream%[2]s);`, + natParamsComment, + natParamsDecl) + + return ioCode +} + func (trw *TypeRWUnion) PhpDefaultValue() string { return "null" } @@ -116,6 +153,24 @@ func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []s return result } +func (trw *TypeRWUnion) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + if bare { + panic("union can't be bare") + } + var result []string + result = append(result, + fmt.Sprintf("if (%[1]s == null) {", targetName), + fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), + "}", + fmt.Sprintf("$success = %[1]s->write_boxed($stream%[2]s);", targetName, phpFormatArgs(args)), + "if (!$success) {", + " return false;", + "}", + ) + + return result +} + func (trw *TypeRWUnion) PhpDefaultInit() string { return trw.Fields[0].t.trw.PhpDefaultInit() } From 6ed793d49add399cab2fae34d1fcac08c6b1a92a Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 13 Jan 2025 14:15:16 +0300 Subject: [PATCH 09/37] fix 64 long and true write --- internal/tlcodegen/helpers_php.go | 17 +++++++++++++++++ internal/tlcodegen/type_rw_struct_php.go | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/tlcodegen/helpers_php.go b/internal/tlcodegen/helpers_php.go index 77c6af6..d0fa826 100644 --- a/internal/tlcodegen/helpers_php.go +++ b/internal/tlcodegen/helpers_php.go @@ -54,6 +54,17 @@ class tl_input_stream { } } + /** @return tuple(int, bool) */ + public function read_int64() { + $data = unpack('q', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 8; + return [$data[1], true]; + } + } + /** @return tuple(bool, bool) */ public function read_bool(int $false_tag, $true_tag) { [$tag, $success] = $this->read_uint32(); @@ -170,6 +181,12 @@ class tl_output_stream { return true; } + /** @return bool */ + public function write_int64(int $value) { + $this->data .= pack('q', $value); + return true; + } + /** @return bool */ public function write_bool(bool $value, int $false_tag, $true_tag) { if ($value) { diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index f76b9e1..4ff6225 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -425,6 +425,10 @@ func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { fieldMask := trw.PHPGetFieldMask(i) shift := 2 textTab := func() string { return strings.Repeat(tab, shift) } + fieldRead := field.t.trw.PhpWriteMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) + if fieldRead == nil { + continue + } if fieldMask != "" { code.WriteString( fmt.Sprintf( @@ -436,7 +440,6 @@ func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { ) shift += 1 } - fieldRead := field.t.trw.PhpWriteMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) for _, line := range fieldRead { code.WriteString(textTab() + line + "\n") } From 616329ebbf97c6a9ae215ebc67a6489607312d56 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 13 Jan 2025 16:04:20 +0300 Subject: [PATCH 10/37] success fix --- internal/tlcodegen/type_rw_struct_php.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 4ff6225..a10a0c2 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -913,7 +913,7 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] 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) {", + "if (!$success) {", " return false;", "}", } @@ -960,7 +960,7 @@ func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args [ fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), "}", fmt.Sprintf("$success = %[2]s->write%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), - "if ($success) {", + "if (!$success) {", " return false;", "}", } From 34cdbbb4b702e4487cc1decd78071ea9602232cd Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 14 Jan 2025 13:49:30 +0300 Subject: [PATCH 11/37] move rpc stuff under feature, same for choosing to generate only used in non internal functions types --- cmd/tlgen/main2.go | 4 + internal/tlcodegen/tlgen.go | 170 ++++++++++++----------- internal/tlcodegen/tlgen_lang_php.go | 14 +- internal/tlcodegen/type_rw.go | 6 +- internal/tlcodegen/type_rw_struct_php.go | 13 +- 5 files changed, 111 insertions(+), 96 deletions(-) diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index 93cd4c4..ab2cda3 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -83,6 +83,10 @@ func parseFlags(opt *tlcodegen.Gen2Options) { `whether to generate methods to get meta information about tl objects`) flag.BoolVar(&opt.AddFactoryData, "php-generate-factory", false, `whether to generate factory of tl objects`) + flag.BoolVar(&opt.IgnoreUnusedInFunctionsTypes, "php-ignore-unused-types", true, + `whether to not generate types without usages in functions`) + flag.BoolVar(&opt.AddRPCTypes, "php-rpc-support", true, + `whether to generate special rpc types`) if opt.AddFactoryData { opt.AddFunctionBodies = true diff --git a/internal/tlcodegen/tlgen.go b/internal/tlcodegen/tlgen.go index feb4512..c3eb40f 100644 --- a/internal/tlcodegen/tlgen.go +++ b/internal/tlcodegen/tlgen.go @@ -332,9 +332,11 @@ type Gen2Options struct { SeparateFiles bool // PHP - AddFunctionBodies bool - AddMetaData bool - AddFactoryData bool + AddFunctionBodies bool + AddMetaData bool + AddFactoryData bool + IgnoreUnusedInFunctionsTypes bool + AddRPCTypes bool // .tlo TLOPath string @@ -945,93 +947,95 @@ func GenerateCode(tl tlast.TL, options Gen2Options) (*Gen2, error) { if gen.options.Language == "php" { // RPC SPECIAL CHANGES - const rpcRequestResultName = "ReqResult" - rpcResultsMapping := map[string]string{ - "reqError": "rpcResponseError", - "reqResultHeader": "rpcResponseHeader", - "_": "rpcResponseOk", - } - rpcRemovedTypes := map[string]bool{ - "rpcReqResult": true, - "rpcReqError": true, - "rpcInvokeReq": true, - } - rpcFunctionTypeRef := tlast.TypeRef{ - Type: tlast.Name{ - Name: PHPRPCFunctionMock, - }, - } - rpcFunctionResultTypeRef := tlast.TypeRef{ - Type: tlast.Name{ - Name: PHPRPCFunctionResultMock, - }, - } - rpcResponseTypeRef := tlast.TypeRef{ - Type: tlast.Name{ - Name: PHPRPCResponseMock, - }, - } - // TODO: RETURN ORIGINAL COMBINATOR - tl = append(tl, &tlast.Combinator{ - TypeDecl: tlast.TypeDeclaration{ - Name: tlast.Name{ - Name: "ReqResult", + if gen.options.AddRPCTypes { + const rpcRequestResultName = "ReqResult" + rpcResultsMapping := map[string]string{ + "reqError": "rpcResponseError", + "reqResultHeader": "rpcResponseHeader", + "_": "rpcResponseOk", + } + rpcRemovedTypes := map[string]bool{ + "rpcReqResult": true, + "rpcReqError": true, + "rpcInvokeReq": true, + } + rpcFunctionTypeRef := tlast.TypeRef{ + Type: tlast.Name{ + Name: PHPRPCFunctionMock, }, - Arguments: []string{"X"}, - }, - Construct: tlast.Constructor{ - Name: tlast.Name{Name: "_"}, - }, - TemplateArguments: []tlast.TemplateArgument{ - { - FieldName: "X", - IsNat: false, + } + rpcFunctionResultTypeRef := tlast.TypeRef{ + Type: tlast.Name{ + Name: PHPRPCFunctionResultMock, }, - }, - Fields: []tlast.Field{ - { - FieldName: "result", - FieldType: tlast.TypeRef{ - Type: tlast.Name{ - Name: "X", + } + rpcResponseTypeRef := tlast.TypeRef{ + Type: tlast.Name{ + Name: PHPRPCResponseMock, + }, + } + // TODO: RETURN ORIGINAL COMBINATOR + tl = append(tl, &tlast.Combinator{ + TypeDecl: tlast.TypeDeclaration{ + Name: tlast.Name{ + Name: "ReqResult", + }, + Arguments: []string{"X"}, + }, + Construct: tlast.Constructor{ + Name: tlast.Name{Name: "_"}, + }, + TemplateArguments: []tlast.TemplateArgument{ + { + FieldName: "X", + IsNat: false, + }, + }, + Fields: []tlast.Field{ + { + FieldName: "result", + FieldType: tlast.TypeRef{ + Type: tlast.Name{ + Name: "X", + }, }, }, }, - }, - }) - tl = append(tl, &tlast.Combinator{ - TypeDecl: tlast.TypeDeclaration{ - Name: rpcFunctionTypeRef.Type, - }, - Construct: tlast.Constructor{Name: rpcFunctionTypeRef.Type}, - }) - tl = append(tl, &tlast.Combinator{ - TypeDecl: tlast.TypeDeclaration{ - Name: rpcFunctionResultTypeRef.Type, - }, - Construct: tlast.Constructor{Name: rpcFunctionResultTypeRef.Type}, - }) - for _, typ := range tl { - if typ.IsFunction && len(typ.TemplateArguments) == 1 { - phpRemoveTemplateFromGeneric(typ, &rpcFunctionTypeRef, &rpcFunctionResultTypeRef) - } else if !typ.IsFunction && - rpcResultsMapping[typ.Construct.Name.String()] != "" && - typ.TypeDecl.Name.String() == rpcRequestResultName { - typ.Construct.Name.Name = rpcResultsMapping[typ.Construct.Name.String()] - typ.TypeDecl = tlast.TypeDeclaration{Name: rpcResponseTypeRef.Type} - phpRemoveTemplateFromGeneric(typ, &rpcFunctionResultTypeRef, &rpcFunctionResultTypeRef) + }) + tl = append(tl, &tlast.Combinator{ + TypeDecl: tlast.TypeDeclaration{ + Name: rpcFunctionTypeRef.Type, + }, + Construct: tlast.Constructor{Name: rpcFunctionTypeRef.Type}, + }) + tl = append(tl, &tlast.Combinator{ + TypeDecl: tlast.TypeDeclaration{ + Name: rpcFunctionResultTypeRef.Type, + }, + Construct: tlast.Constructor{Name: rpcFunctionResultTypeRef.Type}, + }) + for _, typ := range tl { + if typ.IsFunction && len(typ.TemplateArguments) == 1 { + phpRemoveTemplateFromGeneric(typ, &rpcFunctionTypeRef, &rpcFunctionResultTypeRef) + } else if !typ.IsFunction && + rpcResultsMapping[typ.Construct.Name.String()] != "" && + typ.TypeDecl.Name.String() == rpcRequestResultName { + typ.Construct.Name.Name = rpcResultsMapping[typ.Construct.Name.String()] + typ.TypeDecl = tlast.TypeDeclaration{Name: rpcResponseTypeRef.Type} + phpRemoveTemplateFromGeneric(typ, &rpcFunctionResultTypeRef, &rpcFunctionResultTypeRef) + } } - } - // TODO DELETE AS NORMAL PEOPLE - var removedTypesIndecies []int - for i, typ := range tl { - if rpcRemovedTypes[typ.Construct.Name.String()] { - removedTypesIndecies = append(removedTypesIndecies, i) + // TODO DELETE AS NORMAL PEOPLE + var removedTypesIndecies []int + for i, typ := range tl { + if rpcRemovedTypes[typ.Construct.Name.String()] { + removedTypesIndecies = append(removedTypesIndecies, i) + } + } + sort.Ints(removedTypesIndecies) + for i, index := range removedTypesIndecies { + tl = append(tl[:index-i], tl[index-i+1:]...) } - } - sort.Ints(removedTypesIndecies) - for i, index := range removedTypesIndecies { - tl = append(tl[:index-i], tl[index-i+1:]...) } } diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 752a229..14fc092 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -122,11 +122,13 @@ func (gen *Gen2) PhpAdditionalFiles() error { return err } } - if err := gen.addCodeFile(filepath.Join("VK", "TL", "RpcFunction.php"), fmt.Sprintf(RpcFunctionPHP, gen.copyrightText)); err != nil { - return err - } - if err := gen.addCodeFile(filepath.Join("VK", "TL", "RpcResponse.php"), fmt.Sprintf(RpcResponsePHP, gen.copyrightText)); err != nil { - return err + if gen.options.AddRPCTypes { + if err := gen.addCodeFile(filepath.Join("VK", "TL", "RpcFunction.php"), fmt.Sprintf(RpcFunctionPHP, gen.copyrightText)); err != nil { + return err + } + if err := gen.addCodeFile(filepath.Join("VK", "TL", "RpcResponse.php"), fmt.Sprintf(RpcResponsePHP, gen.copyrightText)); err != nil { + return err + } } if gen.options.AddMetaData { if err := gen.phpCreateMeta(); err != nil { @@ -158,7 +160,7 @@ func (gen *Gen2) PhpMarkAllInternalTypes() { } } // TODO: CHANGE SOMEHOW - if rpcResults[wrapper.tlName.String()] { + if gen.options.AddRPCTypes && rpcResults[wrapper.tlName.String()] { nonInternalFunctions = append(nonInternalFunctions, wrapper) } } diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index 9d617c7..a26bdec 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -619,8 +619,10 @@ func (w *TypeRWWrapper) PHPNeedsCode() bool { if w.trw.PhpClassName(false, true) == "" { return false } - if !w.phpInfo.UsedInFunctions || w.phpInfo.UsedOnlyInInternal { - return false + if w.gen.options.IgnoreUnusedInFunctionsTypes { + if !w.phpInfo.UsedInFunctions || w.phpInfo.UsedOnlyInInternal { + return false + } } if w.PHPGenCoreType() != w { return false diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index a10a0c2..dbdf8ce 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -204,7 +204,7 @@ func (trw *TypeRWStruct) PhpGenerateCode(code *strings.Builder, bytes bool) erro } func (trw *TypeRWStruct) PHPStructFunctionSpecificTypes(code *strings.Builder) { - if trw.ResultType != nil { + if trw.wr.gen.options.AddRPCTypes && trw.ResultType != nil { code.WriteString( fmt.Sprintf( ` @@ -228,7 +228,7 @@ class %[1]s_result implements TL\RpcFunctionReturnResult { func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder) { // print function specific methods and types - if trw.ResultType != nil { + if trw.wr.gen.options.AddRPCTypes && trw.ResultType != nil { kphpSpecialCode := "" if trw.wr.HasAnnotation("kphp") { kphpSpecialCode = fmt.Sprintf( @@ -608,6 +608,9 @@ func (trw *TypeRWStruct) PHPStructConstructor(code *strings.Builder, necessaryFi } func (trw *TypeRWStruct) PHPStructRPCSpecialGetters(code *strings.Builder) { + if !trw.wr.gen.options.AddRPCTypes { + return + } if unionParent := trw.wr.PHPUnionParent(); unionParent == nil || PHPSpecialMembersTypes(unionParent) == "" { return } @@ -779,16 +782,16 @@ func (trw *TypeRWStruct) PHPStructHeader(code *strings.Builder) { implementingInterfaces = append(implementingInterfaces, unionParent.trw.PhpClassName(true, false)) } - if trw.ResultType != nil { + if trw.wr.gen.options.AddRPCTypes && trw.ResultType != nil { implementingInterfaces = append(implementingInterfaces, "TL\\RpcFunction") } - if len(trw.wr.origTL[0].TemplateArguments) == 0 { + if trw.wr.gen.options.AddFunctionBodies && len(trw.wr.origTL[0].TemplateArguments) == 0 { implementingInterfaces = append(implementingInterfaces, "TL\\Readable") implementingInterfaces = append(implementingInterfaces, "TL\\Writeable") } - if trw.wr.gen.options.AddFunctionBodies && len(implementingInterfaces) != 0 { + if len(implementingInterfaces) != 0 { code.WriteString("implements ") code.WriteString(strings.Join(implementingInterfaces, ", ")) code.WriteString(" ") From 848c3beefa780edeb34c7ac690cb02f287ccb009 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 14 Jan 2025 16:02:17 +0300 Subject: [PATCH 12/37] add simplication fature --- cmd/tlgen/main2.go | 2 ++ internal/tlcodegen/tlgen.go | 1 + internal/tlcodegen/tlgen_lang_php.go | 13 +++++++++---- internal/tlcodegen/type_rw.go | 13 ++++++++----- internal/tlcodegen/type_rw_struct_php.go | 17 ++++++++++++----- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index ab2cda3..da7e7b7 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -87,6 +87,8 @@ func parseFlags(opt *tlcodegen.Gen2Options) { `whether to not generate types without usages in functions`) flag.BoolVar(&opt.AddRPCTypes, "php-rpc-support", true, `whether to generate special rpc types`) + flag.BoolVar(&opt.InplaceSimpleStructs, "php-inplace-simple-structs", true, + `whether to avoid generation of structs with no arguments and only 1 field`) if opt.AddFactoryData { opt.AddFunctionBodies = true diff --git a/internal/tlcodegen/tlgen.go b/internal/tlcodegen/tlgen.go index c3eb40f..d962abf 100644 --- a/internal/tlcodegen/tlgen.go +++ b/internal/tlcodegen/tlgen.go @@ -337,6 +337,7 @@ type Gen2Options struct { AddFactoryData bool IgnoreUnusedInFunctionsTypes bool AddRPCTypes bool + InplaceSimpleStructs bool // .tlo TLOPath string diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 14fc092..ab52047 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -280,15 +280,20 @@ func (gen *Gen2) phpCreateFactory() error { } } + includesOfRPC := "" + if gen.options.AddRPCTypes { + includesOfRPC = ` +include "RpcFunction.php"; +include "RpcResponse.php";` + } + code.WriteString(fmt.Sprintf(` Date: Wed, 15 Jan 2025 16:12:19 +0300 Subject: [PATCH 13/37] fix tuple write + dictionary smth --- internal/tlcodegen/type_rw.go | 15 +++++++++++++-- internal/tlcodegen/type_rw_struct_php.go | 15 +++++++++------ internal/tlcodegen/type_rw_tuple.go | 9 +++++++++ internal/tlcodegen/type_rw_tuple_php.go | 6 ++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index a8a586e..e309276 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -594,8 +594,8 @@ func (w *TypeRWWrapper) PHPIsPrimitiveType(recursiveCheck bool) bool { return true } if struct_, isStruct := core.trw.(*TypeRWStruct); isStruct { - isDict, _, _, valueType := isDictionaryElement(struct_.wr) - if isDict && struct_.wr.tlName.Namespace == "" { + if phpIsDictionary(struct_.wr) { + _, _, _, valueType := isDictionaryElement(struct_.wr) return valueType.t.PHPIsPrimitiveType(true) } } @@ -606,10 +606,21 @@ func (w *TypeRWWrapper) PHPIsPrimitiveType(recursiveCheck bool) bool { } func (w *TypeRWWrapper) PHPNeedsCode() bool { + if w.tlName.String() == "dictionary" { + print("debug") + } if w.PHPTypePath() == "" || w.PHPIsPrimitiveType(true) { return false } + // TODO + if _, ok := w.trw.(*TypeRWStruct); ok && + !w.gen.options.InplaceSimpleStructs && + strings.HasSuffix(w.tlName.String(), "dictionary") && + w.tlName.Namespace == "" { + return false + } + if strct, isStrct := w.trw.(*TypeRWStruct); isStrct { unionParent := strct.PhpConstructorNeedsUnion() if strct.ResultType == nil && strct.wr.PHPIsTrueType() && unionParent == nil { diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 11c6f22..dfd0b42 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -91,8 +91,7 @@ func (trw *TypeRWStruct) PhpClassNameReplaced() bool { return true } - isDict, _, _, _ := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + if phpIsDictionary(trw.wr) { return true } } @@ -113,8 +112,8 @@ func (trw *TypeRWStruct) PhpClassName(withPath bool, bare bool) string { return "boolean" } - isDict, _, _, valueType := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + if phpIsDictionary(trw.wr) { // TODO NOT A SOLUTION, BUT... + _, _, _, valueType := isDictionaryElement(trw.wr) return valueType.t.trw.PhpClassName(withPath, bare) } } @@ -153,8 +152,9 @@ func (trw *TypeRWStruct) PhpTypeName(withPath bool, bare bool) string { if trw.PhpCanBeSimplify() { return trw.Fields[0].t.trw.PhpTypeName(withPath, trw.Fields[0].bare) } - isDict, _, _, valueType := isDictionaryElement(trw.wr) - if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + + if phpIsDictionary(trw.wr) { // TODO NOT A SOLUTION, BUT... + _, _, _, valueType := isDictionaryElement(trw.wr) return valueType.t.trw.PhpTypeName(withPath, bare) } } @@ -822,6 +822,9 @@ func isUsingTLImport(trw *TypeRWStruct) bool { } func fieldTypeAndDefaultValue(f Field) (string, string) { + if f.originalName == "dict" { + print("debug") + } fieldType := f.t.trw.PhpTypeName(true, f.t.PHPIsBare()) defaultValue := f.t.trw.PhpDefaultValue() if f.t.PHPIsTrueType() { diff --git a/internal/tlcodegen/type_rw_tuple.go b/internal/tlcodegen/type_rw_tuple.go index 7757855..6d671d2 100644 --- a/internal/tlcodegen/type_rw_tuple.go +++ b/internal/tlcodegen/type_rw_tuple.go @@ -63,6 +63,7 @@ func (trw *TypeRWBrackets) markWantsBytesVersion(visitedNodes map[*TypeRWWrapper func isDictionaryElement(wr *TypeRWWrapper) (bool, bool, Field, Field) { // it is hard to mark Dictionary constructor as dictionary, // because it is typedef to Vector or built-in brackets. + // TODO: FIX IT, because len(structElement.Fields) != 2 is true structElement, ok := wr.trw.(*TypeRWStruct) if !ok || len(structElement.Fields) != 2 || !strings.Contains(strings.ToLower(wr.tlName.Name), "dictionary") { return false, false, Field{}, Field{} @@ -74,6 +75,14 @@ func isDictionaryElement(wr *TypeRWWrapper) (bool, bool, Field, Field) { return ok, isString, structElement.Fields[0], structElement.Fields[1] } +func phpIsDictionary(wr *TypeRWWrapper) bool { + isDict, _, _, _ := isDictionaryElement(wr) + if isDict && wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... + return true + } + return false +} + func (trw *TypeRWBrackets) FillRecursiveChildren(visitedNodes map[*TypeRWWrapper]int, generic bool) { for _, typeDep := range trw.AllPossibleRecursionProducers() { typeDep.trw.FillRecursiveChildren(visitedNodes, generic) diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index e50eb49..ff42b0f 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -123,6 +123,12 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { result := make([]string, 0) + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(count(%[1]s));", targetName), + "if (!$success) {", + " return false;", + "}", + ) switch { // actual vector case trw.vectorLike && !trw.dictLike: From 9128a3c1f257d41ff4f7e9997e3e565f4089f352 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 16:16:24 +0300 Subject: [PATCH 14/37] full include in factory, who cares --- internal/tlcodegen/tlgen_lang_php.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index ab52047..43a3c33 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -275,9 +275,9 @@ func (gen *Gen2) phpCreateFactory() error { includes := "" for _, wr := range gen.PhpSelectTypesForGeneration() { - if addFactory(wr) { - includes += fmt.Sprintf("include \"%s\";\n", filepath.Join(wr.PHPFilePath(true)[2:]...)) - } + //if addFactory(wr) { + includes += fmt.Sprintf("include \"%s\";\n", filepath.Join(wr.PHPFilePath(true)[2:]...)) + //} } includesOfRPC := "" From 1389ce80f8608640868cdccb3346b79254ad88df Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 16:36:32 +0300 Subject: [PATCH 15/37] fieldmask fix + tuple size --- internal/tlcodegen/type_rw_struct_php.go | 4 ++-- internal/tlcodegen/type_rw_tuple_php.go | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index dfd0b42..67f2854 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -344,7 +344,7 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { if fieldMask != "" { code.WriteString( fmt.Sprintf( - "%[1]sif (%[2]s & (1 << %[3]d) != 0) {\n", + "%[1]sif ((%[2]s & (1 << %[3]d)) != 0) {\n", textTab(), fieldMask, field.BitNumber, @@ -432,7 +432,7 @@ func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { if fieldMask != "" { code.WriteString( fmt.Sprintf( - "%[1]sif (%[2]s & (1 << %[3]d) != 0) {\n", + "%[1]sif ((%[2]s & (1 << %[3]d)) != 0) {\n", textTab(), fieldMask, field.BitNumber, diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index ff42b0f..6762542 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -123,15 +123,15 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { result := make([]string, 0) - result = append(result, - fmt.Sprintf("$success = $stream->write_uint32(count(%[1]s));", targetName), - "if (!$success) {", - " return false;", - "}", - ) switch { // actual vector case trw.vectorLike && !trw.dictLike: + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(count(%[1]s));", targetName), + "if (!$success) {", + " return false;", + "}", + ) result = append(result, fmt.Sprintf("$vector_size = count(%[1]s);", targetName), // TODO MAKE MORE EFFICIENT @@ -168,6 +168,12 @@ func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args return result // actual map / dictionary case trw.dictLike: + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(count(%[1]s));", targetName), + "if (!$success) {", + " return false;", + "}", + ) keyElement := "$key" valueElement := "$value" result = append(result, From d967b86b12964b79d4ff9ef24be7f1ccee042a39 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 18:14:44 +0300 Subject: [PATCH 16/37] dictionary additional support --- internal/tlcodegen/type_rw_struct_php.go | 64 ++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 67f2854..e8c49d2 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -94,6 +94,12 @@ func (trw *TypeRWStruct) PhpClassNameReplaced() bool { if phpIsDictionary(trw.wr) { return true } + + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + return true + } } return false } @@ -116,6 +122,12 @@ func (trw *TypeRWStruct) PhpClassName(withPath bool, bare bool) string { _, _, _, valueType := isDictionaryElement(trw.wr) return valueType.t.trw.PhpClassName(withPath, bare) } + + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + return trw.Fields[0].t.trw.PhpClassName(withPath, bare) + } } name := trw.wr.tlName.Name @@ -157,6 +169,12 @@ func (trw *TypeRWStruct) PhpTypeName(withPath bool, bare bool) string { _, _, _, valueType := isDictionaryElement(trw.wr) return valueType.t.trw.PhpTypeName(withPath, bare) } + + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + return trw.Fields[0].t.trw.PhpTypeName(withPath, bare) + } } return trw.PhpClassName(withPath, bare) } @@ -726,6 +744,9 @@ func (trw *TypeRWStruct) PHPStructResultType(code *strings.Builder) { func (trw *TypeRWStruct) PHPStructFields(code *strings.Builder) { // print fields declarations for _, f := range trw.Fields { + if trw.PhpClassName(false, true) == "cases_testDictString" && f.originalName == "dict" { + print("debug") + } fieldType, defaultValue := fieldTypeAndDefaultValue(f) code.WriteString( fmt.Sprintf( @@ -822,9 +843,6 @@ func isUsingTLImport(trw *TypeRWStruct) bool { } func fieldTypeAndDefaultValue(f Field) (string, string) { - if f.originalName == "dict" { - print("debug") - } fieldType := f.t.trw.PhpTypeName(true, f.t.PHPIsBare()) defaultValue := f.t.trw.PhpDefaultValue() if f.t.PHPIsTrueType() { @@ -852,6 +870,11 @@ func (trw *TypeRWStruct) PhpDefaultValue() string { if core.PHPIsTrueType() { return "true" } + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + return trw.Fields[0].t.trw.PhpDefaultValue() + } return "null" } @@ -913,6 +936,21 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] //if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... // return valueType.t.trw.PhpTypeName(withPath, bare) //} + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + 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, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, bare, args)...) + return result + } } return []string{ fmt.Sprintf("if (%[1]s == null) {", targetName), @@ -960,6 +998,21 @@ func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args [ //if isDict && trw.wr.tlName.Namespace == "" { // TODO NOT A SOLUTION, BUT... // return valueType.t.trw.PhpTypeName(withPath, bare) //} + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + var result []string + if !bare { + result = append(result, + fmt.Sprintf("$success = $stream->write_uint32(0x%08[1]x);", trw.wr.tlTag), + "if (!$success) {", + " return false;", + "}", + ) + } + result = append(result, trw.Fields[0].t.trw.PhpWriteMethodCall(targetName, bare, args)...) + return result + } } return []string{ fmt.Sprintf("if (%[1]s == null) {", targetName), @@ -980,6 +1033,11 @@ func (trw *TypeRWStruct) PhpDefaultInit() string { if core.PHPIsTrueType() { return "true" } + if !trw.wr.gen.options.InplaceSimpleStructs && + strings.HasSuffix(trw.wr.tlName.String(), "dictionary") && + trw.wr.tlName.Namespace == "" { + return trw.Fields[0].t.trw.PhpDefaultInit() + } return fmt.Sprintf("new %s()", core.trw.PhpClassName(true, true)) } From b7e68dc735bdba19736f9030fa48ff62a1a77334 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 19:03:30 +0300 Subject: [PATCH 17/37] fix different read/write issues --- internal/tlcodegen/type_rw_maybe_php.go | 6 +++--- internal/tlcodegen/type_rw_struct_php.go | 9 +++++--- internal/tlcodegen/type_rw_tuple_php.go | 27 ++++++++++++------------ internal/tlcodegen/type_rw_union_php.go | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index 5360d18..c8809da 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -54,7 +54,7 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []s } if trw.element.t == trw.getInnerTarget().t { result = append(result, - fmt.Sprintf(" if (%[1]s == null) {", targetName), + fmt.Sprintf(" if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.element.t.trw.PhpDefaultInit()), " }", ) @@ -78,7 +78,7 @@ func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args [] if !bare { result := []string{ fmt.Sprintf( - "$success = $stream->write_bool(%[1]s != null, 0x%08[1]x, 0x%08[2]x);", + "$success = $stream->write_bool(!is_null(%[1]s), 0x%08[2]x, 0x%08[3]x);", targetName, trw.emptyTag, trw.okTag, @@ -86,7 +86,7 @@ func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args [] "if (!$success) {", " return false;", "}", - fmt.Sprintf("if (%[1]s != null) {", targetName), + fmt.Sprintf("if (!is_null(%[1]s)) {", targetName), } { bodyWriter := trw.element.t.trw.PhpWriteMethodCall(targetName, trw.element.bare, args) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index e8c49d2..c1c46a4 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -370,6 +370,9 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { ) shift += 1 } + if trw.wr.tlName.String() == "cases.replace7" && field.originalName == "a" { + print("debug") + } fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) for _, line := range fieldRead { code.WriteString(textTab() + line + "\n") @@ -556,7 +559,7 @@ func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, us condition = fmt.Sprintf("$has_%s", dependentField.originalName) } else { condition = fmt.Sprintf( - "$this->%[1]s !== null", + "!is_null($this->%[1]s)", dependentField.originalName, ) } @@ -953,7 +956,7 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] } } return []string{ - fmt.Sprintf("if (%[1]s == null) {", targetName), + fmt.Sprintf("if (is_null(%[1]s)) {", 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)), @@ -1015,7 +1018,7 @@ func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args [ } } return []string{ - fmt.Sprintf("if (%[1]s == null) {", targetName), + fmt.Sprintf("if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), "}", fmt.Sprintf("$success = %[2]s->write%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index 6762542..e301787 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -42,6 +42,7 @@ func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWW } func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args []string) []string { + index := fmt.Sprintf("$i%d", len(trw.PhpClassName(false, true))) result := make([]string, 0) switch { // actual vector @@ -58,7 +59,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args "}", // TODO MAKE MORE EFFICIENT fmt.Sprintf("%[1]s = [];", targetName), - "for($i = 0; $i < $vector_size; $i++) {", + fmt.Sprintf("for(%[1]s = 0; %[1]s < $vector_size; %[1]s++) {", index), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) result = append(result, elementRead...) @@ -70,8 +71,8 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args // tuple with size as last argument case !trw.vectorLike && !trw.dictLike: elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) - tupleSize := args[len(args)-1] - elementArgs := args[:len(args)-1] + tupleSize := args[0] + elementArgs := args[1:] elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, elementArgs) for i := range elementRead { elementRead[i] = " " + elementRead[i] @@ -79,7 +80,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args result = append(result, // TODO MAKE MORE EFFICIENT fmt.Sprintf("%[1]s = [];", targetName), - fmt.Sprintf("for($i = 0; $i < %[1]s; $i++) {", tupleSize), + fmt.Sprintf("for(%[1]s = 0; %[1]s < %[2]s; %[1]s++) {", index, tupleSize), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) result = append(result, elementRead...) @@ -100,7 +101,6 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args for i := range valueRead { valueRead[i] = " " + valueRead[i] } - result = append(result, "[$dict_size, $success] = $stream->read_uint32();", "if (!$success) {", @@ -108,7 +108,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args "}", // TODO MAKE MORE EFFICIENT fmt.Sprintf("%[1]s = [];", targetName), - "for($i = 0; $i < $dict_size; $i++) {", + fmt.Sprintf("for(%[1]s = 0; %[1]s < $dict_size; %[1]s++) {", index), ) result = append(result, keyRead...) result = append(result, valueRead...) @@ -122,6 +122,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args } func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { + index := fmt.Sprintf("$i%d", len(trw.PhpClassName(false, true))) result := make([]string, 0) switch { // actual vector @@ -133,12 +134,11 @@ func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args "}", ) result = append(result, - fmt.Sprintf("$vector_size = count(%[1]s);", targetName), // TODO MAKE MORE EFFICIENT - "for($i = 0; $i < $vector_size; $i++) {", + fmt.Sprintf("for(%[1]s = 0; %[1]s < count(%[2]s); %[1]s++) {", index, targetName), ) { - elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[$i]", targetName), trw.element.bare, args) + elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[%[2]s]", targetName, index), trw.element.bare, args) for i := range elementRead { elementRead[i] = " " + elementRead[i] } @@ -150,15 +150,14 @@ func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args return result // tuple with size as last argument case !trw.vectorLike && !trw.dictLike: - tupleSize := args[len(args)-1] - elementArgs := args[:len(args)-1] + tupleSize := args[0] + elementArgs := args[1:] result = append(result, - fmt.Sprintf("$tuple_size = %[1]s;", tupleSize), // TODO MAKE MORE EFFICIENT - "for($i = 0; $i < $tuple_size; $i++) {", + fmt.Sprintf("for(%[1]s = 0; %[1]s < %[2]s; %[1]s++) {", index, tupleSize), ) { - elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[$i]", targetName), trw.element.bare, elementArgs) + elementRead := trw.element.t.trw.PhpWriteMethodCall(fmt.Sprintf("%[1]s[%[2]s]", targetName, index), trw.element.bare, elementArgs) for i := range elementRead { elementRead[i] = " " + elementRead[i] } diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 21477d9..86849e3 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -159,7 +159,7 @@ func (trw *TypeRWUnion) PhpWriteMethodCall(targetName string, bare bool, args [] } var result []string result = append(result, - fmt.Sprintf("if (%[1]s == null) {", targetName), + fmt.Sprintf("if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), "}", fmt.Sprintf("$success = %[1]s->write_boxed($stream%[2]s);", targetName, phpFormatArgs(args)), From 2debf9b8b8f54194032d772e149d8e5b0be53c47 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 19:05:22 +0300 Subject: [PATCH 18/37] add cases gen to php --- .../Types/dictionaryFieldAny__float__int.php | 89 + .../Types/benchmarks_VrutoyTopLevelUnion.php | 35 + .../benchmarks/Types/benchmarks_vruhash.php | 89 + .../Types/benchmarks_vruposition.php | 242 +++ .../benchmarks_vrutoyTopLevelContainer.php | 99 + ..._vrutoyTopLevelContainerWithDependency.php | 102 + .../benchmarks_vrutoytopLevelUnionBig.php | 97 + .../benchmarks_vrutoytopLevelUnionEmpty.php | 64 + .../VK/TL/cases/Types/cases_TestEnum.php | 36 + .../VK/TL/cases/Types/cases_TestUnion.php | 35 + .../VK/TL/cases/Types/cases_myCycle1.php | 115 ++ .../VK/TL/cases/Types/cases_myCycle2.php | 115 ++ .../VK/TL/cases/Types/cases_myCycle3.php | 115 ++ .../VK/TL/cases/Types/cases_replace7.php | 116 ++ .../VK/TL/cases/Types/cases_replace7plus.php | 136 ++ .../TL/cases/Types/cases_replace7plusplus.php | 136 ++ .../cases_testAllPossibleFieldConfigs.php | 359 ++++ ...s_testAllPossibleFieldConfigsContainer.php | 95 + .../VK/TL/cases/Types/cases_testArray.php | 96 + .../cases_testBeforeReadBitValidation.php | 147 ++ .../VK/TL/cases/Types/cases_testDictAny.php | 97 + .../VK/TL/cases/Types/cases_testDictInt.php | 99 + .../TL/cases/Types/cases_testDictString.php | 99 + .../VK/TL/cases/Types/cases_testEnum1.php | 64 + .../VK/TL/cases/Types/cases_testEnum2.php | 64 + .../VK/TL/cases/Types/cases_testEnum3.php | 64 + .../cases/Types/cases_testEnumContainer.php | 107 ++ .../cases/Types/cases_testLocalFieldmask.php | 144 ++ .../VK/TL/cases/Types/cases_testMaybe.php | 93 + .../TL/cases/Types/cases_testOutFieldMask.php | 135 ++ .../Types/cases_testOutFieldMaskContainer.php | 95 + .../Types/cases_testRecursiveFieldMask.php | 188 ++ .../VK/TL/cases/Types/cases_testTuple.php | 83 + .../VK/TL/cases/Types/cases_testUnion1.php | 76 + .../VK/TL/cases/Types/cases_testUnion2.php | 76 + .../cases/Types/cases_testUnionContainer.php | 99 + .../VK/TL/cases/Types/cases_testVector.php | 91 + .../Types/cases_bytes_TestEnum.php | 36 + .../Types/cases_bytes_testArray.php | 96 + .../Types/cases_bytes_testDictAny.php | 97 + .../Types/cases_bytes_testDictInt.php | 99 + .../Types/cases_bytes_testDictString.php | 99 + .../cases_bytes_testDictStringString.php | 99 + .../Types/cases_bytes_testEnum1.php | 64 + .../Types/cases_bytes_testEnum2.php | 64 + .../Types/cases_bytes_testEnum3.php | 64 + .../Types/cases_bytes_testEnumContainer.php | 107 ++ .../Types/cases_bytes_testTuple.php | 83 + .../Types/cases_bytes_testVector.php | 91 + .../test/gen/cases_php/VK/TL/factory.php | 192 ++ .../test/gen/cases_php/VK/TL/meta.php | 192 ++ .../gen/cases_php/VK/TL/tl_interfaces.php | 35 + .../test/gen/cases_php/VK/TL/tl_streams.php | 251 +++ .../test/gen/cases_php/tlgen2_version.txt | 4 + .../tlcodegen/test/gen/cases_php/tljson.html | 1675 +++++++++++++++++ 55 files changed, 7340 insertions(+) create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/_common/Types/dictionaryFieldAny__float__int.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_VrutoyTopLevelUnion.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruhash.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionEmpty.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_TestEnum.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_TestUnion.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle1.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictInt.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictString.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum1.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum2.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum3.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testMaybe.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion1.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion2.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_TestEnum.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testArray.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictInt.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictString.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictStringString.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum1.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum2.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum3.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/tl_interfaces.php create mode 100644 internal/tlcodegen/test/gen/cases_php/VK/TL/tl_streams.php create mode 100644 internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt create mode 100644 internal/tlcodegen/test/gen/cases_php/tljson.html diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/_common/Types/dictionaryFieldAny__float__int.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/_common/Types/dictionaryFieldAny__float__int.php new file mode 100644 index 0000000..c97ca44 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/_common/Types/dictionaryFieldAny__float__int.php @@ -0,0 +1,89 @@ +key = $key; + $this->value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x2c43a65b) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->key, $success] = $stream->read_double(); + if (!$success) { + return false; + } + [$this->value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x2c43a65b); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_double($this->key); + if (!$success) { + return false; + } + $success = $stream->write_int32($this->value); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_VrutoyTopLevelUnion.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_VrutoyTopLevelUnion.php new file mode 100644 index 0000000..fbaee7e --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_VrutoyTopLevelUnion.php @@ -0,0 +1,35 @@ +low = $low; + $this->high = $high; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xd31bd0fd) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->low, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + [$this->high, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xd31bd0fd); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_int64($this->low); + if (!$success) { + return false; + } + $success = $stream->write_int64($this->high); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php new file mode 100644 index 0000000..873e4e6 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php @@ -0,0 +1,242 @@ +fields_mask = $fields_mask; + $this->payload_offset = $payload_offset; + $this->block_time_nano = $block_time_nano; + $this->hash = $hash; + $this->file_offset = $file_offset; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x32792c04) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->fields_mask, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + $this->commit_bit = true; + } else { + $this->commit_bit = false; + } + if (($this->fields_mask & (1 << 1)) != 0) { + $this->meta_block = true; + } else { + $this->meta_block = false; + } + if (($this->fields_mask & (1 << 3)) != 0) { + $this->split_payload = true; + } else { + $this->split_payload = false; + } + if (($this->fields_mask & (1 << 5)) != 0) { + $this->rotation_block = true; + } else { + $this->rotation_block = false; + } + if (($this->fields_mask & (1 << 15)) != 0) { + $this->canonical_hash = true; + } else { + $this->canonical_hash = false; + } + [$this->payload_offset, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + [$this->block_time_nano, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + if ($this->hash == null) { + $this->hash = new TL\benchmarks\Types\benchmarks_vruhash(); + } + $success = $this->hash->read($stream); + if (!$success) { + return false; + } + [$this->file_offset, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 14)) != 0) { + [$this->seq_number, $success] = $stream->read_int64(); + if (!$success) { + return false; + } + } else { + $this->seq_number = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x32792c04); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->fields_mask); + if (!$success) { + return false; + } + $success = $stream->write_int64($this->payload_offset); + if (!$success) { + return false; + } + $success = $stream->write_int64($this->block_time_nano); + if (!$success) { + return false; + } + if ($this->hash == null) { + $this->hash = new TL\benchmarks\Types\benchmarks_vruhash(); + } + $success = $this->hash->write($stream); + if (!$success) { + return false; + } + $success = $stream->write_int64($this->file_offset); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 14)) != 0) { + $success = $stream->write_int64($this->seq_number); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateFieldsMask() { + $mask = 0; + + if ($this->commit_bit) { + $mask |= self::BIT_COMMIT_BIT_0; + } + + if ($this->meta_block) { + $mask |= self::BIT_META_BLOCK_1; + } + + if ($this->split_payload) { + $mask |= self::BIT_SPLIT_PAYLOAD_3; + } + + if ($this->rotation_block) { + $mask |= self::BIT_ROTATION_BLOCK_5; + } + + if ($this->seq_number !== null) { + $mask |= self::BIT_SEQ_NUMBER_14; + } + + if ($this->canonical_hash) { + $mask |= self::BIT_CANONICAL_HASH_15; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php new file mode 100644 index 0000000..b3f5e31 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php @@ -0,0 +1,99 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xfb442ca5) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$tag, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + switch ($tag) { + case 0xef556bee: + $variant = new TL\benchmarks\Types\benchmarks_vrutoytopLevelUnionBig(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0xce27c770: + $variant = new TL\benchmarks\Types\benchmarks_vrutoytopLevelUnionEmpty(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + default: + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xfb442ca5); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + if ($this->value == null) { + $this->value = new TL\benchmarks\Types\benchmarks_vrutoytopLevelUnionBig(); + } + $success = $this->value->write_boxed($stream); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php new file mode 100644 index 0000000..08fae3a --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php @@ -0,0 +1,102 @@ +n = $n; + $this->value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xc176008e) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->value = []; + for($i28 = 0; $i28 < $this->n; $i28++) { + $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); + if ($array_benchmarks_VruPosition___element == null) { + $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); + } + $success = $array_benchmarks_VruPosition___element->read($stream); + if (!$success) { + return false; + } + $this->value[] = $array_benchmarks_VruPosition___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xc176008e); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + for($i28 = 0; $i28 < $this->n; $i28++) { + if ($this->value[$i28] == null) { + $this->value[$i28] = new TL\benchmarks\Types\benchmarks_vruposition(); + } + $success = $this->value[$i28]->write($stream); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php new file mode 100644 index 0000000..1f72992 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php @@ -0,0 +1,97 @@ +next_positions = $next_positions; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xef556bee) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$vector_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->next_positions = []; + for($i28 = 0; $i28 < $vector_size; $i28++) { + $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); + if ($array_benchmarks_VruPosition___element == null) { + $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); + } + $success = $array_benchmarks_VruPosition___element->read($stream); + if (!$success) { + return false; + } + $this->next_positions[] = $array_benchmarks_VruPosition___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xef556bee); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->next_positions)); + if (!$success) { + return false; + } + for($i28 = 0; $i28 < count($this->next_positions); $i28++) { + if ($this->next_positions[$i28] == null) { + $this->next_positions[$i28] = new TL\benchmarks\Types\benchmarks_vruposition(); + } + $success = $this->next_positions[$i28]->write($stream); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionEmpty.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionEmpty.php new file mode 100644 index 0000000..eb0d320 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionEmpty.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0xce27c770) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xce27c770); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_TestEnum.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_TestEnum.php new file mode 100644 index 0000000..6f5e3a3 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_TestEnum.php @@ -0,0 +1,36 @@ +fields_mask = $fields_mask; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xd3ca919d) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->fields_mask, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle2(); + } + $success = $this->a->read($stream); + if (!$success) { + return false; + } + } else { + $this->a = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xd3ca919d); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->fields_mask); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle2(); + } + $success = $this->a->write($stream); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateFieldsMask() { + $mask = 0; + + if ($this->a) { + $mask |= self::BIT_A_0; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php new file mode 100644 index 0000000..1d1c830 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php @@ -0,0 +1,115 @@ +fields_mask = $fields_mask; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x5444c9a2) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->fields_mask, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle3(); + } + $success = $this->a->read($stream); + if (!$success) { + return false; + } + } else { + $this->a = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x5444c9a2); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->fields_mask); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle3(); + } + $success = $this->a->write($stream); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateFieldsMask() { + $mask = 0; + + if ($this->a) { + $mask |= self::BIT_A_0; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php new file mode 100644 index 0000000..6236610 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php @@ -0,0 +1,115 @@ +fields_mask = $fields_mask; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x7624f86b) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->fields_mask, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle1(); + } + $success = $this->a->read($stream); + if (!$success) { + return false; + } + } else { + $this->a = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x7624f86b); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->fields_mask); + if (!$success) { + return false; + } + if (($this->fields_mask & (1 << 0)) != 0) { + if ($this->a == null) { + $this->a = new TL\cases\Types\cases_myCycle1(); + } + $success = $this->a->write($stream); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateFieldsMask() { + $mask = 0; + + if ($this->a) { + $mask |= self::BIT_A_0; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php new file mode 100644 index 0000000..eb53a11 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php @@ -0,0 +1,116 @@ +n = $n; + $this->m = $m; + $this->a = $a; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x6ccce4be) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + [$this->m, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->a = []; + for($i15 = 0; $i15 < $this->n; $i15++) { + $array_array_int___element = []; + $array_array_int___element = []; + for($i9 = 0; $i9 < $this->m; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $array_array_int___element[] = $array_int___element; + } + $this->a[] = $array_array_int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x6ccce4be); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + $success = $stream->write_uint32($this->m); + if (!$success) { + return false; + } + for($i15 = 0; $i15 < $this->n; $i15++) { + for($i9 = 0; $i9 < $this->m; $i9++) { + $success = $stream->write_int32($this->a[$i15][$i9]); + if (!$success) { + return false; + } + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php new file mode 100644 index 0000000..8f9a8d5 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php @@ -0,0 +1,136 @@ +n = $n; + $this->m = $m; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x197858f5) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + [$this->m, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->n & (1 << 0)) != 0) { + $this->a = []; + for($i15 = 0; $i15 < $this->n; $i15++) { + $array_array_int___element = []; + $array_array_int___element = []; + for($i9 = 0; $i9 < $this->m; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $array_array_int___element[] = $array_int___element; + } + $this->a[] = $array_array_int___element; + } + } else { + $this->a = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x197858f5); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + $success = $stream->write_uint32($this->m); + if (!$success) { + return false; + } + if (($this->n & (1 << 0)) != 0) { + for($i15 = 0; $i15 < $this->n; $i15++) { + for($i9 = 0; $i9 < $this->m; $i9++) { + $success = $stream->write_int32($this->a[$i15][$i9]); + if (!$success) { + return false; + } + } + } + } + return true; + } + + /** + * @return int + */ + public function calculateN() { + $mask = 0; + + if ($this->a !== null) { + $mask |= self::BIT_A_0; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php new file mode 100644 index 0000000..625f866 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php @@ -0,0 +1,136 @@ +N = $N; + $this->M = $M; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xabc39b68) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->N, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + [$this->M, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->N & (1 << 0)) != 0) { + $this->A = []; + for($i15 = 0; $i15 < $this->N; $i15++) { + $array_array_int___element = []; + $array_array_int___element = []; + for($i9 = 0; $i9 < $this->M; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $array_array_int___element[] = $array_int___element; + } + $this->A[] = $array_array_int___element; + } + } else { + $this->A = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xabc39b68); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->N); + if (!$success) { + return false; + } + $success = $stream->write_uint32($this->M); + if (!$success) { + return false; + } + if (($this->N & (1 << 0)) != 0) { + for($i15 = 0; $i15 < $this->N; $i15++) { + for($i9 = 0; $i9 < $this->M; $i9++) { + $success = $stream->write_int32($this->A[$i15][$i9]); + if (!$success) { + return false; + } + } + } + } + return true; + } + + /** + * @return int + */ + public function calculateN() { + $mask = 0; + + if ($this->A !== null) { + $mask |= self::BIT_A_0; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php new file mode 100644 index 0000000..9a26858 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php @@ -0,0 +1,359 @@ +local = $local; + $this->f00 = $f00; + $this->f01 = $f01; + $this->f02 = $f02; + $this->f03 = $f03; + } + + /** + * @param TL\tl_input_stream $stream + * @param int $outer + * @return bool + */ + public function read_boxed($stream, $outer) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xfb6836d3) { + return false; + } + return $this->read($stream, $outer); + } + + /** + * @param TL\tl_input_stream $stream + * @param int $outer + * @return bool + */ + public function read($stream, $outer) { + [$this->local, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + [$this->f00, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f01 = true; + $this->f02 = []; + for($i9 = 0; $i9 < $this->local; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f02[] = $array_int___element; + } + $this->f03 = []; + for($i9 = 0; $i9 < $outer; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f03[] = $array_int___element; + } + if (($this->local & (1 << 0)) != 0) { + [$this->f10, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + } else { + $this->f10 = null; + } + if (($this->local & (1 << 1)) != 0) { + $this->f11 = true; + } else { + $this->f11 = false; + } + if (($this->local & (1 << 2)) != 0) { + $this->f12 = []; + for($i9 = 0; $i9 < $this->local; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f12[] = $array_int___element; + } + } else { + $this->f12 = null; + } + if (($this->local & (1 << 3)) != 0) { + $this->f13 = []; + for($i9 = 0; $i9 < $outer; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f13[] = $array_int___element; + } + } else { + $this->f13 = null; + } + if (($outer & (1 << 0)) != 0) { + [$this->f20, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + } else { + $this->f20 = null; + } + if (($outer & (1 << 1)) != 0) { + $this->f21 = true; + } else { + $this->f21 = false; + } + if (($outer & (1 << 2)) != 0) { + $this->f22 = []; + for($i9 = 0; $i9 < $this->local; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f22[] = $array_int___element; + } + } else { + $this->f22 = null; + } + if (($outer & (1 << 3)) != 0) { + $this->f23 = []; + for($i9 = 0; $i9 < $outer; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f23[] = $array_int___element; + } + } else { + $this->f23 = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @param int $outer + * @return bool + */ + public function write_boxed($stream, $outer) { + $success = $stream->write_uint32(0xfb6836d3); + if (!$success) { + return false; + } + return $this->write($stream, $outer); + } + + /** + * @param TL\tl_output_stream $stream + * @param int $outer + * @return bool + */ + public function write($stream, $outer) { + $success = $stream->write_uint32($this->local); + if (!$success) { + return false; + } + $success = $stream->write_int32($this->f00); + if (!$success) { + return false; + } + for($i9 = 0; $i9 < $this->local; $i9++) { + $success = $stream->write_int32($this->f02[$i9]); + if (!$success) { + return false; + } + } + for($i9 = 0; $i9 < $outer; $i9++) { + $success = $stream->write_int32($this->f03[$i9]); + if (!$success) { + return false; + } + } + if (($this->local & (1 << 0)) != 0) { + $success = $stream->write_int32($this->f10); + if (!$success) { + return false; + } + } + if (($this->local & (1 << 2)) != 0) { + for($i9 = 0; $i9 < $this->local; $i9++) { + $success = $stream->write_int32($this->f12[$i9]); + if (!$success) { + return false; + } + } + } + if (($this->local & (1 << 3)) != 0) { + for($i9 = 0; $i9 < $outer; $i9++) { + $success = $stream->write_int32($this->f13[$i9]); + if (!$success) { + return false; + } + } + } + if (($outer & (1 << 0)) != 0) { + $success = $stream->write_int32($this->f20); + if (!$success) { + return false; + } + } + if (($outer & (1 << 2)) != 0) { + for($i9 = 0; $i9 < $this->local; $i9++) { + $success = $stream->write_int32($this->f22[$i9]); + if (!$success) { + return false; + } + } + } + if (($outer & (1 << 3)) != 0) { + for($i9 = 0; $i9 < $outer; $i9++) { + $success = $stream->write_int32($this->f23[$i9]); + if (!$success) { + return false; + } + } + } + return true; + } + + /** + * @return int + */ + public function calculateLocal() { + $mask = 0; + + if ($this->f10 !== null) { + $mask |= self::BIT_F10_0; + } + + if ($this->f11) { + $mask |= self::BIT_F11_1; + } + + if ($this->f12 !== null) { + $mask |= self::BIT_F12_2; + } + + if ($this->f13 !== null) { + $mask |= self::BIT_F13_3; + } + + return $mask; + } + + /** + * @return int + */ + public function calculateOuter() { + $mask = 0; + + if ($this->f20 !== null) { + $mask |= self::BIT_F20_0; + } + + if ($this->f21) { + $mask |= self::BIT_F21_1; + } + + if ($this->f22 !== null) { + $mask |= self::BIT_F22_2; + } + + if ($this->f23 !== null) { + $mask |= self::BIT_F23_3; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php new file mode 100644 index 0000000..1471ebc --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php @@ -0,0 +1,95 @@ +outer = $outer; + $this->value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xe3fae936) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->outer, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if ($this->value == null) { + $this->value = new TL\cases\Types\cases_testAllPossibleFieldConfigs(); + } + $success = $this->value->read($stream, $this->outer); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xe3fae936); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->outer); + if (!$success) { + return false; + } + if ($this->value == null) { + $this->value = new TL\cases\Types\cases_testAllPossibleFieldConfigs(); + } + $success = $this->value->write($stream, $this->outer); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php new file mode 100644 index 0000000..dc6add0 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php @@ -0,0 +1,96 @@ +n = $n; + $this->arr = $arr; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xa888030d) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->arr = []; + for($i9 = 0; $i9 < $this->n; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->arr[] = $array_int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xa888030d); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + for($i9 = 0; $i9 < $this->n; $i9++) { + $success = $stream->write_int32($this->arr[$i9]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php new file mode 100644 index 0000000..c7d40d7 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php @@ -0,0 +1,147 @@ +n = $n; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x9b2396db) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->n & (1 << 0)) != 0) { + $this->a = []; + for($i9 = 0; $i9 < $this->n; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->a[] = $array_int___element; + } + } else { + $this->a = null; + } + if (($this->n & (1 << 1)) != 0) { + $this->b = []; + for($i9 = 0; $i9 < $this->n; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->b[] = $array_int___element; + } + } else { + $this->b = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x9b2396db); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + if (($this->n & (1 << 0)) != 0) { + for($i9 = 0; $i9 < $this->n; $i9++) { + $success = $stream->write_int32($this->a[$i9]); + if (!$success) { + return false; + } + } + } + if (($this->n & (1 << 1)) != 0) { + for($i9 = 0; $i9 < $this->n; $i9++) { + $success = $stream->write_int32($this->b[$i9]); + if (!$success) { + return false; + } + } + } + return true; + } + + /** + * @return int + */ + public function calculateN() { + $mask = 0; + + if ($this->a !== null) { + $mask |= self::BIT_A_0; + } + + if ($this->b !== null) { + $mask |= self::BIT_B_1; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php new file mode 100644 index 0000000..ee443a8 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php @@ -0,0 +1,97 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xe29b8ae6) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$vector_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i36 = 0; $i36 < $vector_size; $i36++) { + $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); + if ($array_DictionaryFieldAny__float__int___element == null) { + $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); + } + $success = $array_DictionaryFieldAny__float__int___element->read($stream); + if (!$success) { + return false; + } + $this->dict[] = $array_DictionaryFieldAny__float__int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xe29b8ae6); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + for($i36 = 0; $i36 < count($this->dict); $i36++) { + if ($this->dict[$i36] == null) { + $this->dict[$i36] = new TL\_common\Types\dictionaryFieldAny__float__int(); + } + $success = $this->dict[$i36]->write($stream); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictInt.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictInt.php new file mode 100644 index 0000000..bf92378 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictInt.php @@ -0,0 +1,99 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xd3877643) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$dict_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i9 = 0; $i9 < $dict_size; $i9++) { + [$array_int___key, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + [$array_int___value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->dict[$array_int___key] = $array_int___value; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xd3877643); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + ksort($this->dict); + foreach($this->dict as $key => $value) { + $success = $stream->write_int32($key); + if (!$success) { + return false; + } + $success = $stream->write_int32($value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictString.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictString.php new file mode 100644 index 0000000..a6ee3ea --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictString.php @@ -0,0 +1,99 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xc463c79b) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$dict_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i9 = 0; $i9 < $dict_size; $i9++) { + [$array_int___key, $success] = $stream->read_string(); + if (!$success) { + return false; + } + [$array_int___value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->dict[$array_int___key] = $array_int___value; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xc463c79b); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + ksort($this->dict); + foreach($this->dict as $key => $value) { + $success = $stream->write_string($key); + if (!$success) { + return false; + } + $success = $stream->write_int32($value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum1.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum1.php new file mode 100644 index 0000000..4eebc67 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum1.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x6c6c55ac) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x6c6c55ac); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum2.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum2.php new file mode 100644 index 0000000..c7f4df7 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum2.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x86ea88ce) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x86ea88ce); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum3.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum3.php new file mode 100644 index 0000000..47cc536 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnum3.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x69b83e2f) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x69b83e2f); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php new file mode 100644 index 0000000..7098fa2 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php @@ -0,0 +1,107 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xcb684231) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$tag, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + switch ($tag) { + case 0x6c6c55ac: + $variant = new TL\cases\Types\cases_testEnum1(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0x86ea88ce: + $variant = new TL\cases\Types\cases_testEnum2(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0x69b83e2f: + $variant = new TL\cases\Types\cases_testEnum3(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + default: + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xcb684231); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + if ($this->value == null) { + $this->value = new TL\cases\Types\cases_testEnum1(); + } + $success = $this->value->write_boxed($stream); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php new file mode 100644 index 0000000..637d524 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php @@ -0,0 +1,144 @@ +f1 = $f1; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xf68fd3f9) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->f1, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->f1 & (1 << 0)) != 0) { + [$this->f2, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + } else { + $this->f2 = null; + } + if (($this->f2 & (1 << 1)) != 0) { + $this->f3 = true; + } else { + $this->f3 = false; + } + if (($this->f2 & (1 << 1)) != 0) { + $this->f4 = true; + } else { + $this->f4 = false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xf68fd3f9); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->f1); + if (!$success) { + return false; + } + if (($this->f1 & (1 << 0)) != 0) { + $success = $stream->write_uint32($this->f2); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateF1() { + $mask = 0; + + if ($this->f2 !== null) { + $mask |= self::BIT_F2_0; + } + + return $mask; + } + + /** + * @return int + */ + public function calculateF2() { + $mask = 0; + + if ($this->f3 && $this->f4) { + $mask |= (self::BIT_F3_1 | self::BIT_F4_1); + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testMaybe.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testMaybe.php new file mode 100644 index 0000000..bdb1ede --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testMaybe.php @@ -0,0 +1,93 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xd6602613) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$maybeContainsValue, $success] = $stream->read_bool(0x27930a7b, 0x3f9c8ef8); + if (!$success) { + return false; + } + if ($maybeContainsValue) { + if (is_null($this->value)) { + $this->value = 0; + } + [$this->value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + } else { + $this->value = null; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xd6602613); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_bool(!is_null($this->value), 0x27930a7b, 0x3f9c8ef8); + if (!$success) { + return false; + } + if (!is_null($this->value)) { + $success = $stream->write_int32($this->value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php new file mode 100644 index 0000000..d89b7a0 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php @@ -0,0 +1,135 @@ +f3 = $f3; + } + + /** + * @param TL\tl_input_stream $stream + * @param int $f + * @return bool + */ + public function read_boxed($stream, $f) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xbd6b4b3c) { + return false; + } + return $this->read($stream, $f); + } + + /** + * @param TL\tl_input_stream $stream + * @param int $f + * @return bool + */ + public function read($stream, $f) { + if (($f & (1 << 0)) != 0) { + [$this->f1, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + } else { + $this->f1 = null; + } + if (($f & (1 << 3)) != 0) { + $this->f2 = true; + } else { + $this->f2 = false; + } + $this->f3 = []; + for($i9 = 0; $i9 < $f; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->f3[] = $array_int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @param int $f + * @return bool + */ + public function write_boxed($stream, $f) { + $success = $stream->write_uint32(0xbd6b4b3c); + if (!$success) { + return false; + } + return $this->write($stream, $f); + } + + /** + * @param TL\tl_output_stream $stream + * @param int $f + * @return bool + */ + public function write($stream, $f) { + if (($f & (1 << 0)) != 0) { + $success = $stream->write_uint32($this->f1); + if (!$success) { + return false; + } + } + for($i9 = 0; $i9 < $f; $i9++) { + $success = $stream->write_int32($this->f3[$i9]); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateF() { + $mask = 0; + + if ($this->f1 !== null) { + $mask |= self::BIT_F1_0; + } + + if ($this->f2) { + $mask |= self::BIT_F2_3; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php new file mode 100644 index 0000000..d74cd3f --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php @@ -0,0 +1,95 @@ +f = $f; + $this->inner = $inner; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x1850ffe4) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->f, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if ($this->inner == null) { + $this->inner = new TL\cases\Types\cases_testOutFieldMask(); + } + $success = $this->inner->read($stream, $this->f); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x1850ffe4); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->f); + if (!$success) { + return false; + } + if ($this->inner == null) { + $this->inner = new TL\cases\Types\cases_testOutFieldMask(); + } + $success = $this->inner->write($stream, $this->f); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php new file mode 100644 index 0000000..8172603 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php @@ -0,0 +1,188 @@ +f0 = $f0; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xc58cf85e) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->f0, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + if (($this->f0 & (1 << 0)) != 0) { + [$this->f1, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + } else { + $this->f1 = null; + } + if (($this->f1 & (1 << 1)) != 0) { + [$this->f2, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + } else { + $this->f2 = null; + } + if (($this->f0 & (1 << 0)) != 0) { + $this->t1 = true; + } else { + $this->t1 = false; + } + if (($this->f1 & (1 << 1)) != 0) { + $this->t2 = true; + } else { + $this->t2 = false; + } + if (($this->f2 & (1 << 2)) != 0) { + $this->t3 = true; + } else { + $this->t3 = false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xc58cf85e); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->f0); + if (!$success) { + return false; + } + if (($this->f0 & (1 << 0)) != 0) { + $success = $stream->write_uint32($this->f1); + if (!$success) { + return false; + } + } + if (($this->f1 & (1 << 1)) != 0) { + $success = $stream->write_uint32($this->f2); + if (!$success) { + return false; + } + } + return true; + } + + /** + * @return int + */ + public function calculateF0() { + $mask = 0; + + if ($this->f1 !== null && $this->t1) { + $mask |= (self::BIT_F1_0 | self::BIT_T1_0); + } + + return $mask; + } + + /** + * @return int + */ + public function calculateF1() { + $mask = 0; + + if ($this->f2 !== null && $this->t2) { + $mask |= (self::BIT_F2_1 | self::BIT_T2_1); + } + + return $mask; + } + + /** + * @return int + */ + public function calculateF2() { + $mask = 0; + + if ($this->t3) { + $mask |= self::BIT_T3_2; + } + + return $mask; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php new file mode 100644 index 0000000..3752b2f --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php @@ -0,0 +1,83 @@ +tpl = $tpl; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x4b9caf8f) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + $this->tpl = []; + for($i9 = 0; $i9 < 4; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->tpl[] = $array_int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x4b9caf8f); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + for($i9 = 0; $i9 < 4; $i9++) { + $success = $stream->write_int32($this->tpl[$i9]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion1.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion1.php new file mode 100644 index 0000000..fbac9b0 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion1.php @@ -0,0 +1,76 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x4b4f09b1) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x4b4f09b1); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_int32($this->value); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion2.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion2.php new file mode 100644 index 0000000..dbc45cb --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnion2.php @@ -0,0 +1,76 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x464f96c4) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->value, $success] = $stream->read_string(); + if (!$success) { + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x464f96c4); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_string($this->value); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php new file mode 100644 index 0000000..d6415fa --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php @@ -0,0 +1,99 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x4497a381) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$tag, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + switch ($tag) { + case 0x4b4f09b1: + $variant = new TL\cases\Types\cases_testUnion1(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0x464f96c4: + $variant = new TL\cases\Types\cases_testUnion2(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + default: + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x4497a381); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + if ($this->value == null) { + $this->value = new TL\cases\Types\cases_testUnion1(); + } + $success = $this->value->write_boxed($stream); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php new file mode 100644 index 0000000..55fea5d --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php @@ -0,0 +1,91 @@ +arr = $arr; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x4975695c) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$vector_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->arr = []; + for($i9 = 0; $i9 < $vector_size; $i9++) { + $array_int___element = 0; + [$array_int___element, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->arr[] = $array_int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x4975695c); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->arr)); + if (!$success) { + return false; + } + for($i9 = 0; $i9 < count($this->arr); $i9++) { + $success = $stream->write_int32($this->arr[$i9]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_TestEnum.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_TestEnum.php new file mode 100644 index 0000000..bc70054 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_TestEnum.php @@ -0,0 +1,36 @@ +n = $n; + $this->arr = $arr; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x3762fb81) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$this->n, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->arr = []; + for($i12 = 0; $i12 < $this->n; $i12++) { + $array_string___element = ''; + [$array_string___element, $success] = $stream->read_string(); + if (!$success) { + return false; + } + $this->arr[] = $array_string___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x3762fb81); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32($this->n); + if (!$success) { + return false; + } + for($i12 = 0; $i12 < $this->n; $i12++) { + $success = $stream->write_string($this->arr[$i12]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php new file mode 100644 index 0000000..d1254fb --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php @@ -0,0 +1,97 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x5a5fce57) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$vector_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i36 = 0; $i36 < $vector_size; $i36++) { + $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); + if ($array_DictionaryFieldAny__float__int___element == null) { + $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); + } + $success = $array_DictionaryFieldAny__float__int___element->read($stream); + if (!$success) { + return false; + } + $this->dict[] = $array_DictionaryFieldAny__float__int___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x5a5fce57); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + for($i36 = 0; $i36 < count($this->dict); $i36++) { + if ($this->dict[$i36] == null) { + $this->dict[$i36] = new TL\_common\Types\dictionaryFieldAny__float__int(); + } + $success = $this->dict[$i36]->write($stream); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictInt.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictInt.php new file mode 100644 index 0000000..3be8f0a --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictInt.php @@ -0,0 +1,99 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x453ace07) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$dict_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i9 = 0; $i9 < $dict_size; $i9++) { + [$array_int___key, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + [$array_int___value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->dict[$array_int___key] = $array_int___value; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x453ace07); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + ksort($this->dict); + foreach($this->dict as $key => $value) { + $success = $stream->write_int32($key); + if (!$success) { + return false; + } + $success = $stream->write_int32($value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictString.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictString.php new file mode 100644 index 0000000..e75e7b2 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictString.php @@ -0,0 +1,99 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x6c04d6ce) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$dict_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i9 = 0; $i9 < $dict_size; $i9++) { + [$array_int___key, $success] = $stream->read_string(); + if (!$success) { + return false; + } + [$array_int___value, $success] = $stream->read_int32(); + if (!$success) { + return false; + } + $this->dict[$array_int___key] = $array_int___value; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x6c04d6ce); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + ksort($this->dict); + foreach($this->dict as $key => $value) { + $success = $stream->write_string($key); + if (!$success) { + return false; + } + $success = $stream->write_int32($value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictStringString.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictStringString.php new file mode 100644 index 0000000..5752e7f --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictStringString.php @@ -0,0 +1,99 @@ +dict = $dict; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0xad69c772) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$dict_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->dict = []; + for($i12 = 0; $i12 < $dict_size; $i12++) { + [$array_string___key, $success] = $stream->read_string(); + if (!$success) { + return false; + } + [$array_string___value, $success] = $stream->read_string(); + if (!$success) { + return false; + } + $this->dict[$array_string___key] = $array_string___value; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0xad69c772); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->dict)); + if (!$success) { + return false; + } + ksort($this->dict); + foreach($this->dict as $key => $value) { + $success = $stream->write_string($key); + if (!$success) { + return false; + } + $success = $stream->write_string($value); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum1.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum1.php new file mode 100644 index 0000000..c4393cc --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum1.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x58aad3f5) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x58aad3f5); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum2.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum2.php new file mode 100644 index 0000000..68800ee --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum2.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x00b47add) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x00b47add); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum3.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum3.php new file mode 100644 index 0000000..3bb9419 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnum3.php @@ -0,0 +1,64 @@ +read_uint32(); + if (!$success || $magic != 0x81911ffa) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x81911ffa); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php new file mode 100644 index 0000000..b7cc580 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php @@ -0,0 +1,107 @@ +value = $value; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x32b92037) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$tag, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + switch ($tag) { + case 0x6c6c55ac: + $variant = new TL\cases\Types\cases_testEnum1(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0x86ea88ce: + $variant = new TL\cases\Types\cases_testEnum2(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + case 0x69b83e2f: + $variant = new TL\cases\Types\cases_testEnum3(); + $success = $variant->read($stream); + if (!$success) { + return false; + } + $this->value = $variant; + break; + default: + return false; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x32b92037); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + if ($this->value == null) { + $this->value = new TL\cases\Types\cases_testEnum1(); + } + $success = $this->value->write_boxed($stream); + if (!$success) { + return false; + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php new file mode 100644 index 0000000..fb927d0 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php @@ -0,0 +1,83 @@ +tpl = $tpl; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x2dd3bacf) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + $this->tpl = []; + for($i12 = 0; $i12 < 4; $i12++) { + $array_string___element = ''; + [$array_string___element, $success] = $stream->read_string(); + if (!$success) { + return false; + } + $this->tpl[] = $array_string___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x2dd3bacf); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + for($i12 = 0; $i12 < 4; $i12++) { + $success = $stream->write_string($this->tpl[$i12]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php new file mode 100644 index 0000000..73f7c7c --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php @@ -0,0 +1,91 @@ +arr = $arr; + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read_boxed($stream) { + [$magic, $success] = $stream->read_uint32(); + if (!$success || $magic != 0x3647c8ae) { + return false; + } + return $this->read($stream); + } + + /** + * @param TL\tl_input_stream $stream + * @return bool + */ + public function read($stream) { + [$vector_size, $success] = $stream->read_uint32(); + if (!$success) { + return false; + } + $this->arr = []; + for($i12 = 0; $i12 < $vector_size; $i12++) { + $array_string___element = ''; + [$array_string___element, $success] = $stream->read_string(); + if (!$success) { + return false; + } + $this->arr[] = $array_string___element; + } + return true; + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write_boxed($stream) { + $success = $stream->write_uint32(0x3647c8ae); + if (!$success) { + return false; + } + return $this->write($stream); + } + + /** + * @param TL\tl_output_stream $stream + * @return bool + */ + public function write($stream) { + $success = $stream->write_uint32(count($this->arr)); + if (!$success) { + return false; + } + for($i12 = 0; $i12 < count($this->arr); $i12++) { + $success = $stream->write_string($this->arr[$i12]); + if (!$success) { + return false; + } + } + return true; + } + +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php new file mode 100644 index 0000000..a0d7d16 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php @@ -0,0 +1,192 @@ +tl_factory_by_name)) { + return $this->tl_factory_by_name[$tl_name](); + } + return null; + } + + /** + * @param int $tl_tag + * @return TL\TL_Object|null + */ + function tl_object_by_tag($tl_tag) { + if (array_key_exists($tl_tag, $this->tl_factory_by_tag)) { + return $this->tl_factory_by_tag[$tl_tag](); + } + return null; + } + + function __construct() { + $itemd31bd0fd = function () { return new TL\benchmarks\Types\benchmarks_vruhash(); }; + $this->tl_factory_by_name["benchmarks.vruhash"] = $itemd31bd0fd; + $this->tl_factory_by_tag[0xd31bd0fd] = $itemd31bd0fd; + $item32792c04 = function () { return new TL\benchmarks\Types\benchmarks_vruposition(); }; + $this->tl_factory_by_name["benchmarks.vruposition"] = $item32792c04; + $this->tl_factory_by_tag[0x32792c04] = $item32792c04; + $itemfb442ca5 = function () { return new TL\benchmarks\Types\benchmarks_vrutoyTopLevelContainer(); }; + $this->tl_factory_by_name["benchmarks.vrutoyTopLevelContainer"] = $itemfb442ca5; + $this->tl_factory_by_tag[0xfb442ca5] = $itemfb442ca5; + $itemc176008e = function () { return new TL\benchmarks\Types\benchmarks_vrutoyTopLevelContainerWithDependency(); }; + $this->tl_factory_by_name["benchmarks.vrutoyTopLevelContainerWithDependency"] = $itemc176008e; + $this->tl_factory_by_tag[0xc176008e] = $itemc176008e; + $item3762fb81 = function () { return new TL\cases_bytes\Types\cases_bytes_testArray(); }; + $this->tl_factory_by_name["cases_bytes.testArray"] = $item3762fb81; + $this->tl_factory_by_tag[0x3762fb81] = $item3762fb81; + $item5a5fce57 = function () { return new TL\cases_bytes\Types\cases_bytes_testDictAny(); }; + $this->tl_factory_by_name["cases_bytes.testDictAny"] = $item5a5fce57; + $this->tl_factory_by_tag[0x5a5fce57] = $item5a5fce57; + $item453ace07 = function () { return new TL\cases_bytes\Types\cases_bytes_testDictInt(); }; + $this->tl_factory_by_name["cases_bytes.testDictInt"] = $item453ace07; + $this->tl_factory_by_tag[0x453ace07] = $item453ace07; + $item6c04d6ce = function () { return new TL\cases_bytes\Types\cases_bytes_testDictString(); }; + $this->tl_factory_by_name["cases_bytes.testDictString"] = $item6c04d6ce; + $this->tl_factory_by_tag[0x6c04d6ce] = $item6c04d6ce; + $itemad69c772 = function () { return new TL\cases_bytes\Types\cases_bytes_testDictStringString(); }; + $this->tl_factory_by_name["cases_bytes.testDictStringString"] = $itemad69c772; + $this->tl_factory_by_tag[0xad69c772] = $itemad69c772; + $item32b92037 = function () { return new TL\cases_bytes\Types\cases_bytes_testEnumContainer(); }; + $this->tl_factory_by_name["cases_bytes.testEnumContainer"] = $item32b92037; + $this->tl_factory_by_tag[0x32b92037] = $item32b92037; + $item2dd3bacf = function () { return new TL\cases_bytes\Types\cases_bytes_testTuple(); }; + $this->tl_factory_by_name["cases_bytes.testTuple"] = $item2dd3bacf; + $this->tl_factory_by_tag[0x2dd3bacf] = $item2dd3bacf; + $item3647c8ae = function () { return new TL\cases_bytes\Types\cases_bytes_testVector(); }; + $this->tl_factory_by_name["cases_bytes.testVector"] = $item3647c8ae; + $this->tl_factory_by_tag[0x3647c8ae] = $item3647c8ae; + $itemd3ca919d = function () { return new TL\cases\Types\cases_myCycle1(); }; + $this->tl_factory_by_name["cases.myCycle1"] = $itemd3ca919d; + $this->tl_factory_by_tag[0xd3ca919d] = $itemd3ca919d; + $item5444c9a2 = function () { return new TL\cases\Types\cases_myCycle2(); }; + $this->tl_factory_by_name["cases.myCycle2"] = $item5444c9a2; + $this->tl_factory_by_tag[0x5444c9a2] = $item5444c9a2; + $item7624f86b = function () { return new TL\cases\Types\cases_myCycle3(); }; + $this->tl_factory_by_name["cases.myCycle3"] = $item7624f86b; + $this->tl_factory_by_tag[0x7624f86b] = $item7624f86b; + $item6ccce4be = function () { return new TL\cases\Types\cases_replace7(); }; + $this->tl_factory_by_name["cases.replace7"] = $item6ccce4be; + $this->tl_factory_by_tag[0x6ccce4be] = $item6ccce4be; + $item197858f5 = function () { return new TL\cases\Types\cases_replace7plus(); }; + $this->tl_factory_by_name["cases.replace7plus"] = $item197858f5; + $this->tl_factory_by_tag[0x197858f5] = $item197858f5; + $itemabc39b68 = function () { return new TL\cases\Types\cases_replace7plusplus(); }; + $this->tl_factory_by_name["cases.replace7plusplus"] = $itemabc39b68; + $this->tl_factory_by_tag[0xabc39b68] = $itemabc39b68; + $iteme3fae936 = function () { return new TL\cases\Types\cases_testAllPossibleFieldConfigsContainer(); }; + $this->tl_factory_by_name["cases.testAllPossibleFieldConfigsContainer"] = $iteme3fae936; + $this->tl_factory_by_tag[0xe3fae936] = $iteme3fae936; + $itema888030d = function () { return new TL\cases\Types\cases_testArray(); }; + $this->tl_factory_by_name["cases.testArray"] = $itema888030d; + $this->tl_factory_by_tag[0xa888030d] = $itema888030d; + $item9b2396db = function () { return new TL\cases\Types\cases_testBeforeReadBitValidation(); }; + $this->tl_factory_by_name["cases.testBeforeReadBitValidation"] = $item9b2396db; + $this->tl_factory_by_tag[0x9b2396db] = $item9b2396db; + $iteme29b8ae6 = function () { return new TL\cases\Types\cases_testDictAny(); }; + $this->tl_factory_by_name["cases.testDictAny"] = $iteme29b8ae6; + $this->tl_factory_by_tag[0xe29b8ae6] = $iteme29b8ae6; + $itemd3877643 = function () { return new TL\cases\Types\cases_testDictInt(); }; + $this->tl_factory_by_name["cases.testDictInt"] = $itemd3877643; + $this->tl_factory_by_tag[0xd3877643] = $itemd3877643; + $itemc463c79b = function () { return new TL\cases\Types\cases_testDictString(); }; + $this->tl_factory_by_name["cases.testDictString"] = $itemc463c79b; + $this->tl_factory_by_tag[0xc463c79b] = $itemc463c79b; + $itemcb684231 = function () { return new TL\cases\Types\cases_testEnumContainer(); }; + $this->tl_factory_by_name["cases.testEnumContainer"] = $itemcb684231; + $this->tl_factory_by_tag[0xcb684231] = $itemcb684231; + $itemf68fd3f9 = function () { return new TL\cases\Types\cases_testLocalFieldmask(); }; + $this->tl_factory_by_name["cases.testLocalFieldmask"] = $itemf68fd3f9; + $this->tl_factory_by_tag[0xf68fd3f9] = $itemf68fd3f9; + $itemd6602613 = function () { return new TL\cases\Types\cases_testMaybe(); }; + $this->tl_factory_by_name["cases.testMaybe"] = $itemd6602613; + $this->tl_factory_by_tag[0xd6602613] = $itemd6602613; + $item1850ffe4 = function () { return new TL\cases\Types\cases_testOutFieldMaskContainer(); }; + $this->tl_factory_by_name["cases.testOutFieldMaskContainer"] = $item1850ffe4; + $this->tl_factory_by_tag[0x1850ffe4] = $item1850ffe4; + $itemc58cf85e = function () { return new TL\cases\Types\cases_testRecursiveFieldMask(); }; + $this->tl_factory_by_name["cases.testRecursiveFieldMask"] = $itemc58cf85e; + $this->tl_factory_by_tag[0xc58cf85e] = $itemc58cf85e; + $item4b9caf8f = function () { return new TL\cases\Types\cases_testTuple(); }; + $this->tl_factory_by_name["cases.testTuple"] = $item4b9caf8f; + $this->tl_factory_by_tag[0x4b9caf8f] = $item4b9caf8f; + $item4497a381 = function () { return new TL\cases\Types\cases_testUnionContainer(); }; + $this->tl_factory_by_name["cases.testUnionContainer"] = $item4497a381; + $this->tl_factory_by_tag[0x4497a381] = $item4497a381; + $item4975695c = function () { return new TL\cases\Types\cases_testVector(); }; + $this->tl_factory_by_name["cases.testVector"] = $item4975695c; + $this->tl_factory_by_tag[0x4975695c] = $item4975695c; + } +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php new file mode 100644 index 0000000..1e60bf9 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php @@ -0,0 +1,192 @@ +tag = $tag; + $this->annotations = $annotations; + $this->tl_name = $tl_name; + } +} + +class tl_meta { + /** @var tl_item[] */ + private $tl_item_by_tag = []; + + /** @var tl_item[] */ + private $tl_item_by_name = []; + + /** + * @param string $tl_name + * @return tl_item|null + */ + function tl_item_by_name($tl_name) { + if (array_key_exists($tl_name, $this->tl_item_by_name)) { + return $this->tl_item_by_name[$tl_name]; + } + return null; + } + + /** + * @param int $tl_tag + * @return tl_item|null + */ + function tl_item_by_tag($tl_tag) { + if (array_key_exists($tl_tag, $this->tl_item_by_tag)) { + return $this->tl_item_by_tag[$tl_tag]; + } + return null; + } + + function __construct() { + $itemd31bd0fd = new tl_item(0xd31bd0fd, 0x0, "benchmarks.vruhash"); + $this->tl_item_by_name["benchmarks.vruhash"] = $itemd31bd0fd; + $this->tl_item_by_tag[0xd31bd0fd] = $itemd31bd0fd; + $item32792c04 = new tl_item(0x32792c04, 0x0, "benchmarks.vruposition"); + $this->tl_item_by_name["benchmarks.vruposition"] = $item32792c04; + $this->tl_item_by_tag[0x32792c04] = $item32792c04; + $itemfb442ca5 = new tl_item(0xfb442ca5, 0x0, "benchmarks.vrutoyTopLevelContainer"); + $this->tl_item_by_name["benchmarks.vrutoyTopLevelContainer"] = $itemfb442ca5; + $this->tl_item_by_tag[0xfb442ca5] = $itemfb442ca5; + $itemc176008e = new tl_item(0xc176008e, 0x0, "benchmarks.vrutoyTopLevelContainerWithDependency"); + $this->tl_item_by_name["benchmarks.vrutoyTopLevelContainerWithDependency"] = $itemc176008e; + $this->tl_item_by_tag[0xc176008e] = $itemc176008e; + $itemef556bee = new tl_item(0xef556bee, 0x0, "benchmarks.vrutoytopLevelUnionBig"); + $this->tl_item_by_name["benchmarks.vrutoytopLevelUnionBig"] = $itemef556bee; + $this->tl_item_by_tag[0xef556bee] = $itemef556bee; + $itemce27c770 = new tl_item(0xce27c770, 0x0, "benchmarks.vrutoytopLevelUnionEmpty"); + $this->tl_item_by_name["benchmarks.vrutoytopLevelUnionEmpty"] = $itemce27c770; + $this->tl_item_by_tag[0xce27c770] = $itemce27c770; + $item3762fb81 = new tl_item(0x3762fb81, 0x0, "cases_bytes.testArray"); + $this->tl_item_by_name["cases_bytes.testArray"] = $item3762fb81; + $this->tl_item_by_tag[0x3762fb81] = $item3762fb81; + $item5a5fce57 = new tl_item(0x5a5fce57, 0x0, "cases_bytes.testDictAny"); + $this->tl_item_by_name["cases_bytes.testDictAny"] = $item5a5fce57; + $this->tl_item_by_tag[0x5a5fce57] = $item5a5fce57; + $item453ace07 = new tl_item(0x453ace07, 0x0, "cases_bytes.testDictInt"); + $this->tl_item_by_name["cases_bytes.testDictInt"] = $item453ace07; + $this->tl_item_by_tag[0x453ace07] = $item453ace07; + $item6c04d6ce = new tl_item(0x6c04d6ce, 0x0, "cases_bytes.testDictString"); + $this->tl_item_by_name["cases_bytes.testDictString"] = $item6c04d6ce; + $this->tl_item_by_tag[0x6c04d6ce] = $item6c04d6ce; + $itemad69c772 = new tl_item(0xad69c772, 0x0, "cases_bytes.testDictStringString"); + $this->tl_item_by_name["cases_bytes.testDictStringString"] = $itemad69c772; + $this->tl_item_by_tag[0xad69c772] = $itemad69c772; + $item58aad3f5 = new tl_item(0x58aad3f5, 0x0, "cases_bytes.testEnum1"); + $this->tl_item_by_name["cases_bytes.testEnum1"] = $item58aad3f5; + $this->tl_item_by_tag[0x58aad3f5] = $item58aad3f5; + $item00b47add = new tl_item(0x00b47add, 0x0, "cases_bytes.testEnum2"); + $this->tl_item_by_name["cases_bytes.testEnum2"] = $item00b47add; + $this->tl_item_by_tag[0x00b47add] = $item00b47add; + $item81911ffa = new tl_item(0x81911ffa, 0x0, "cases_bytes.testEnum3"); + $this->tl_item_by_name["cases_bytes.testEnum3"] = $item81911ffa; + $this->tl_item_by_tag[0x81911ffa] = $item81911ffa; + $item32b92037 = new tl_item(0x32b92037, 0x0, "cases_bytes.testEnumContainer"); + $this->tl_item_by_name["cases_bytes.testEnumContainer"] = $item32b92037; + $this->tl_item_by_tag[0x32b92037] = $item32b92037; + $item2dd3bacf = new tl_item(0x2dd3bacf, 0x0, "cases_bytes.testTuple"); + $this->tl_item_by_name["cases_bytes.testTuple"] = $item2dd3bacf; + $this->tl_item_by_tag[0x2dd3bacf] = $item2dd3bacf; + $item3647c8ae = new tl_item(0x3647c8ae, 0x0, "cases_bytes.testVector"); + $this->tl_item_by_name["cases_bytes.testVector"] = $item3647c8ae; + $this->tl_item_by_tag[0x3647c8ae] = $item3647c8ae; + $itemd3ca919d = new tl_item(0xd3ca919d, 0x0, "cases.myCycle1"); + $this->tl_item_by_name["cases.myCycle1"] = $itemd3ca919d; + $this->tl_item_by_tag[0xd3ca919d] = $itemd3ca919d; + $item5444c9a2 = new tl_item(0x5444c9a2, 0x0, "cases.myCycle2"); + $this->tl_item_by_name["cases.myCycle2"] = $item5444c9a2; + $this->tl_item_by_tag[0x5444c9a2] = $item5444c9a2; + $item7624f86b = new tl_item(0x7624f86b, 0x0, "cases.myCycle3"); + $this->tl_item_by_name["cases.myCycle3"] = $item7624f86b; + $this->tl_item_by_tag[0x7624f86b] = $item7624f86b; + $item6ccce4be = new tl_item(0x6ccce4be, 0x0, "cases.replace7"); + $this->tl_item_by_name["cases.replace7"] = $item6ccce4be; + $this->tl_item_by_tag[0x6ccce4be] = $item6ccce4be; + $item197858f5 = new tl_item(0x197858f5, 0x0, "cases.replace7plus"); + $this->tl_item_by_name["cases.replace7plus"] = $item197858f5; + $this->tl_item_by_tag[0x197858f5] = $item197858f5; + $itemabc39b68 = new tl_item(0xabc39b68, 0x0, "cases.replace7plusplus"); + $this->tl_item_by_name["cases.replace7plusplus"] = $itemabc39b68; + $this->tl_item_by_tag[0xabc39b68] = $itemabc39b68; + $iteme3fae936 = new tl_item(0xe3fae936, 0x0, "cases.testAllPossibleFieldConfigsContainer"); + $this->tl_item_by_name["cases.testAllPossibleFieldConfigsContainer"] = $iteme3fae936; + $this->tl_item_by_tag[0xe3fae936] = $iteme3fae936; + $itema888030d = new tl_item(0xa888030d, 0x0, "cases.testArray"); + $this->tl_item_by_name["cases.testArray"] = $itema888030d; + $this->tl_item_by_tag[0xa888030d] = $itema888030d; + $item9b2396db = new tl_item(0x9b2396db, 0x0, "cases.testBeforeReadBitValidation"); + $this->tl_item_by_name["cases.testBeforeReadBitValidation"] = $item9b2396db; + $this->tl_item_by_tag[0x9b2396db] = $item9b2396db; + $iteme29b8ae6 = new tl_item(0xe29b8ae6, 0x0, "cases.testDictAny"); + $this->tl_item_by_name["cases.testDictAny"] = $iteme29b8ae6; + $this->tl_item_by_tag[0xe29b8ae6] = $iteme29b8ae6; + $itemd3877643 = new tl_item(0xd3877643, 0x0, "cases.testDictInt"); + $this->tl_item_by_name["cases.testDictInt"] = $itemd3877643; + $this->tl_item_by_tag[0xd3877643] = $itemd3877643; + $itemc463c79b = new tl_item(0xc463c79b, 0x0, "cases.testDictString"); + $this->tl_item_by_name["cases.testDictString"] = $itemc463c79b; + $this->tl_item_by_tag[0xc463c79b] = $itemc463c79b; + $item6c6c55ac = new tl_item(0x6c6c55ac, 0x0, "cases.testEnum1"); + $this->tl_item_by_name["cases.testEnum1"] = $item6c6c55ac; + $this->tl_item_by_tag[0x6c6c55ac] = $item6c6c55ac; + $item86ea88ce = new tl_item(0x86ea88ce, 0x0, "cases.testEnum2"); + $this->tl_item_by_name["cases.testEnum2"] = $item86ea88ce; + $this->tl_item_by_tag[0x86ea88ce] = $item86ea88ce; + $item69b83e2f = new tl_item(0x69b83e2f, 0x0, "cases.testEnum3"); + $this->tl_item_by_name["cases.testEnum3"] = $item69b83e2f; + $this->tl_item_by_tag[0x69b83e2f] = $item69b83e2f; + $itemcb684231 = new tl_item(0xcb684231, 0x0, "cases.testEnumContainer"); + $this->tl_item_by_name["cases.testEnumContainer"] = $itemcb684231; + $this->tl_item_by_tag[0xcb684231] = $itemcb684231; + $itemf68fd3f9 = new tl_item(0xf68fd3f9, 0x0, "cases.testLocalFieldmask"); + $this->tl_item_by_name["cases.testLocalFieldmask"] = $itemf68fd3f9; + $this->tl_item_by_tag[0xf68fd3f9] = $itemf68fd3f9; + $itemd6602613 = new tl_item(0xd6602613, 0x0, "cases.testMaybe"); + $this->tl_item_by_name["cases.testMaybe"] = $itemd6602613; + $this->tl_item_by_tag[0xd6602613] = $itemd6602613; + $item1850ffe4 = new tl_item(0x1850ffe4, 0x0, "cases.testOutFieldMaskContainer"); + $this->tl_item_by_name["cases.testOutFieldMaskContainer"] = $item1850ffe4; + $this->tl_item_by_tag[0x1850ffe4] = $item1850ffe4; + $itemc58cf85e = new tl_item(0xc58cf85e, 0x0, "cases.testRecursiveFieldMask"); + $this->tl_item_by_name["cases.testRecursiveFieldMask"] = $itemc58cf85e; + $this->tl_item_by_tag[0xc58cf85e] = $itemc58cf85e; + $item4b9caf8f = new tl_item(0x4b9caf8f, 0x0, "cases.testTuple"); + $this->tl_item_by_name["cases.testTuple"] = $item4b9caf8f; + $this->tl_item_by_tag[0x4b9caf8f] = $item4b9caf8f; + $item4b4f09b1 = new tl_item(0x4b4f09b1, 0x0, "cases.testUnion1"); + $this->tl_item_by_name["cases.testUnion1"] = $item4b4f09b1; + $this->tl_item_by_tag[0x4b4f09b1] = $item4b4f09b1; + $item464f96c4 = new tl_item(0x464f96c4, 0x0, "cases.testUnion2"); + $this->tl_item_by_name["cases.testUnion2"] = $item464f96c4; + $this->tl_item_by_tag[0x464f96c4] = $item464f96c4; + $item4497a381 = new tl_item(0x4497a381, 0x0, "cases.testUnionContainer"); + $this->tl_item_by_name["cases.testUnionContainer"] = $item4497a381; + $this->tl_item_by_tag[0x4497a381] = $item4497a381; + $item4975695c = new tl_item(0x4975695c, 0x0, "cases.testVector"); + $this->tl_item_by_name["cases.testVector"] = $item4975695c; + $this->tl_item_by_tag[0x4975695c] = $item4975695c; + } +} diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/tl_interfaces.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/tl_interfaces.php new file mode 100644 index 0000000..39a509e --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/tl_interfaces.php @@ -0,0 +1,35 @@ +data = $data; + } + + public function get_offset(): int { + return $this->offset; + } + + public function remaining_size(): int { + return strlen($this->data) - $this->offset; + } + + /** @return tuple(int, bool) */ + public function read_int32() { + // TODO: 'l' - signed 32 bit SYSTEM DEPENDENT ENDIAN + $data = unpack('l', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 4; + return [$data[1], true]; + } + } + + /** @return tuple(int, bool) */ + public function read_uint32() { + $data = unpack('V', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 4; + return [$data[1], true]; + } + } + + /** @return tuple(int, bool) */ + public function read_int64() { + $data = unpack('q', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 8; + return [$data[1], true]; + } + } + + /** @return tuple(bool, bool) */ + public function read_bool(int $false_tag, $true_tag) { + [$tag, $success] = $this->read_uint32(); + if (!$success) { + return [false, false]; + } else if ($tag == $false_tag) { + return [false, true]; + } else if ($tag == $true_tag) { + return [true, true]; + } + return [false, false]; + } + + /** @return tuple(float, bool) */ + public function read_float() { + $data = unpack('f', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 4; + return [$data[1], true]; + } + } + + /** @return tuple(float, bool) */ + public function read_double() { + $data = unpack('d', $this->data, $this->offset); + if (!$data) { + return [0, false]; + } else { + $this->offset += 8; + return [$data[1], true]; + } + } + + /** @return tuple(string, bool) */ + public function read_string() { + $size = $this->remaining_size(); + if ($size == 0) { + return ["", false]; + } + $first_byte = ord($this->data[$this->offset]); + $l = 0; + $p = 0; + if ($first_byte < tl_constants::tinyStringLen) { + $l = $first_byte; + $this->offset += 1; + $p = $l + 1; + } elseif ($first_byte == tl_constants::bigStringMarker) { + if ($size < 4) { + return ["", false]; + } + $l = (ord($this->data[$this->offset + 3]) << 16) + (ord($this->data[$this->offset + 2]) << 8) + (ord($this->data[$this->offset + 1]) << 0); + $this->offset += 4; + $p = $l; + if ($l <= tl_constants::tinyStringLen) { + return ["", false]; + } + } else { + if ($size < 8) { + 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 > max int + $l = $l64; + $this->offset += 8; + $p = $l; + if ($l <= tl_constants::bigStringLen) { + return ["", false]; + } + } + $start = $this->offset; + if ($l > 0) { + if ($this->remaining_size() < $l) { + return ["", false]; + } + } + $padding = $this->paddingLen($p); + for ($i = 0; $i < $padding; $i++) { + if (ord($this->data[$this->offset + $l + $i]) != 0) { + return ["", false]; + } + } + $this->offset += $l + $padding; + return [substr($this->data, $start, $l), true]; + } + + function paddingLen(int $l): int { + return (4 - ($l % 4)) % 4; + } +} + +class tl_output_stream { + /** @var string */ + private $data = ""; + + public function __construct(string $data) { + $this->data = $data; + } + + public function get_data(): string { + return $this->data; + } + + /** @return bool */ + public function write_uint32(int $value) { + $this->data .= pack('V', $value); + return true; + } + + /** @return bool */ + public function write_int32(int $value) { + $this->data .= pack('l', $value); + return true; + } + + /** @return bool */ + public function write_int64(int $value) { + $this->data .= pack('q', $value); + return true; + } + + /** @return bool */ + public function write_bool(bool $value, int $false_tag, $true_tag) { + if ($value) { + $this->data .= pack('V', $true_tag); + } else { + $this->data .= pack('V', $false_tag); + } + return true; + } + + /** @return bool */ + public function write_float(float $value) { + $this->data .= pack('f', $value); + return true; + } + + /** @return bool */ + public function write_double(float $value) { + $this->data .= pack('d', $value); + return true; + } + + /** @return bool */ + public function write_string(string $value) { + $l = strlen($value); + $p = 0; + if ($l <= tl_constants::tinyStringLen) { + $this->data .= chr($l); + $p = $l + 1; + } else if ($l <= tl_constants::bigStringLen) { + $this->data .= chr(tl_constants::bigStringMarker); + $this->data .= chr(($l & 255)); + $this->data .= chr((($l >> 8) & 255)); + $this->data .= chr((($l >> 16) & 255)); + $p = $l; + } else { + if ($l > tl_constants::hugeStringLen) { + $l = tl_constants::hugeStringLen; + $value = substr($value, 0, $l); + } + $this->data .= chr(tl_constants::hugeStringMarker); + $this->data .= chr(($l & 255)); + $this->data .= chr((($l >> 8) & 255)); + $this->data .= chr((($l >> 16) & 255)); + $this->data .= chr((($l >> 24) & 255)); + $this->data .= chr((($l >> 32) & 255)); + $this->data .= chr((($l >> 40) & 255)); + $this->data .= chr((($l >> 48) & 255)); + $p = $l; + } + $this->data .= $value; + if ($p % 4 == 1) { + $this->data .= chr(0); + $this->data .= chr(0); + $this->data .= chr(0); + } else if ($p % 4 == 2) { + $this->data .= chr(0); + $this->data .= chr(0); + } else if ($p % 4 == 3) { + $this->data .= chr(0); + } + return true; + } +} +?> diff --git a/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt b/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt new file mode 100644 index 0000000..b7eb433 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt @@ -0,0 +1,4 @@ +tlgen version: (devel) +schema url: https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/cases.tl +schema commit: abcdefgh +schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC) diff --git a/internal/tlcodegen/test/gen/cases_php/tljson.html b/internal/tlcodegen/test/gen/cases_php/tljson.html new file mode 100644 index 0000000..cfa476a --- /dev/null +++ b/internal/tlcodegen/test/gen/cases_php/tljson.html @@ -0,0 +1,1675 @@ + + + + + + TL JSON help + + +

Schema

+
    +
  • tlgen version: (devel)
  • +
  • TL schema url
  • +
  • TL schema commit: abcdefgh
  • +
  • TL schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)
  • +
  • TL ⟷ JSON mapping rules: TLJSON.md
  • +
+

Functions

+
    +
+

Types

+

#

+Builtin type #. Represents uint32. Can be used as field mask or collection size. +

benchmarks.vruhash

+ // BLOCK: BENCHMARKS
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "low": <int64>, +
  "high": <int64> +
+ } +
+
TL
+
+ benchmarks.vruhash#d31bd0fd low:long high:long = benchmarks.VruHash; + // We store xxh3 components in LE endianness, as common in TL
+
+
+ +

benchmarks.vruposition

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  "fields_mask": <uint32>, +
  "commit_bit": true,// fields_mask bit #0 + + // we set this bit only if block with this bit set is committed, so we have no more than 1 such uncommitted block.
+
  "meta_block": true,// fields_mask bit #1 + + // this block contains meta data of VR protocol
+
  "split_payload": true,// fields_mask bit #3 + + // this position splits payload. If this set, meta_block and commit_bit are both not set
+
  "rotation_block": true,// fields_mask bit #5 + + // If set, binlog should rotate and this block should be in new file
+
  "canonical_hash": true,// fields_mask bit #15 + + // If set, hash is stored in canonical byte order.
+
  "payload_offset": <int64>, + // Motivation for storing it in each block - when random seeking into the middle of file, we must be sure without scanning from beginning
+
  "block_time_nano": <int64>, + // Only for debug, not used in any logic
+
  "hash": benchmarks.vruhash, +
  "file_offset": <int64>, +
  "seq_number": <int64>// fields_mask bit #14 + + // incremented after each block.
+
+ } +
+
TL
+
+ benchmarks.vruposition#32792c04 fields_mask:# commit_bit:fields_mask.0?true meta_block:fields_mask.1?true split_payload:fields_mask.3?true rotation_block:fields_mask.5?true canonical_hash:fields_mask.15?true payload_offset:long block_time_nano:long hash:benchmarks.vruhash file_offset:long seq_number:fields_mask.14?long = benchmarks.VruPosition; +
+
+ +

benchmarks.vrutoyPositions<#>

+ +External # (nat) arguments: n +

+
+
JSON
+
+ { + + + + + + + +
  "next_positions": [n × benchmarks.vruposition] +
+ } +
+
TL
+
+ benchmarks.vrutoyPositions#b6003de0 {n:#}{n:Type} next_positions:%(__tuple n benchmarks.vruposition) = benchmarks.VrutoyPositions n; +
+
+ +

benchmarks.vrutoyTopLevelContainer

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": benchmarks.VrutoyTopLevelUnion +
+ } +
+
TL
+
+ benchmarks.vrutoyTopLevelContainer#fb442ca5 value:benchmarks.VrutoyTopLevelUnion = benchmarks.VrutoyTopLevelContainer; +
+
+ +

benchmarks.vrutoyTopLevelContainerWithDependency

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "n": <uint32>, +
  "value": benchmarks.vrutoyPositions<n> +
+ } +
+
TL
+
+ benchmarks.vrutoyTopLevelContainerWithDependency#c176008e n:# value:(benchmarks.vrutoyPositions n) = benchmarks.VrutoyTopLevelContainerWithDependency; +
+
+ +

benchmarks.VrutoyTopLevelUnion

+ +

+
+
JSON
+
+ + + + + + + +
{"type":"benchmarks.vrutoytopLevelUnionBig#ef556bee","value":benchmarks.vrutoytopLevelUnionBig} +
{"type":"benchmarks.vrutoytopLevelUnionEmpty#ce27c770"} +
+
+
TL
+
+
    +
  • + benchmarks.vrutoytopLevelUnionBig#ef556bee next_positions:(vector benchmarks.vruposition) = benchmarks.VrutoyTopLevelUnion; +
  • +
  • + benchmarks.vrutoytopLevelUnionEmpty#ce27c770 = benchmarks.VrutoyTopLevelUnion; +
  • +
+
+
+ +

benchmarks.vrutoytopLevelUnionBig

+ +

+
+
JSON
+
+ { + + + + + + + +
  "next_positions": [benchmarks.vruposition, ...] +
+ } +
+
TL
+
+ benchmarks.vrutoytopLevelUnionBig#ef556bee next_positions:(vector benchmarks.vruposition) = benchmarks.VrutoyTopLevelUnion; +
+
+ + + + + + + + + + + + + + + +

cases_bytes.testArray

+ // BLOCK: Bytes vesrion
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "n": <uint32>, +
  "arr": [n × <string>] +
+ } +
+
TL
+
+ cases_bytes.testArray#3762fb81 n:# arr:%(__tuple n string) = cases_bytes.TestArray; +
+
+ +

cases_bytes.testDictAny

+ // will be array of tuples
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": [dictionaryFieldAny<double,int>, ...] +
+ } +
+
TL
+
+ cases_bytes.testDictAny#5a5fce57 dict:(dictionaryAny double int) = cases_bytes.TestDictAny; +
+
+ +

cases_bytes.testDictInt

+ // will be map
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": {<int32>: <int32>} +
+ } +
+
TL
+
+ cases_bytes.testDictInt#453ace07 dict:(dictionaryAny int int) = cases_bytes.TestDictInt; +
+
+ +

cases_bytes.testDictString

+ // will be map
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": {<string>: <int32>} +
+ } +
+
TL
+
+ cases_bytes.testDictString#6c04d6ce dict:(dictionary int) = cases_bytes.TestDictString; +
+
+ +

cases_bytes.testDictStringString

+ // will be map
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": {<string>: <string>} +
+ } +
+
TL
+
+ cases_bytes.testDictStringString#ad69c772 dict:(dictionary string) = cases_bytes.TestDictStringString; +
+
+ +

cases_bytes.TestEnum

+ +

+
+
JSON
+
+ + + + + + + + + + + + + +
"cases_bytes.testEnum1#58aad3f5" +
"cases_bytes.testEnum2#00b47add" +
"cases_bytes.testEnum3#81911ffa" +
+
+
TL
+
+
    +
  • + cases_bytes.testEnum1#58aad3f5 = cases_bytes.TestEnum; +
  • +
  • + cases_bytes.testEnum2#00b47add = cases_bytes.TestEnum; +
  • +
  • + cases_bytes.testEnum3#81911ffa = cases_bytes.TestEnum; +
  • +
+
+
+ + + + +

cases_bytes.testEnumContainer

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": cases.TestEnum +
+ } +
+
TL
+
+ cases_bytes.testEnumContainer#32b92037 value:cases.TestEnum = cases_bytes.TestEnumContainer; +
+
+ +

cases_bytes.testTuple

+ +

+
+
JSON
+
+ { + + + + + + + +
  "tpl": [4 × <string>] +
+ } +
+
TL
+
+ cases_bytes.testTuple#2dd3bacf tpl:(tuple string 4) = cases_bytes.TestTuple; +
+
+ +

cases_bytes.testVector

+ +

+
+
JSON
+
+ { + + + + + + + +
  "arr": [<string>, ...] +
+ } +
+
TL
+
+ cases_bytes.testVector#3647c8ae arr:(vector string) = cases_bytes.TestVector; +
+
+ +

cases.myCycle1

+ // BLOCK: TEST RECURSIVE TYPES
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "fields_mask": <uint32>, +
  "a": cases.myCycle2// fields_mask bit #0 + +
+ } +
+
TL
+
+ cases.myCycle1#d3ca919d fields_mask:# a:fields_mask.0?cases.myCycle2 = cases.MyCycle1; +
+
+ +

cases.myCycle2

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "fields_mask": <uint32>, +
  "a": cases.myCycle3// fields_mask bit #0 + +
+ } +
+
TL
+
+ cases.myCycle2#5444c9a2 fields_mask:# a:fields_mask.0?cases.myCycle3 = cases.MyCycle2; +
+
+ +

cases.myCycle3

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "fields_mask": <uint32>, +
  "a": cases.myCycle1// fields_mask bit #0 + +
+ } +
+
TL
+
+ cases.myCycle3#7624f86b fields_mask:# a:fields_mask.0?cases.myCycle1 = cases.MyCycle3; +
+
+ +

cases.replace7

+ // BLOCK: TEST JSON TRANSALTION SPECS
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + +
  "n": <uint32>, +
  "m": <uint32>, +
  "a": [m × [m × <int32>]] +
+ } +
+
TL
+
+ cases.replace7#6ccce4be n:# m:# a:%(__tuple n %(__tuple m int)) = cases.Replace7; +
+
+ +

cases.replace7plus

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + +
  "n": <uint32>, +
  "m": <uint32>, +
  "a": [m × [m × <int32>]]// n bit #0 + +
+ } +
+
TL
+
+ cases.replace7plus#197858f5 n:# m:# a:n.0?%(__tuple n %(__tuple m int)) = cases.Replace7plus; +
+
+ +

cases.replace7plusplus

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + +
  "N": <uint32>, +
  "M": <uint32>, +
  "A": [M × [M × <int32>]]// N bit #0 + +
+ } +
+
TL
+
+ cases.replace7plusplus#abc39b68 N:# M:# A:N.0?%(__tuple N %(__tuple M int)) = cases.Replace7plusplus; +
+
+ +

cases.testAllPossibleFieldConfigs<#>

+ +External # (nat) arguments: outer +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  "local": <uint32>, +
  "f00": <int32>, + // no fieldmask, no nat dependencies in type
+
  "f01": true, + // no fieldmask, true type
+
  "f02": [local × <int32>], + // no fieldmask, have some local nat dependencies in type
+
  "f03": [outer × <int32>], + // no fieldmask, have only external nat dependencies in type
+
  "f10": <int32>,// local bit #0 + + // local fieldmask, no nat dependencies in type
+
  "f11": true,// local bit #1 + + // local fieldmask, true type
+
  "f12": [local × <int32>],// local bit #2 + + // local fieldmask, have some local nat dependencies in type
+
  "f13": [outer × <int32>],// local bit #3 + + // local fieldmask, have only external nat dependencies in type
+
  "f20": <int32>,// outer bit #0 + + // outer fieldmask, no nat dependencies in type
+
  "f21": true,// outer bit #1 + + // outer fieldmask, true type
+
  "f22": [local × <int32>],// outer bit #2 + + // outer fieldmask, have some local nat dependencies in type
+
  "f23": [outer × <int32>]// outer bit #3 + + // outer fieldmask, have only external nat dependencies in type
+
+ } +
+
TL
+
+ cases.testAllPossibleFieldConfigs#fb6836d3 {outer:#}{outer:Type} local:# f00:int f01:%True f02:%(__tuple local int) f03:%(__tuple outer int) f10:local.0?int f11:local.1?%True f12:local.2?%(__tuple local int) f13:local.3?%(__tuple outer int) f20:outer.0?int f21:outer.1?%True f22:outer.2?%(__tuple local int) f23:outer.3?%(__tuple outer int) = cases.TestAllPossibleFieldConfigs outer; +
+
+ +

cases.testAllPossibleFieldConfigsContainer

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "outer": <uint32>, +
  "value": cases.testAllPossibleFieldConfigs<outer> +
+ } +
+
TL
+
+ cases.testAllPossibleFieldConfigsContainer#e3fae936 outer:# value:(cases.testAllPossibleFieldConfigs outer) = cases.TestAllPossibleFieldConfigsContainer; +
+
+ +

cases.testArray

+ // BLOCK: TEST BRACKETS (arrays, vectors, dicitinaries etc.)
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "n": <uint32>, +
  "arr": [n × <int32>] +
+ } +
+
TL
+
+ cases.testArray#a888030d n:# arr:%(__tuple n int) = cases.TestArray; +
+
+ +

cases.testBeforeReadBitValidation

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + +
  "n": <uint32>, +
  "a": [n × <int32>],// n bit #0 + +
  "b": [n × <int32>]// n bit #1 + +
+ } +
+
TL
+
+ cases.testBeforeReadBitValidation#9b2396db n:# a:n.0?%(__tuple n int) b:n.1?%(__tuple n int) = cases.TestBeforeReadBitValidation; +
+
+ +

cases.testDictAny

+ // will be array of tuples
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": [dictionaryFieldAny<double,int>, ...] +
+ } +
+
TL
+
+ cases.testDictAny#e29b8ae6 dict:(dictionaryAny double int) = cases.TestDictAny; +
+
+ +

cases.testDictInt

+ // will be map
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": {<int32>: <int32>} +
+ } +
+
TL
+
+ cases.testDictInt#d3877643 dict:(dictionaryAny int int) = cases.TestDictInt; +
+
+ +

cases.testDictString

+ // will be map
+ +

+
+
JSON
+
+ { + + + + + + + +
  "dict": {<string>: <int32>} +
+ } +
+
TL
+
+ cases.testDictString#c463c79b dict:(dictionary int) = cases.TestDictString; +
+
+ +

cases.TestEnum

+ +

+
+
JSON
+
+ + + + + + + + + + + + + +
"cases.testEnum1#6c6c55ac" +
"cases.testEnum2#86ea88ce" +
"cases.testEnum3#69b83e2f" +
+
+
TL
+
+
    +
  • + cases.testEnum1#6c6c55ac = cases.TestEnum; +
  • +
  • + cases.testEnum2#86ea88ce = cases.TestEnum; +
  • +
  • + cases.testEnum3#69b83e2f = cases.TestEnum; +
  • +
+
+
+ + + + +

cases.testEnumContainer

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": cases.TestEnum +
+ } +
+
TL
+
+ cases.testEnumContainer#cb684231 value:cases.TestEnum = cases.TestEnumContainer; +
+
+ +

cases.testLocalFieldmask

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + + + + + + + +
  "f1": <uint32>, +
  "f2": <uint32>,// f1 bit #0 + +
  "f3": true,// f2 bit #1 + +
  "f4": true// f2 bit #1 + +
+ } +
+
TL
+
+ cases.testLocalFieldmask#f68fd3f9 f1:# f2:f1.0?# f3:f2.1?%True f4:f2.1?%True = cases.TestLocalFieldmask; +
+
+ +

cases.testMaybe

+ // BLOCK: TEST UNIONS
+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": Maybe<int> +
+ } +
+
TL
+
+ cases.testMaybe#d6602613 value:(Maybe int) = cases.TestMaybe; +
+
+ +

cases.testOutFieldMask<#>

+ +External # (nat) arguments: f +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + +
  "f1": <uint32>,// f bit #0 + +
  "f2": true,// f bit #3 + +
  "f3": [f × <int32>] +
+ } +
+
TL
+
+ cases.testOutFieldMask#bd6b4b3c {f:#}{f:Type} f1:f.0?# f2:f.3?%True f3:%(__tuple f int) = cases.TestOutFieldMask f; +
+
+ +

cases.testOutFieldMaskContainer

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "f": <uint32>, +
  "inner": cases.testOutFieldMask<f> +
+ } +
+
TL
+
+ cases.testOutFieldMaskContainer#1850ffe4 f:# inner:(cases.testOutFieldMask f) = cases.TestOutFieldMaskContainer; +
+
+ +

cases.testRecursiveFieldMask

+ // BLOCK: TEST FIELD MASKS
+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  "f0": <uint32>, +
  "f1": <uint32>,// f0 bit #0 + +
  "f2": <uint32>,// f1 bit #1 + +
  "t1": true,// f0 bit #0 + +
  "t2": true,// f1 bit #1 + +
  "t3": true// f2 bit #2 + +
+ } +
+
TL
+
+ cases.testRecursiveFieldMask#c58cf85e f0:# f1:f0.0?# f2:f1.1?# t1:f0.0?%True t2:f1.1?%True t3:f2.2?%True = cases.TestRecursiveFieldmask; +
+
+ +

cases.testTuple

+ +

+
+
JSON
+
+ { + + + + + + + +
  "tpl": [4 × <int32>] +
+ } +
+
TL
+
+ cases.testTuple#4b9caf8f tpl:(tuple int 4) = cases.TestTuple; +
+
+ +

cases.TestUnion

+ +

+
+
JSON
+
+ + + + + + + +
{"type":"cases.testUnion1#4b4f09b1","value":cases.testUnion1} +
{"type":"cases.testUnion2#464f96c4","value":cases.testUnion2} +
+
+
TL
+
+
    +
  • + cases.testUnion1#4b4f09b1 value:int = cases.TestUnion; +
  • +
  • + cases.testUnion2#464f96c4 value:string = cases.TestUnion; +
  • +
+
+
+ +

cases.testUnion1

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": <int32> +
+ } +
+
TL
+
+ cases.testUnion1#4b4f09b1 value:int = cases.TestUnion; +
+
+ +

cases.testUnion2

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": <string> +
+ } +
+
TL
+
+ cases.testUnion2#464f96c4 value:string = cases.TestUnion; +
+
+ +

cases.testUnionContainer

+ +

+
+
JSON
+
+ { + + + + + + + +
  "value": cases.TestUnion +
+ } +
+
TL
+
+ cases.testUnionContainer#4497a381 value:cases.TestUnion = cases.TestUnionContainer; +
+
+ +

cases.testVector

+ +

+
+
JSON
+
+ { + + + + + + + +
  "arr": [<int32>, ...] +
+ } +
+
TL
+
+ cases.testVector#4975695c arr:(vector int) = cases.TestVector; +
+
+ + + +

dictionaryFieldAny<double,int>

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "key": <float64>, +
  "value": <int32> +
+ } +
+
TL
+
+ dictionaryFieldAny#2c43a65b {k:Type} {v:Type} key:k value:v = DictionaryFieldAny k v; +
+
+ +

dictionaryFieldAny<int,int>

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "key": <int32>, +
  "value": <int32> +
+ } +
+
TL
+
+ dictionaryFieldAny#2c43a65b {k:Type} {v:Type} key:k value:v = DictionaryFieldAny k v; +
+
+ +

dictionaryField<int>

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "key": <string>, +
  "value": <int32> +
+ } +
+
TL
+
+ dictionaryField#239c1b62 {t:Type} key:string value:t = DictionaryField t; +
+
+ +

dictionaryField<string>

+ +

+
+
JSON
+
+ { + + + + + + + + + + + + + +
  "key": <string>, +
  "value": <string> +
+ } +
+
TL
+
+ dictionaryField#239c1b62 {t:Type} key:string value:t = DictionaryField t; +
+
+ + + + + + +

Maybe<int>

+ +

+
+
JSON
+
+
    +
  • {}
  • +
  • {"value": <int32>}
  • +
+
+
TL
+
+
    +
  • resultFalse#27930a7b {t:Type} = Maybe t;
  • +
  • resultTrue#3f9c8ef8 {t:Type} t = Maybe t;
  • +
+
+
+ + + + + + + + + + + + + + + + + + + From f03af6c5b0f9da5388555040df2c6179ea1d8368 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 19:10:01 +0300 Subject: [PATCH 19/37] push test on cases --- .../test/codegen_test/php/test_cases.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 internal/tlcodegen/test/codegen_test/php/test_cases.php diff --git a/internal/tlcodegen/test/codegen_test/php/test_cases.php b/internal/tlcodegen/test/codegen_test/php/test_cases.php new file mode 100644 index 0000000..d36f353 --- /dev/null +++ b/internal/tlcodegen/test/codegen_test/php/test_cases.php @@ -0,0 +1,90 @@ += 0; $i -= 2) { + $digit = digit_to_value($chunk[$i]) + 16 * digit_to_value($chunk[$i - 1]); + $result .= chr($digit); + } + } + return $result; +} + +function string_to_hex(string $data): string { + $chunks = []; + for($i = 0; $i < strlen($data); $i += 4) { + $chunk = ""; + for($s = 3; $s >= 0; $s -= 1) { + $chunk .= value_to_digit(ord($data[$i + $s]) / 16); + $chunk .= value_to_digit(ord($data[$i + $s]) % 16); + } + $chunks []= $chunk; + } + return join(" ", $chunks); +} + +$PATH_TO_DATA = "../data/test-objects-bytes.json"; + +$value = json_decode(file_get_contents($PATH_TO_DATA)); +$factory = new VK\TL\tl_factory(); + +foreach($value->Tests as $test_name => $test_data) { + $testing_type = $test_data->TestingType; + foreach($test_data->Successes as $exact_test) { + $input_data = hex_to_string($exact_test->Bytes); + + $stream = new VK\TL\tl_input_stream($input_data); + $output = new VK\TL\tl_output_stream(""); + + $object = $factory->tl_object_by_name($testing_type); + if ($object == null) { + throw new Exception(sprintf("no such type \"%s\"", $testing_type)); + } + + $success = $object->read($stream); + if (!$success) { + throw new Exception(sprintf("\nunsuccessfull read for type \"%s\" on data \"%s\"", $testing_type, $exact_test["Bytes"])); + } + + $success = $object->write($output); + if (!$success) { + throw new Exception(sprintf("\nunsuccessfull write for type \"%s\" on data \"%s\"", $testing_type, $exact_test["Bytes"])); + } + + if ($input_data != $output->get_data()) { + throw new Exception(sprintf("\nread and write result are different on \"%s\":\n\texpected: %s\n\tactual: %s\n", $testing_type, string_to_hex($input_data), string_to_hex($output->get_data()))); + } + + printf("Test with \"%s\" passed on \"%s\"\n", $testing_type, string_to_hex($input_data)); + } +} + +printf("\nAll tests are passed!\n"); \ No newline at end of file From 6b631d8fd7b298e90cd0f4979465c296ac02ee5c Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 15 Jan 2025 19:11:06 +0300 Subject: [PATCH 20/37] push makefile --- internal/tlcodegen/test/codegen_test/php/Makefile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 internal/tlcodegen/test/codegen_test/php/Makefile diff --git a/internal/tlcodegen/test/codegen_test/php/Makefile b/internal/tlcodegen/test/codegen_test/php/Makefile new file mode 100644 index 0000000..a957df9 --- /dev/null +++ b/internal/tlcodegen/test/codegen_test/php/Makefile @@ -0,0 +1,2 @@ +run-all-tests: + php test_cases.php \ No newline at end of file From a72d11f08321ed6ff04f34e8bcfb5f339c42b247 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Thu, 16 Jan 2025 12:31:29 +0300 Subject: [PATCH 21/37] make more simple to use makefile + clen debug --- .../tlcodegen/test/codegen_test/php/Makefile | 28 +- .../test/codegen_test/php/basictl.php | 220 --- .../test/codegen_test/php/test_basictl.php | 13 +- .../test/codegen_test/php/test_cases.php | 2 +- .../Types/benchmarks_vruposition.php | 6 +- .../benchmarks_vrutoyTopLevelContainer.php | 2 +- ..._vrutoyTopLevelContainerWithDependency.php | 4 +- .../benchmarks_vrutoytopLevelUnionBig.php | 4 +- .../VK/TL/cases/Types/cases_myCycle1.php | 4 +- .../VK/TL/cases/Types/cases_myCycle2.php | 4 +- .../VK/TL/cases/Types/cases_myCycle3.php | 4 +- .../VK/TL/cases/Types/cases_replace7plus.php | 2 +- .../TL/cases/Types/cases_replace7plusplus.php | 2 +- .../cases_testAllPossibleFieldConfigs.php | 12 +- ...s_testAllPossibleFieldConfigsContainer.php | 4 +- .../cases_testBeforeReadBitValidation.php | 4 +- .../VK/TL/cases/Types/cases_testDictAny.php | 4 +- .../cases/Types/cases_testEnumContainer.php | 2 +- .../cases/Types/cases_testLocalFieldmask.php | 2 +- .../TL/cases/Types/cases_testOutFieldMask.php | 2 +- .../Types/cases_testOutFieldMaskContainer.php | 4 +- .../Types/cases_testRecursiveFieldMask.php | 4 +- .../cases/Types/cases_testUnionContainer.php | 2 +- .../Types/cases_bytes_testDictAny.php | 4 +- .../Types/cases_bytes_testEnumContainer.php | 2 +- .../test/gen/cases_php/tlgen2_version.txt | 4 +- .../tlcodegen/test/gen/cases_php/tljson.html | 1675 ----------------- internal/tlcodegen/tlgen_lang_php.go | 8 - internal/tlcodegen/type_rw.go | 3 - internal/tlcodegen/type_rw_struct_php.go | 6 - 30 files changed, 76 insertions(+), 1961 deletions(-) delete mode 100644 internal/tlcodegen/test/codegen_test/php/basictl.php delete mode 100644 internal/tlcodegen/test/gen/cases_php/tljson.html diff --git a/internal/tlcodegen/test/codegen_test/php/Makefile b/internal/tlcodegen/test/codegen_test/php/Makefile index a957df9..ab7ab62 100644 --- a/internal/tlcodegen/test/codegen_test/php/Makefile +++ b/internal/tlcodegen/test/codegen_test/php/Makefile @@ -1,2 +1,26 @@ -run-all-tests: - php test_cases.php \ No newline at end of file +build-tlgen: + @cd ../../../../../; \ + $(MAKE) build; + +build-php-files: build-tlgen + @cd ../../../../../; \ + ./target/bin/tlgen \ + --language=php \ + --php-serialization-bodies \ + --php-generate-meta \ + --php-generate-factory \ + --php-ignore-unused-types=false \ + --php-rpc-support=false \ + --php-inplace-simple-structs=false \ + \ + --outdir=./internal/tlcodegen/test/gen/cases_php \ + \ + --schemaURL="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/cases.tl" \ + --schemaCommit="php gen cases test" \ + --schemaTimestamp=1737019773 \ + \ + ./internal/tlcodegen/test/tls/cases.tl + +run-all-tests: build-php-files + php test_cases.php; + php test_basictl.php; \ No newline at end of file diff --git a/internal/tlcodegen/test/codegen_test/php/basictl.php b/internal/tlcodegen/test/codegen_test/php/basictl.php deleted file mode 100644 index 1d54be6..0000000 --- a/internal/tlcodegen/test/codegen_test/php/basictl.php +++ /dev/null @@ -1,220 +0,0 @@ -data = $data; - } - - public function get_offset(): int { - return $this->offset; - } - - public function remaining_size(): int { - return strlen($this->data) - $this->offset; - } - - /** @return tuple(int, bool) */ - public function read_int32() { - // TODO: 'l' - signed 32 bit SYSTEM DEPENDENT ENDIAN - $data = unpack('l', $this->data, $this->offset); - if (!$data) { - return [0, false]; - } else { - $this->offset += 4; - return [$data[1], true]; - } - } - - /** @return tuple(int, bool) */ - public function read_uint32() { - $data = unpack('V', $this->data, $this->offset); - if (!$data) { - return [0, false]; - } else { - $this->offset += 4; - return [$data[1], true]; - } - } - - /** @return tuple(bool, bool) */ - public function read_bool(int $false_tag, $true_tag) { - [$tag, $success] = $this->read_uint32(); - if (!$success) { - return [false, false]; - } else if ($tag == $false_tag) { - return [false, true]; - } else if ($tag == $true_tag) { - return [true, true]; - } - return [false, false]; - } - - /** @return tuple(float, bool) */ - public function read_float() { - $data = unpack('f', $this->data, $this->offset); - if (!$data) { - return [0, false]; - } else { - $this->offset += 4; - return [$data[1], true]; - } - } - - /** @return tuple(float, bool) */ - public function read_double() { - $data = unpack('d', $this->data, $this->offset); - if (!$data) { - return [0, false]; - } else { - $this->offset += 8; - return [$data[1], true]; - } - } - - /** @return tuple(string, bool) */ - public function read_string() { - $size = $this->remaining_size(); - if ($size == 0) { - return ["", false]; - } - $first_byte = ord($this->data[$this->offset]); - $l = 0; - $p = 0; - if ($first_byte < tl_constants::tinyStringLen) { - $l = $first_byte; - $this->offset += 1; - $p = $l + 1; - } elseif ($first_byte == tl_constants::bigStringMarker) { - if ($size < 4) { - return ["", false]; - } - $l = (ord($this->data[$this->offset + 3]) << 16) + (ord($this->data[$this->offset + 2]) << 8) + (ord($this->data[$this->offset + 1]) << 0); - $this->offset += 4; - $p = $l; - if ($l <= tl_constants::tinyStringLen) { - return ["", false]; - } - } else { - if ($size < 8) { - 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 - $l = $l64; - $this->offset += 8; - $p = $l; - if ($l <= tl_constants::bigStringLen) { - return ["", false]; - } - } - $start = $this->offset; - if ($l > 0) { - if ($this->remaining_size() < $l) { - return ["", false]; - } - } - $padding = $this->paddingLen($p); - for ($i = 0; $i < $padding; $i++) { - if (ord($this->data[$this->offset + $l + $i]) != 0) { - return ["", false]; - } - } - $this->offset += $l + $padding; - return [substr($this->data, $start, $l), true]; - } - - function paddingLen(int $l): int { - return (4 - ($l % 4)) % 4; - } -} - -class tl_output_stream { - /** @var string */ - private $data = ""; - - public function __construct(string $data) { - $this->data = $data; - } - - public function get_data(): string { - return $this->data; - } - - public function write_uint32(int $value) { - $this->data .= pack('V', $value); - } - - public function write_int32(int $value) { - $this->data .= pack('l', $value); - } - - public function write_bool(bool $value, int $false_tag, $true_tag) { - if ($value) { - $this->data .= pack('V', $true_tag); - } else { - $this->data .= pack('V', $false_tag); - } - } - - public function write_float(float $value) { - $this->data .= pack('f', $value); - } - - public function write_double(float $value) { - $this->data .= pack('d', $value); - } - - public function write_string(string $value) { - $l = strlen($value); - $p = 0; - if ($l <= tl_constants::tinyStringLen) { - $this->data .= chr($l); - $p = $l + 1; - } else if ($l <= tl_constants::bigStringLen) { - $this->data .= chr(tl_constants::bigStringMarker); - $this->data .= chr(($l & 255)); - $this->data .= chr((($l >> 8) & 255)); - $this->data .= chr((($l >> 16) & 255)); - $p = $l; - } else { - if ($l > tl_constants::hugeStringLen) { - $l = tl_constants::hugeStringLen; - $value = substr($value, 0, $l); - } - $this->data .= chr(tl_constants::hugeStringMarker); - $this->data .= chr(($l & 255)); - $this->data .= chr((($l >> 8) & 255)); - $this->data .= chr((($l >> 16) & 255)); - $this->data .= chr((($l >> 24) & 255)); - $this->data .= chr((($l >> 32) & 255)); - $this->data .= chr((($l >> 40) & 255)); - $this->data .= chr((($l >> 48) & 255)); - $p = $l; - } - $this->data .= $value; - if ($p % 4 == 1) { - $this->data .= chr(0); - $this->data .= chr(0); - $this->data .= chr(0); - } else if ($p % 4 == 2) { - $this->data .= chr(0); - $this->data .= chr(0); - } else if ($p % 4 == 3) { - $this->data .= chr(0); - } - } -} -?> \ No newline at end of file diff --git a/internal/tlcodegen/test/codegen_test/php/test_basictl.php b/internal/tlcodegen/test/codegen_test/php/test_basictl.php index 24fd0cb..c7d3280 100644 --- a/internal/tlcodegen/test/codegen_test/php/test_basictl.php +++ b/internal/tlcodegen/test/codegen_test/php/test_basictl.php @@ -1,6 +1,9 @@ data_type) { case "string": { $w->write_string($this->serializing_data); @@ -57,7 +60,7 @@ public function test_read_write_interaction(): bool if ($this->tl_data && $serialized_data != test_case::binary_to_string($this->tl_data)) { return false; } - $r = new tl_input_stream($w->get_data()); + $r = new TL\tl_input_stream($w->get_data()); $return_value = ""; $success = true; switch ($this->data_type) { @@ -128,9 +131,9 @@ function bool_to_string(bool $x): string } if (count($failed_tests) == 0) { - printf("ALL TESTS PASSED!\n"); + printf("\033[01;32mAll tests are passed!\033[0m\n"); } else { - printf("FAILED %d TESTS:\n", count($failed_tests)); + printf("Failed %d tests:\n", count($failed_tests)); foreach ($failed_tests as $failed_test) { printf("\t%s\n", $failed_test); } diff --git a/internal/tlcodegen/test/codegen_test/php/test_cases.php b/internal/tlcodegen/test/codegen_test/php/test_cases.php index d36f353..e3ec5c5 100644 --- a/internal/tlcodegen/test/codegen_test/php/test_cases.php +++ b/internal/tlcodegen/test/codegen_test/php/test_cases.php @@ -87,4 +87,4 @@ function string_to_hex(string $data): string { } } -printf("\nAll tests are passed!\n"); \ No newline at end of file +printf("\n\033[01;32mAll tests are passed!\033[01;0m\n"); \ No newline at end of file diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php index 873e4e6..e7bc4cb 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vruposition.php @@ -135,7 +135,7 @@ public function read($stream) { if (!$success) { return false; } - if ($this->hash == null) { + if (is_null($this->hash)) { $this->hash = new TL\benchmarks\Types\benchmarks_vruhash(); } $success = $this->hash->read($stream); @@ -186,7 +186,7 @@ public function write($stream) { if (!$success) { return false; } - if ($this->hash == null) { + if (is_null($this->hash)) { $this->hash = new TL\benchmarks\Types\benchmarks_vruhash(); } $success = $this->hash->write($stream); @@ -228,7 +228,7 @@ public function calculateFieldsMask() { $mask |= self::BIT_ROTATION_BLOCK_5; } - if ($this->seq_number !== null) { + if (!is_null($this->seq_number)) { $mask |= self::BIT_SEQ_NUMBER_14; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php index b3f5e31..d291990 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainer.php @@ -86,7 +86,7 @@ public function write_boxed($stream) { * @return bool */ public function write($stream) { - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\benchmarks\Types\benchmarks_vrutoytopLevelUnionBig(); } $success = $this->value->write_boxed($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php index 08fae3a..41d6ac0 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php @@ -54,7 +54,7 @@ public function read($stream) { $this->value = []; for($i28 = 0; $i28 < $this->n; $i28++) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - if ($array_benchmarks_VruPosition___element == null) { + if (is_null($array_benchmarks_VruPosition___element)) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); } $success = $array_benchmarks_VruPosition___element->read($stream); @@ -88,7 +88,7 @@ public function write($stream) { return false; } for($i28 = 0; $i28 < $this->n; $i28++) { - if ($this->value[$i28] == null) { + if (is_null($this->value[$i28])) { $this->value[$i28] = new TL\benchmarks\Types\benchmarks_vruposition(); } $success = $this->value[$i28]->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php index 1f72992..3d9101a 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php @@ -49,7 +49,7 @@ public function read($stream) { $this->next_positions = []; for($i28 = 0; $i28 < $vector_size; $i28++) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - if ($array_benchmarks_VruPosition___element == null) { + if (is_null($array_benchmarks_VruPosition___element)) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); } $success = $array_benchmarks_VruPosition___element->read($stream); @@ -83,7 +83,7 @@ public function write($stream) { return false; } for($i28 = 0; $i28 < count($this->next_positions); $i28++) { - if ($this->next_positions[$i28] == null) { + if (is_null($this->next_positions[$i28])) { $this->next_positions[$i28] = new TL\benchmarks\Types\benchmarks_vruposition(); } $success = $this->next_positions[$i28]->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle1.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle1.php index 1aa293b..26e51ef 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle1.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle1.php @@ -53,7 +53,7 @@ public function read($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle2(); } $success = $this->a->read($stream); @@ -88,7 +88,7 @@ public function write($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle2(); } $success = $this->a->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php index 1d1c830..5c543c4 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle2.php @@ -53,7 +53,7 @@ public function read($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle3(); } $success = $this->a->read($stream); @@ -88,7 +88,7 @@ public function write($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle3(); } $success = $this->a->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php index 6236610..88a9f9a 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_myCycle3.php @@ -53,7 +53,7 @@ public function read($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle1(); } $success = $this->a->read($stream); @@ -88,7 +88,7 @@ public function write($stream) { return false; } if (($this->fields_mask & (1 << 0)) != 0) { - if ($this->a == null) { + if (is_null($this->a)) { $this->a = new TL\cases\Types\cases_myCycle1(); } $success = $this->a->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php index 8f9a8d5..fef19a4 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php @@ -126,7 +126,7 @@ public function write($stream) { public function calculateN() { $mask = 0; - if ($this->a !== null) { + if (!is_null($this->a)) { $mask |= self::BIT_A_0; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php index 625f866..2d06d84 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php @@ -126,7 +126,7 @@ public function write($stream) { public function calculateN() { $mask = 0; - if ($this->A !== null) { + if (!is_null($this->A)) { $mask |= self::BIT_A_0; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php index 9a26858..068ba17 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php @@ -312,7 +312,7 @@ public function write($stream, $outer) { public function calculateLocal() { $mask = 0; - if ($this->f10 !== null) { + if (!is_null($this->f10)) { $mask |= self::BIT_F10_0; } @@ -320,11 +320,11 @@ public function calculateLocal() { $mask |= self::BIT_F11_1; } - if ($this->f12 !== null) { + if (!is_null($this->f12)) { $mask |= self::BIT_F12_2; } - if ($this->f13 !== null) { + if (!is_null($this->f13)) { $mask |= self::BIT_F13_3; } @@ -337,7 +337,7 @@ public function calculateLocal() { public function calculateOuter() { $mask = 0; - if ($this->f20 !== null) { + if (!is_null($this->f20)) { $mask |= self::BIT_F20_0; } @@ -345,11 +345,11 @@ public function calculateOuter() { $mask |= self::BIT_F21_1; } - if ($this->f22 !== null) { + if (!is_null($this->f22)) { $mask |= self::BIT_F22_2; } - if ($this->f23 !== null) { + if (!is_null($this->f23)) { $mask |= self::BIT_F23_3; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php index 1471ebc..02c5629 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigsContainer.php @@ -51,7 +51,7 @@ public function read($stream) { if (!$success) { return false; } - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\cases\Types\cases_testAllPossibleFieldConfigs(); } $success = $this->value->read($stream, $this->outer); @@ -82,7 +82,7 @@ public function write($stream) { if (!$success) { return false; } - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\cases\Types\cases_testAllPossibleFieldConfigs(); } $success = $this->value->write($stream, $this->outer); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php index c7d40d7..e6a7af1 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php @@ -133,11 +133,11 @@ public function write($stream) { public function calculateN() { $mask = 0; - if ($this->a !== null) { + if (!is_null($this->a)) { $mask |= self::BIT_A_0; } - if ($this->b !== null) { + if (!is_null($this->b)) { $mask |= self::BIT_B_1; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php index ee443a8..24ff3a4 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php @@ -49,7 +49,7 @@ public function read($stream) { $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - if ($array_DictionaryFieldAny__float__int___element == null) { + if (is_null($array_DictionaryFieldAny__float__int___element)) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); } $success = $array_DictionaryFieldAny__float__int___element->read($stream); @@ -83,7 +83,7 @@ public function write($stream) { return false; } for($i36 = 0; $i36 < count($this->dict); $i36++) { - if ($this->dict[$i36] == null) { + if (is_null($this->dict[$i36])) { $this->dict[$i36] = new TL\_common\Types\dictionaryFieldAny__float__int(); } $success = $this->dict[$i36]->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php index 7098fa2..f9857b3 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testEnumContainer.php @@ -94,7 +94,7 @@ public function write_boxed($stream) { * @return bool */ public function write($stream) { - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\cases\Types\cases_testEnum1(); } $success = $this->value->write_boxed($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php index 637d524..ae3f5fe 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testLocalFieldmask.php @@ -121,7 +121,7 @@ public function write($stream) { public function calculateF1() { $mask = 0; - if ($this->f2 !== null) { + if (!is_null($this->f2)) { $mask |= self::BIT_F2_0; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php index d89b7a0..e4f5cbc 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php @@ -121,7 +121,7 @@ public function write($stream, $f) { public function calculateF() { $mask = 0; - if ($this->f1 !== null) { + if (!is_null($this->f1)) { $mask |= self::BIT_F1_0; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php index d74cd3f..6bae3a1 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMaskContainer.php @@ -51,7 +51,7 @@ public function read($stream) { if (!$success) { return false; } - if ($this->inner == null) { + if (is_null($this->inner)) { $this->inner = new TL\cases\Types\cases_testOutFieldMask(); } $success = $this->inner->read($stream, $this->f); @@ -82,7 +82,7 @@ public function write($stream) { if (!$success) { return false; } - if ($this->inner == null) { + if (is_null($this->inner)) { $this->inner = new TL\cases\Types\cases_testOutFieldMask(); } $success = $this->inner->write($stream, $this->f); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php index 8172603..8f3bd97 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testRecursiveFieldMask.php @@ -152,7 +152,7 @@ public function write($stream) { public function calculateF0() { $mask = 0; - if ($this->f1 !== null && $this->t1) { + if (!is_null($this->f1) && $this->t1) { $mask |= (self::BIT_F1_0 | self::BIT_T1_0); } @@ -165,7 +165,7 @@ public function calculateF0() { public function calculateF1() { $mask = 0; - if ($this->f2 !== null && $this->t2) { + if (!is_null($this->f2) && $this->t2) { $mask |= (self::BIT_F2_1 | self::BIT_T2_1); } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php index d6415fa..c283f53 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testUnionContainer.php @@ -86,7 +86,7 @@ public function write_boxed($stream) { * @return bool */ public function write($stream) { - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\cases\Types\cases_testUnion1(); } $success = $this->value->write_boxed($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php index d1254fb..36edf02 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php @@ -49,7 +49,7 @@ public function read($stream) { $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - if ($array_DictionaryFieldAny__float__int___element == null) { + if (is_null($array_DictionaryFieldAny__float__int___element)) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); } $success = $array_DictionaryFieldAny__float__int___element->read($stream); @@ -83,7 +83,7 @@ public function write($stream) { return false; } for($i36 = 0; $i36 < count($this->dict); $i36++) { - if ($this->dict[$i36] == null) { + if (is_null($this->dict[$i36])) { $this->dict[$i36] = new TL\_common\Types\dictionaryFieldAny__float__int(); } $success = $this->dict[$i36]->write($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php index b7cc580..b702663 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testEnumContainer.php @@ -94,7 +94,7 @@ public function write_boxed($stream) { * @return bool */ public function write($stream) { - if ($this->value == null) { + if (is_null($this->value)) { $this->value = new TL\cases\Types\cases_testEnum1(); } $success = $this->value->write_boxed($stream); diff --git a/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt b/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt index b7eb433..8aed2ac 100644 --- a/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt +++ b/internal/tlcodegen/test/gen/cases_php/tlgen2_version.txt @@ -1,4 +1,4 @@ tlgen version: (devel) schema url: https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/cases.tl -schema commit: abcdefgh -schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC) +schema commit: php gen cases test +schema version: 1737019773 (2025-01-16 09:29:33 +0000 UTC) diff --git a/internal/tlcodegen/test/gen/cases_php/tljson.html b/internal/tlcodegen/test/gen/cases_php/tljson.html deleted file mode 100644 index cfa476a..0000000 --- a/internal/tlcodegen/test/gen/cases_php/tljson.html +++ /dev/null @@ -1,1675 +0,0 @@ - - - - - - TL JSON help - - -

Schema

-
    -
  • tlgen version: (devel)
  • -
  • TL schema url
  • -
  • TL schema commit: abcdefgh
  • -
  • TL schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)
  • -
  • TL ⟷ JSON mapping rules: TLJSON.md
  • -
-

Functions

-
    -
-

Types

-

#

-Builtin type #. Represents uint32. Can be used as field mask or collection size. -

benchmarks.vruhash

- // BLOCK: BENCHMARKS
- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "low": <int64>, -
  "high": <int64> -
- } -
-
TL
-
- benchmarks.vruhash#d31bd0fd low:long high:long = benchmarks.VruHash; - // We store xxh3 components in LE endianness, as common in TL
-
-
- -

benchmarks.vruposition

- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  "fields_mask": <uint32>, -
  "commit_bit": true,// fields_mask bit #0 - - // we set this bit only if block with this bit set is committed, so we have no more than 1 such uncommitted block.
-
  "meta_block": true,// fields_mask bit #1 - - // this block contains meta data of VR protocol
-
  "split_payload": true,// fields_mask bit #3 - - // this position splits payload. If this set, meta_block and commit_bit are both not set
-
  "rotation_block": true,// fields_mask bit #5 - - // If set, binlog should rotate and this block should be in new file
-
  "canonical_hash": true,// fields_mask bit #15 - - // If set, hash is stored in canonical byte order.
-
  "payload_offset": <int64>, - // Motivation for storing it in each block - when random seeking into the middle of file, we must be sure without scanning from beginning
-
  "block_time_nano": <int64>, - // Only for debug, not used in any logic
-
  "hash": benchmarks.vruhash, -
  "file_offset": <int64>, -
  "seq_number": <int64>// fields_mask bit #14 - - // incremented after each block.
-
- } -
-
TL
-
- benchmarks.vruposition#32792c04 fields_mask:# commit_bit:fields_mask.0?true meta_block:fields_mask.1?true split_payload:fields_mask.3?true rotation_block:fields_mask.5?true canonical_hash:fields_mask.15?true payload_offset:long block_time_nano:long hash:benchmarks.vruhash file_offset:long seq_number:fields_mask.14?long = benchmarks.VruPosition; -
-
- -

benchmarks.vrutoyPositions<#>

- -External # (nat) arguments: n -

-
-
JSON
-
- { - - - - - - - -
  "next_positions": [n × benchmarks.vruposition] -
- } -
-
TL
-
- benchmarks.vrutoyPositions#b6003de0 {n:#}{n:Type} next_positions:%(__tuple n benchmarks.vruposition) = benchmarks.VrutoyPositions n; -
-
- -

benchmarks.vrutoyTopLevelContainer

- -

-
-
JSON
-
- { - - - - - - - -
  "value": benchmarks.VrutoyTopLevelUnion -
- } -
-
TL
-
- benchmarks.vrutoyTopLevelContainer#fb442ca5 value:benchmarks.VrutoyTopLevelUnion = benchmarks.VrutoyTopLevelContainer; -
-
- -

benchmarks.vrutoyTopLevelContainerWithDependency

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "n": <uint32>, -
  "value": benchmarks.vrutoyPositions<n> -
- } -
-
TL
-
- benchmarks.vrutoyTopLevelContainerWithDependency#c176008e n:# value:(benchmarks.vrutoyPositions n) = benchmarks.VrutoyTopLevelContainerWithDependency; -
-
- -

benchmarks.VrutoyTopLevelUnion

- -

-
-
JSON
-
- - - - - - - -
{"type":"benchmarks.vrutoytopLevelUnionBig#ef556bee","value":benchmarks.vrutoytopLevelUnionBig} -
{"type":"benchmarks.vrutoytopLevelUnionEmpty#ce27c770"} -
-
-
TL
-
-
    -
  • - benchmarks.vrutoytopLevelUnionBig#ef556bee next_positions:(vector benchmarks.vruposition) = benchmarks.VrutoyTopLevelUnion; -
  • -
  • - benchmarks.vrutoytopLevelUnionEmpty#ce27c770 = benchmarks.VrutoyTopLevelUnion; -
  • -
-
-
- -

benchmarks.vrutoytopLevelUnionBig

- -

-
-
JSON
-
- { - - - - - - - -
  "next_positions": [benchmarks.vruposition, ...] -
- } -
-
TL
-
- benchmarks.vrutoytopLevelUnionBig#ef556bee next_positions:(vector benchmarks.vruposition) = benchmarks.VrutoyTopLevelUnion; -
-
- - - - - - - - - - - - - - - -

cases_bytes.testArray

- // BLOCK: Bytes vesrion
- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "n": <uint32>, -
  "arr": [n × <string>] -
- } -
-
TL
-
- cases_bytes.testArray#3762fb81 n:# arr:%(__tuple n string) = cases_bytes.TestArray; -
-
- -

cases_bytes.testDictAny

- // will be array of tuples
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": [dictionaryFieldAny<double,int>, ...] -
- } -
-
TL
-
- cases_bytes.testDictAny#5a5fce57 dict:(dictionaryAny double int) = cases_bytes.TestDictAny; -
-
- -

cases_bytes.testDictInt

- // will be map
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": {<int32>: <int32>} -
- } -
-
TL
-
- cases_bytes.testDictInt#453ace07 dict:(dictionaryAny int int) = cases_bytes.TestDictInt; -
-
- -

cases_bytes.testDictString

- // will be map
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": {<string>: <int32>} -
- } -
-
TL
-
- cases_bytes.testDictString#6c04d6ce dict:(dictionary int) = cases_bytes.TestDictString; -
-
- -

cases_bytes.testDictStringString

- // will be map
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": {<string>: <string>} -
- } -
-
TL
-
- cases_bytes.testDictStringString#ad69c772 dict:(dictionary string) = cases_bytes.TestDictStringString; -
-
- -

cases_bytes.TestEnum

- -

-
-
JSON
-
- - - - - - - - - - - - - -
"cases_bytes.testEnum1#58aad3f5" -
"cases_bytes.testEnum2#00b47add" -
"cases_bytes.testEnum3#81911ffa" -
-
-
TL
-
-
    -
  • - cases_bytes.testEnum1#58aad3f5 = cases_bytes.TestEnum; -
  • -
  • - cases_bytes.testEnum2#00b47add = cases_bytes.TestEnum; -
  • -
  • - cases_bytes.testEnum3#81911ffa = cases_bytes.TestEnum; -
  • -
-
-
- - - - -

cases_bytes.testEnumContainer

- -

-
-
JSON
-
- { - - - - - - - -
  "value": cases.TestEnum -
- } -
-
TL
-
- cases_bytes.testEnumContainer#32b92037 value:cases.TestEnum = cases_bytes.TestEnumContainer; -
-
- -

cases_bytes.testTuple

- -

-
-
JSON
-
- { - - - - - - - -
  "tpl": [4 × <string>] -
- } -
-
TL
-
- cases_bytes.testTuple#2dd3bacf tpl:(tuple string 4) = cases_bytes.TestTuple; -
-
- -

cases_bytes.testVector

- -

-
-
JSON
-
- { - - - - - - - -
  "arr": [<string>, ...] -
- } -
-
TL
-
- cases_bytes.testVector#3647c8ae arr:(vector string) = cases_bytes.TestVector; -
-
- -

cases.myCycle1

- // BLOCK: TEST RECURSIVE TYPES
- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "fields_mask": <uint32>, -
  "a": cases.myCycle2// fields_mask bit #0 - -
- } -
-
TL
-
- cases.myCycle1#d3ca919d fields_mask:# a:fields_mask.0?cases.myCycle2 = cases.MyCycle1; -
-
- -

cases.myCycle2

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "fields_mask": <uint32>, -
  "a": cases.myCycle3// fields_mask bit #0 - -
- } -
-
TL
-
- cases.myCycle2#5444c9a2 fields_mask:# a:fields_mask.0?cases.myCycle3 = cases.MyCycle2; -
-
- -

cases.myCycle3

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "fields_mask": <uint32>, -
  "a": cases.myCycle1// fields_mask bit #0 - -
- } -
-
TL
-
- cases.myCycle3#7624f86b fields_mask:# a:fields_mask.0?cases.myCycle1 = cases.MyCycle3; -
-
- -

cases.replace7

- // BLOCK: TEST JSON TRANSALTION SPECS
- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - -
  "n": <uint32>, -
  "m": <uint32>, -
  "a": [m × [m × <int32>]] -
- } -
-
TL
-
- cases.replace7#6ccce4be n:# m:# a:%(__tuple n %(__tuple m int)) = cases.Replace7; -
-
- -

cases.replace7plus

- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - -
  "n": <uint32>, -
  "m": <uint32>, -
  "a": [m × [m × <int32>]]// n bit #0 - -
- } -
-
TL
-
- cases.replace7plus#197858f5 n:# m:# a:n.0?%(__tuple n %(__tuple m int)) = cases.Replace7plus; -
-
- -

cases.replace7plusplus

- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - -
  "N": <uint32>, -
  "M": <uint32>, -
  "A": [M × [M × <int32>]]// N bit #0 - -
- } -
-
TL
-
- cases.replace7plusplus#abc39b68 N:# M:# A:N.0?%(__tuple N %(__tuple M int)) = cases.Replace7plusplus; -
-
- -

cases.testAllPossibleFieldConfigs<#>

- -External # (nat) arguments: outer -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  "local": <uint32>, -
  "f00": <int32>, - // no fieldmask, no nat dependencies in type
-
  "f01": true, - // no fieldmask, true type
-
  "f02": [local × <int32>], - // no fieldmask, have some local nat dependencies in type
-
  "f03": [outer × <int32>], - // no fieldmask, have only external nat dependencies in type
-
  "f10": <int32>,// local bit #0 - - // local fieldmask, no nat dependencies in type
-
  "f11": true,// local bit #1 - - // local fieldmask, true type
-
  "f12": [local × <int32>],// local bit #2 - - // local fieldmask, have some local nat dependencies in type
-
  "f13": [outer × <int32>],// local bit #3 - - // local fieldmask, have only external nat dependencies in type
-
  "f20": <int32>,// outer bit #0 - - // outer fieldmask, no nat dependencies in type
-
  "f21": true,// outer bit #1 - - // outer fieldmask, true type
-
  "f22": [local × <int32>],// outer bit #2 - - // outer fieldmask, have some local nat dependencies in type
-
  "f23": [outer × <int32>]// outer bit #3 - - // outer fieldmask, have only external nat dependencies in type
-
- } -
-
TL
-
- cases.testAllPossibleFieldConfigs#fb6836d3 {outer:#}{outer:Type} local:# f00:int f01:%True f02:%(__tuple local int) f03:%(__tuple outer int) f10:local.0?int f11:local.1?%True f12:local.2?%(__tuple local int) f13:local.3?%(__tuple outer int) f20:outer.0?int f21:outer.1?%True f22:outer.2?%(__tuple local int) f23:outer.3?%(__tuple outer int) = cases.TestAllPossibleFieldConfigs outer; -
-
- -

cases.testAllPossibleFieldConfigsContainer

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "outer": <uint32>, -
  "value": cases.testAllPossibleFieldConfigs<outer> -
- } -
-
TL
-
- cases.testAllPossibleFieldConfigsContainer#e3fae936 outer:# value:(cases.testAllPossibleFieldConfigs outer) = cases.TestAllPossibleFieldConfigsContainer; -
-
- -

cases.testArray

- // BLOCK: TEST BRACKETS (arrays, vectors, dicitinaries etc.)
- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "n": <uint32>, -
  "arr": [n × <int32>] -
- } -
-
TL
-
- cases.testArray#a888030d n:# arr:%(__tuple n int) = cases.TestArray; -
-
- -

cases.testBeforeReadBitValidation

- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - -
  "n": <uint32>, -
  "a": [n × <int32>],// n bit #0 - -
  "b": [n × <int32>]// n bit #1 - -
- } -
-
TL
-
- cases.testBeforeReadBitValidation#9b2396db n:# a:n.0?%(__tuple n int) b:n.1?%(__tuple n int) = cases.TestBeforeReadBitValidation; -
-
- -

cases.testDictAny

- // will be array of tuples
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": [dictionaryFieldAny<double,int>, ...] -
- } -
-
TL
-
- cases.testDictAny#e29b8ae6 dict:(dictionaryAny double int) = cases.TestDictAny; -
-
- -

cases.testDictInt

- // will be map
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": {<int32>: <int32>} -
- } -
-
TL
-
- cases.testDictInt#d3877643 dict:(dictionaryAny int int) = cases.TestDictInt; -
-
- -

cases.testDictString

- // will be map
- -

-
-
JSON
-
- { - - - - - - - -
  "dict": {<string>: <int32>} -
- } -
-
TL
-
- cases.testDictString#c463c79b dict:(dictionary int) = cases.TestDictString; -
-
- -

cases.TestEnum

- -

-
-
JSON
-
- - - - - - - - - - - - - -
"cases.testEnum1#6c6c55ac" -
"cases.testEnum2#86ea88ce" -
"cases.testEnum3#69b83e2f" -
-
-
TL
-
-
    -
  • - cases.testEnum1#6c6c55ac = cases.TestEnum; -
  • -
  • - cases.testEnum2#86ea88ce = cases.TestEnum; -
  • -
  • - cases.testEnum3#69b83e2f = cases.TestEnum; -
  • -
-
-
- - - - -

cases.testEnumContainer

- -

-
-
JSON
-
- { - - - - - - - -
  "value": cases.TestEnum -
- } -
-
TL
-
- cases.testEnumContainer#cb684231 value:cases.TestEnum = cases.TestEnumContainer; -
-
- -

cases.testLocalFieldmask

- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - -
  "f1": <uint32>, -
  "f2": <uint32>,// f1 bit #0 - -
  "f3": true,// f2 bit #1 - -
  "f4": true// f2 bit #1 - -
- } -
-
TL
-
- cases.testLocalFieldmask#f68fd3f9 f1:# f2:f1.0?# f3:f2.1?%True f4:f2.1?%True = cases.TestLocalFieldmask; -
-
- -

cases.testMaybe

- // BLOCK: TEST UNIONS
- -

-
-
JSON
-
- { - - - - - - - -
  "value": Maybe<int> -
- } -
-
TL
-
- cases.testMaybe#d6602613 value:(Maybe int) = cases.TestMaybe; -
-
- -

cases.testOutFieldMask<#>

- -External # (nat) arguments: f -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - -
  "f1": <uint32>,// f bit #0 - -
  "f2": true,// f bit #3 - -
  "f3": [f × <int32>] -
- } -
-
TL
-
- cases.testOutFieldMask#bd6b4b3c {f:#}{f:Type} f1:f.0?# f2:f.3?%True f3:%(__tuple f int) = cases.TestOutFieldMask f; -
-
- -

cases.testOutFieldMaskContainer

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "f": <uint32>, -
  "inner": cases.testOutFieldMask<f> -
- } -
-
TL
-
- cases.testOutFieldMaskContainer#1850ffe4 f:# inner:(cases.testOutFieldMask f) = cases.TestOutFieldMaskContainer; -
-
- -

cases.testRecursiveFieldMask

- // BLOCK: TEST FIELD MASKS
- -

-
-
JSON
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  "f0": <uint32>, -
  "f1": <uint32>,// f0 bit #0 - -
  "f2": <uint32>,// f1 bit #1 - -
  "t1": true,// f0 bit #0 - -
  "t2": true,// f1 bit #1 - -
  "t3": true// f2 bit #2 - -
- } -
-
TL
-
- cases.testRecursiveFieldMask#c58cf85e f0:# f1:f0.0?# f2:f1.1?# t1:f0.0?%True t2:f1.1?%True t3:f2.2?%True = cases.TestRecursiveFieldmask; -
-
- -

cases.testTuple

- -

-
-
JSON
-
- { - - - - - - - -
  "tpl": [4 × <int32>] -
- } -
-
TL
-
- cases.testTuple#4b9caf8f tpl:(tuple int 4) = cases.TestTuple; -
-
- -

cases.TestUnion

- -

-
-
JSON
-
- - - - - - - -
{"type":"cases.testUnion1#4b4f09b1","value":cases.testUnion1} -
{"type":"cases.testUnion2#464f96c4","value":cases.testUnion2} -
-
-
TL
-
-
    -
  • - cases.testUnion1#4b4f09b1 value:int = cases.TestUnion; -
  • -
  • - cases.testUnion2#464f96c4 value:string = cases.TestUnion; -
  • -
-
-
- -

cases.testUnion1

- -

-
-
JSON
-
- { - - - - - - - -
  "value": <int32> -
- } -
-
TL
-
- cases.testUnion1#4b4f09b1 value:int = cases.TestUnion; -
-
- -

cases.testUnion2

- -

-
-
JSON
-
- { - - - - - - - -
  "value": <string> -
- } -
-
TL
-
- cases.testUnion2#464f96c4 value:string = cases.TestUnion; -
-
- -

cases.testUnionContainer

- -

-
-
JSON
-
- { - - - - - - - -
  "value": cases.TestUnion -
- } -
-
TL
-
- cases.testUnionContainer#4497a381 value:cases.TestUnion = cases.TestUnionContainer; -
-
- -

cases.testVector

- -

-
-
JSON
-
- { - - - - - - - -
  "arr": [<int32>, ...] -
- } -
-
TL
-
- cases.testVector#4975695c arr:(vector int) = cases.TestVector; -
-
- - - -

dictionaryFieldAny<double,int>

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "key": <float64>, -
  "value": <int32> -
- } -
-
TL
-
- dictionaryFieldAny#2c43a65b {k:Type} {v:Type} key:k value:v = DictionaryFieldAny k v; -
-
- -

dictionaryFieldAny<int,int>

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "key": <int32>, -
  "value": <int32> -
- } -
-
TL
-
- dictionaryFieldAny#2c43a65b {k:Type} {v:Type} key:k value:v = DictionaryFieldAny k v; -
-
- -

dictionaryField<int>

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "key": <string>, -
  "value": <int32> -
- } -
-
TL
-
- dictionaryField#239c1b62 {t:Type} key:string value:t = DictionaryField t; -
-
- -

dictionaryField<string>

- -

-
-
JSON
-
- { - - - - - - - - - - - - - -
  "key": <string>, -
  "value": <string> -
- } -
-
TL
-
- dictionaryField#239c1b62 {t:Type} key:string value:t = DictionaryField t; -
-
- - - - - - -

Maybe<int>

- -

-
-
JSON
-
-
    -
  • {}
  • -
  • {"value": <int32>}
  • -
-
-
TL
-
-
    -
  • resultFalse#27930a7b {t:Type} = Maybe t;
  • -
  • resultTrue#3f9c8ef8 {t:Type} t = Maybe t;
  • -
-
-
- - - - - - - - - - - - - - - - - - - diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 43a3c33..6b26225 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -42,14 +42,6 @@ func (gen *Gen2) generateCodePHP(generateByteVersions []string) error { } for _, wrapper := range gen.PhpSelectTypesForGeneration() { - fmt.Println(fmt.Sprintf( - "PHP{%[1]s} in GO{%[2]s}", - wrapper.trw.PhpClassName(false, true), - wrapper.goGlobalName, - wrapper.NatParams, - wrapper.origTL[0].TemplateArguments, - wrapper.arguments), - ) err := phpGenerateCodeForWrapper(gen, wrapper, true, wrapper.PHPGenerateCode) if err != nil { return err diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index e309276..5f7a529 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -606,9 +606,6 @@ func (w *TypeRWWrapper) PHPIsPrimitiveType(recursiveCheck bool) bool { } func (w *TypeRWWrapper) PHPNeedsCode() bool { - if w.tlName.String() == "dictionary" { - print("debug") - } if w.PHPTypePath() == "" || w.PHPIsPrimitiveType(true) { return false diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index c1c46a4..1be6d64 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -370,9 +370,6 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { ) shift += 1 } - if trw.wr.tlName.String() == "cases.replace7" && field.originalName == "a" { - print("debug") - } fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) for _, line := range fieldRead { code.WriteString(textTab() + line + "\n") @@ -747,9 +744,6 @@ func (trw *TypeRWStruct) PHPStructResultType(code *strings.Builder) { func (trw *TypeRWStruct) PHPStructFields(code *strings.Builder) { // print fields declarations for _, f := range trw.Fields { - if trw.PhpClassName(false, true) == "cases_testDictString" && f.originalName == "dict" { - print("debug") - } fieldType, defaultValue := fieldTypeAndDefaultValue(f) code.WriteString( fmt.Sprintf( From 398b1a405e3aa04761f8b6713b6b19b6401d0634 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 20 Jan 2025 13:18:25 +0300 Subject: [PATCH 22/37] fix arguments push --- internal/tlcodegen/tlgen.go | 4 +- internal/tlcodegen/tlgen_lang_php.go | 4 +- internal/tlcodegen/type_rw.go | 73 +++++++++++++- internal/tlcodegen/type_rw_bool_php.go | 4 +- internal/tlcodegen/type_rw_maybe_php.go | 4 +- internal/tlcodegen/type_rw_primitive_php.go | 4 +- internal/tlcodegen/type_rw_struct_php.go | 102 +++++++++++++------- internal/tlcodegen/type_rw_tuple_php.go | 17 ++-- internal/tlcodegen/type_rw_union_php.go | 8 +- 9 files changed, 160 insertions(+), 60 deletions(-) diff --git a/internal/tlcodegen/tlgen.go b/internal/tlcodegen/tlgen.go index d962abf..690c747 100644 --- a/internal/tlcodegen/tlgen.go +++ b/internal/tlcodegen/tlgen.go @@ -1185,7 +1185,9 @@ func GenerateCode(tl tlast.TL, options Gen2Options) (*Gen2, error) { } skippedDueToWhitelist := 0 - gen.typesInfo = processCombinators(gen.allConstructors) + if gen.options.Language == "cpp" { + gen.typesInfo = processCombinators(gen.allConstructors) + } for _, typ := range tl { if LegacyGenerateUnusedNatTemplates(typ.Construct.Name.String()) && len(typ.TemplateArguments) == 1 && typ.TemplateArguments[0].IsNat { diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 6b26225..599b110 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -23,8 +23,8 @@ type TypeRWPHPData interface { // PhpDefaultValue return default value for field of this type (can be null) PhpDefaultValue() string PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) - PhpReadMethodCall(targetName string, bare bool, args []string) []string - PhpWriteMethodCall(targetName string, bare bool, args []string) []string + PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string + PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string } type PhpClassMeta struct { diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index 5f7a529..dc64a90 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -655,8 +655,9 @@ func (w *TypeRWWrapper) PHPNeedsCode() bool { } type TypeArgumentsTree struct { - value string + name string leaf bool + value *string // value != nil => leaf == True children []*TypeArgumentsTree } @@ -675,7 +676,7 @@ func (t *TypeArgumentsTree) IsEmpty() bool { func (t *TypeArgumentsTree) EnumerateWithPrefixes() []string { const natPrefix = "" values := make([]string, 0) - t.enumerateWithPrefixes(&values, "") + t.enumerateWithPrefixes(&values, "$") values = utils.MapSlice(values, func(s string) string { return natPrefix + s }) return values } @@ -696,7 +697,7 @@ func (t *TypeArgumentsTree) enumerateWithPrefixes(values *[]string, curPrefix st } else { for _, child := range t.children { if child != nil { - prefix := curPrefix + child.value + prefix := curPrefix + child.name if !child.leaf { prefix += delimiter } @@ -706,8 +707,70 @@ func (t *TypeArgumentsTree) enumerateWithPrefixes(values *[]string, curPrefix st } } +func (t *TypeArgumentsTree) ListAllValues() []string { + if t == nil { + return nil + } + values := make([]string, 0) + listAllValuesRecursive(t, &values) + return values +} + +func listAllValuesRecursive(t *TypeArgumentsTree, values *[]string) { + if t == nil { + return + } + if t.leaf { + if t.value != nil { + *values = append(*values, *t.value) + } + } else { + for _, child := range t.children { + listAllValuesRecursive(child, values) + } + } +} + +func (t *TypeArgumentsTree) FillAllLeafs() { + values := t.EnumerateWithPrefixes() + curIndex := 0 + fillAllLeafsRecursive(t, &curIndex, &values) +} + +func (t *TypeArgumentsTree) CloneValuesFrom(src *TypeArgumentsTree) { + if t == nil { + return + } + if t.leaf { + t.value = src.value + return + } + for i, child := range t.children { + if child != nil { + child.CloneValuesFrom(src.children[i]) + } + } +} + +func fillAllLeafsRecursive(t *TypeArgumentsTree, curIndex *int, values *[]string) { + if t == nil { + return + } + if t.leaf { + t.value = &(*values)[*curIndex] + *curIndex += 1 + return + } + for _, child := range t.children { + fillAllLeafsRecursive(child, curIndex, values) + } +} + func (w *TypeRWWrapper) PHPGetNatTypeDependenciesDeclAsArray() []string { t := TypeArgumentsTree{} + if w.goGlobalName == "PairIntBoxedTupleTupleInt47" { + print("debug") + } w.PHPGetNatTypeDependenciesDecl(&t) return t.EnumerateWithPrefixes() } @@ -719,11 +782,11 @@ func (w *TypeRWWrapper) PHPGetNatTypeDependenciesDecl(tree *TypeArgumentsTree) { if template.IsNat { tree.children[i] = &TypeArgumentsTree{} tree.children[i].leaf = true - tree.children[i].value = template.FieldName + tree.children[i].name = template.FieldName } else { tree.children[i] = &TypeArgumentsTree{} tree.children[i].leaf = false - tree.children[i].value = template.FieldName + tree.children[i].name = template.FieldName actualArg.tip.PHPGetNatTypeDependenciesDecl(tree.children[i]) if tree.children[i].IsEmpty() { tree.children[i] = nil diff --git a/internal/tlcodegen/type_rw_bool_php.go b/internal/tlcodegen/type_rw_bool_php.go index fec4208..d80155c 100644 --- a/internal/tlcodegen/type_rw_bool_php.go +++ b/internal/tlcodegen/type_rw_bool_php.go @@ -28,7 +28,7 @@ func (trw *TypeRWBool) PhpDefaultValue() string { func (trw *TypeRWBool) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { } -func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { return []string{ fmt.Sprintf( @@ -45,7 +45,7 @@ func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args []st return nil } -func (trw *TypeRWBool) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWBool) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { return []string{ fmt.Sprintf( diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index c8809da..06e5c39 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -39,7 +39,7 @@ func (trw *TypeRWMaybe) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrap trw.element.t.PhpIterateReachableTypes(reachableTypes) } -func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { result := []string{ fmt.Sprintf( @@ -74,7 +74,7 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args []s return nil } -func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { result := []string{ fmt.Sprintf( diff --git a/internal/tlcodegen/type_rw_primitive_php.go b/internal/tlcodegen/type_rw_primitive_php.go index 3ff35f8..7f1ef8b 100644 --- a/internal/tlcodegen/type_rw_primitive_php.go +++ b/internal/tlcodegen/type_rw_primitive_php.go @@ -58,7 +58,7 @@ func (trw *TypeRWPrimitive) phpIOMethodsSuffix() string { } } -func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { panic("can't be boxed") } @@ -70,7 +70,7 @@ func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args } } -func (trw *TypeRWPrimitive) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWPrimitive) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if !bare { panic("can't be boxed") } diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 1be6d64..2292c16 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -23,12 +23,28 @@ func (trw *TypeRWStruct) PHPFindNatByName(name string) (localNat bool, indexInDe panic(fmt.Sprintf("no such nat \"%s\"", name)) } -func (trw *TypeRWStruct) PHPGetFieldNatDependenciesValues(fieldIndex int) []string { +func (trw *TypeRWStruct) PHPGetFieldNatDependenciesValuesAsTypeTree(fieldIndex int, calculatedArgs *TypeArgumentsTree) TypeArgumentsTree { field := trw.Fields[fieldIndex] - argsValues := make([]string, 0) - currentType := field.t - trw.phpGetFieldArgs(currentType, &field.origTL.FieldType, &argsValues) - return argsValues + tree := TypeArgumentsTree{} + localTree := TypeArgumentsTree{} + + if calculatedArgs == nil { + trw.wr.PHPGetNatTypeDependenciesDecl(&tree) + tree.FillAllLeafs() + } else { + tree = *calculatedArgs + } + + genericsMap := make(map[string]*TypeArgumentsTree) + for _, child := range tree.children { + if child != nil { + genericsMap[child.name] = child + } + } + + field.t.PHPGetNatTypeDependenciesDecl(&localTree) + trw.phpGetFieldArgsTree(field.t, &field.origTL.FieldType, &localTree, &genericsMap) + return localTree } func (trw *TypeRWStruct) PHPGetFieldMask(fieldIndex int) string { @@ -43,38 +59,32 @@ func (trw *TypeRWStruct) PHPGetFieldMask(fieldIndex int) string { return "" } -func (trw *TypeRWStruct) phpGetFieldArgs(currentType *TypeRWWrapper, currentTypeRef *tlast.TypeRef, argsValues *[]string) { +func (trw *TypeRWStruct) phpGetFieldArgsTree(currentType *TypeRWWrapper, currentTypeRef *tlast.TypeRef, tree *TypeArgumentsTree, genericsToTrees *map[string]*TypeArgumentsTree) { if len(currentTypeRef.Args) != len(currentType.origTL[0].TemplateArguments) { generic := currentTypeRef.Type.String() - index := -1 - for i, arg := range trw.wr.origTL[0].TemplateArguments { - if arg.FieldName == generic { - index = i - break - } - } - var args TypeArgumentsTree - trw.wr.PHPGetNatTypeDependenciesDecl(&args) - for _, arg := range args.EnumerateSubTreeWithPrefixes(index) { - *argsValues = append(*argsValues, fmt.Sprintf("$%s", arg)) - } + tree.CloneValuesFrom((*genericsToTrees)[generic]) return } for i, _ := range currentType.origTL[0].TemplateArguments { actualArg := currentType.arguments[i] + actualArgRef := currentTypeRef.Args[i] if actualArg.isNat { if actualArg.isArith { - *argsValues = append(*argsValues, strconv.FormatUint(uint64(actualArg.Arith.Res), 10)) + value := strconv.FormatUint(uint64(actualArg.Arith.Res), 10) + (*tree).children[i].value = &value } else { - isLocal, index := trw.PHPFindNatByName(currentTypeRef.Args[i].T.String()) + isLocal, index := trw.PHPFindNatByName(actualArgRef.T.String()) if isLocal { - *argsValues = append(*argsValues, fmt.Sprintf("$this->%s", trw.Fields[index].originalName)) + value := fmt.Sprintf("$this->%s", trw.Fields[index].originalName) + (*tree).children[i].value = &value } else { - *argsValues = append(*argsValues, "$"+trw.wr.origTL[0].TemplateArguments[index].FieldName) + (*tree).children[i].CloneValuesFrom((*genericsToTrees)[trw.wr.origTL[0].TemplateArguments[index].FieldName]) } } } else { - trw.phpGetFieldArgs(actualArg.tip, ¤tTypeRef.Args[i].T, argsValues) + if tree != nil { + trw.phpGetFieldArgsTree(actualArg.tip, &actualArgRef.T, tree.children[i], genericsToTrees) + } } } return @@ -316,13 +326,13 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { natParamsComment := strings.Join( utils.MapSlice( trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), - func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + func(s string) string { return fmt.Sprintf("\n * @param int %s", s) }), "", ) natParamsDecl := strings.Join( utils.MapSlice( trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), - func(s string) string { return ", $" + s }), + func(s string) string { return ", " + s }), "", ) code.WriteString(fmt.Sprintf(` @@ -370,7 +380,23 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { ) shift += 1 } - fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) + if (trw.wr.goGlobalName == "TestData3TestData3PairIntInt" || + trw.wr.goGlobalName == "TestData4TestData4PairIntInt") && + field.originalName == "y" { + print("debug") + } + if trw.wr.goGlobalName == "PairIntBoxedTupleTupleInt47" && field.originalName == "b" { + localTree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) + fmt.Println(localTree) + print("debug") + } + if trw.wr.goGlobalName == "Left1VectorEitherStatBoxedBool" && + field.originalName == "name" { + print("debug") + } + + tree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) + fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, &tree) for _, line := range fieldRead { code.WriteString(textTab() + line + "\n") } @@ -400,13 +426,13 @@ func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { natParamsComment := strings.Join( utils.MapSlice( trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), - func(s string) string { return fmt.Sprintf("\n * @param int $%s", s) }), + func(s string) string { return fmt.Sprintf("\n * @param int %s", s) }), "", ) natParamsDecl := strings.Join( utils.MapSlice( trw.wr.PHPGetNatTypeDependenciesDeclAsArray(), - func(s string) string { return ", $" + s }), + func(s string) string { return ", " + s }), "", ) code.WriteString(fmt.Sprintf(` @@ -443,7 +469,8 @@ func (trw *TypeRWStruct) PHPStructWriteMethods(code *strings.Builder) { fieldMask := trw.PHPGetFieldMask(i) shift := 2 textTab := func() string { return strings.Repeat(tab, shift) } - fieldRead := field.t.trw.PhpWriteMethodCall("$this->"+field.originalName, field.bare, trw.PHPGetFieldNatDependenciesValues(i)) + tree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) + fieldRead := field.t.trw.PhpWriteMethodCall("$this->"+field.originalName, field.bare, &tree) if fieldRead == nil { continue } @@ -897,7 +924,7 @@ func (trw *TypeRWStruct) PhpConstructorNeedsUnion() (unionParent *TypeRWWrapper) return nil } -func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { return []string{fmt.Sprintf("$success = RPC_READ%s($stream, %s);", ifString(bare, "", "_boxed"), targetName)} } @@ -913,7 +940,11 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] "}", ) } - result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, args)...) + if trw.wr.goGlobalName == "TupleTuplePairIntInt" { + print("debug") + } + newArgs := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(0, args) + result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, &newArgs)...) return result } if trw.ResultType == nil && trw.wr.PHPIsTrueType() { @@ -953,14 +984,14 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args [] fmt.Sprintf("if (is_null(%[1]s)) {", 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)), + fmt.Sprintf("$success = %[2]s->read%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args.ListAllValues())), "if (!$success) {", " return false;", "}", } } -func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { return []string{fmt.Sprintf("$success = RPC_WRITE%s($stream, %s);", ifString(bare, "", "_boxed"), targetName)} } @@ -976,7 +1007,8 @@ func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args [ "}", ) } - result = append(result, trw.Fields[0].t.trw.PhpWriteMethodCall(targetName, trw.Fields[0].bare, args)...) + newArgs := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(0, args) + result = append(result, trw.Fields[0].t.trw.PhpWriteMethodCall(targetName, trw.Fields[0].bare, &newArgs)...) return result } if trw.ResultType == nil && trw.wr.PHPIsTrueType() { @@ -1015,7 +1047,7 @@ func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args [ fmt.Sprintf("if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), "}", - fmt.Sprintf("$success = %[2]s->write%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args)), + fmt.Sprintf("$success = %[2]s->write%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args.ListAllValues())), "if (!$success) {", " return false;", "}", diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index e301787..d560119 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -41,7 +41,7 @@ func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWW trw.element.t.PhpIterateReachableTypes(reachableTypes) } -func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { index := fmt.Sprintf("$i%d", len(trw.PhpClassName(false, true))) result := make([]string, 0) switch { @@ -71,9 +71,12 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args // tuple with size as last argument case !trw.vectorLike && !trw.dictLike: elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) - tupleSize := args[0] - elementArgs := args[1:] - elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, elementArgs) + tupleSize := *args.children[0].value + //elementArgs := args[1:] + if elementName == "$array_test_Data4__Pair__int__int___element" || elementName == "$array_test_Data3__Pair__int__int___element" { + print("debug") + } + elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, args.children[1]) for i := range elementRead { elementRead[i] = " " + elementRead[i] } @@ -121,7 +124,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args return []string{fmt.Sprintf("", trw.wr.goGlobalName)} } -func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { index := fmt.Sprintf("$i%d", len(trw.PhpClassName(false, true))) result := make([]string, 0) switch { @@ -150,8 +153,8 @@ func (trw *TypeRWBrackets) PhpWriteMethodCall(targetName string, bare bool, args return result // tuple with size as last argument case !trw.vectorLike && !trw.dictLike: - tupleSize := args[0] - elementArgs := args[1:] + tupleSize := *args.children[0].value + elementArgs := args.children[1] result = append(result, // TODO MAKE MORE EFFICIENT fmt.Sprintf("for(%[1]s = 0; %[1]s < %[2]s; %[1]s++) {", index, tupleSize), diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 86849e3..9a7bf26 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -120,7 +120,7 @@ func (trw *TypeRWUnion) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrap } } -func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if bare { panic("union can't be bare") } @@ -137,7 +137,7 @@ func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []s result = append(result, fmt.Sprintf(" case 0x%08[1]x:", curType.tlTag), fmt.Sprintf(" $variant = new %s();", curType.trw.PhpTypeName(true, true)), - fmt.Sprintf(" $success = $variant->read($stream%s);", phpFormatArgs(args)), + fmt.Sprintf(" $success = $variant->read($stream%s);", phpFormatArgs(args.ListAllValues())), " if (!$success) {", " return false;", " }", @@ -153,7 +153,7 @@ func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args []s return result } -func (trw *TypeRWUnion) PhpWriteMethodCall(targetName string, bare bool, args []string) []string { +func (trw *TypeRWUnion) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { if bare { panic("union can't be bare") } @@ -162,7 +162,7 @@ func (trw *TypeRWUnion) PhpWriteMethodCall(targetName string, bare bool, args [] fmt.Sprintf("if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), "}", - fmt.Sprintf("$success = %[1]s->write_boxed($stream%[2]s);", targetName, phpFormatArgs(args)), + fmt.Sprintf("$success = %[1]s->write_boxed($stream%[2]s);", targetName, phpFormatArgs(args.ListAllValues())), "if (!$success) {", " return false;", "}", From df10b53d246009f2b68b8533aa8abccbbfb5abbb Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 20 Jan 2025 13:25:53 +0300 Subject: [PATCH 23/37] removed debug --- internal/tlcodegen/tlgen_kernel.go | 5 ----- internal/tlcodegen/type_rw.go | 3 --- internal/tlcodegen/type_rw_struct_php.go | 18 ------------------ internal/tlcodegen/type_rw_tuple_php.go | 3 --- 4 files changed, 29 deletions(-) diff --git a/internal/tlcodegen/tlgen_kernel.go b/internal/tlcodegen/tlgen_kernel.go index 38f3a78..eb3da0c 100644 --- a/internal/tlcodegen/tlgen_kernel.go +++ b/internal/tlcodegen/tlgen_kernel.go @@ -204,11 +204,6 @@ func (gen *Gen2) getType(lrc LocalResolveContext, t tlast.TypeRef, unionParent * func (gen *Gen2) generateType(myWrapper *TypeRWWrapper) error { tlType := myWrapper.origTL - - if tlType[0].Construct.Name.String() == "test.dataIgnoreFlags" { - print("debug") - } - lrc := LocalResolveContext{ localTypeArgs: map[string]LocalTypeArg{}, localNatArgs: map[string]LocalNatArg{}, diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index dc64a90..7a9822c 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -768,9 +768,6 @@ func fillAllLeafsRecursive(t *TypeArgumentsTree, curIndex *int, values *[]string func (w *TypeRWWrapper) PHPGetNatTypeDependenciesDeclAsArray() []string { t := TypeArgumentsTree{} - if w.goGlobalName == "PairIntBoxedTupleTupleInt47" { - print("debug") - } w.PHPGetNatTypeDependenciesDecl(&t) return t.EnumerateWithPrefixes() } diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 2292c16..feb102c 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -380,21 +380,6 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { ) shift += 1 } - if (trw.wr.goGlobalName == "TestData3TestData3PairIntInt" || - trw.wr.goGlobalName == "TestData4TestData4PairIntInt") && - field.originalName == "y" { - print("debug") - } - if trw.wr.goGlobalName == "PairIntBoxedTupleTupleInt47" && field.originalName == "b" { - localTree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) - fmt.Println(localTree) - print("debug") - } - if trw.wr.goGlobalName == "Left1VectorEitherStatBoxedBool" && - field.originalName == "name" { - print("debug") - } - tree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, &tree) for _, line := range fieldRead { @@ -940,9 +925,6 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args *T "}", ) } - if trw.wr.goGlobalName == "TupleTuplePairIntInt" { - print("debug") - } newArgs := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(0, args) result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, &newArgs)...) return result diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index d560119..8f1cf2f 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -73,9 +73,6 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) tupleSize := *args.children[0].value //elementArgs := args[1:] - if elementName == "$array_test_Data4__Pair__int__int___element" || elementName == "$array_test_Data3__Pair__int__int___element" { - print("debug") - } elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, args.children[1]) for i := range elementRead { elementRead[i] = " " + elementRead[i] From 27848dd4359f8d89d0803bed6d4854452149fee9 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 20 Jan 2025 14:00:26 +0300 Subject: [PATCH 24/37] remove unnecessary inits --- ..._vrutoyTopLevelContainerWithDependency.php | 3 -- .../benchmarks_vrutoytopLevelUnionBig.php | 3 -- .../VK/TL/cases/Types/cases_replace7.php | 1 - .../VK/TL/cases/Types/cases_replace7plus.php | 1 - .../TL/cases/Types/cases_replace7plusplus.php | 1 - .../VK/TL/cases/Types/cases_testDictAny.php | 3 -- .../Types/cases_bytes_testDictAny.php | 3 -- internal/tlcodegen/tlgen_lang_php.go | 2 +- internal/tlcodegen/type_rw_bool_php.go | 2 +- internal/tlcodegen/type_rw_maybe_php.go | 7 +++-- internal/tlcodegen/type_rw_primitive_php.go | 2 +- internal/tlcodegen/type_rw_struct_php.go | 24 ++++++++++------ internal/tlcodegen/type_rw_tuple_php.go | 28 +++++++++++++------ internal/tlcodegen/type_rw_union_php.go | 2 +- 14 files changed, 42 insertions(+), 40 deletions(-) diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php index 41d6ac0..09a964f 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php @@ -54,9 +54,6 @@ public function read($stream) { $this->value = []; for($i28 = 0; $i28 < $this->n; $i28++) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - if (is_null($array_benchmarks_VruPosition___element)) { - $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - } $success = $array_benchmarks_VruPosition___element->read($stream); if (!$success) { return false; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php index 3d9101a..3e94f94 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php @@ -49,9 +49,6 @@ public function read($stream) { $this->next_positions = []; for($i28 = 0; $i28 < $vector_size; $i28++) { $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - if (is_null($array_benchmarks_VruPosition___element)) { - $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - } $success = $array_benchmarks_VruPosition___element->read($stream); if (!$success) { return false; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php index eb53a11..8b2554a 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php @@ -62,7 +62,6 @@ public function read($stream) { } $this->a = []; for($i15 = 0; $i15 < $this->n; $i15++) { - $array_array_int___element = []; $array_array_int___element = []; for($i9 = 0; $i9 < $this->m; $i9++) { $array_int___element = 0; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php index fef19a4..3f25d6f 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php @@ -64,7 +64,6 @@ public function read($stream) { if (($this->n & (1 << 0)) != 0) { $this->a = []; for($i15 = 0; $i15 < $this->n; $i15++) { - $array_array_int___element = []; $array_array_int___element = []; for($i9 = 0; $i9 < $this->m; $i9++) { $array_int___element = 0; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php index 2d06d84..f4adb3f 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php @@ -64,7 +64,6 @@ public function read($stream) { if (($this->N & (1 << 0)) != 0) { $this->A = []; for($i15 = 0; $i15 < $this->N; $i15++) { - $array_array_int___element = []; $array_array_int___element = []; for($i9 = 0; $i9 < $this->M; $i9++) { $array_int___element = 0; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php index 24ff3a4..85fbcbb 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php @@ -49,9 +49,6 @@ public function read($stream) { $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - if (is_null($array_DictionaryFieldAny__float__int___element)) { - $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - } $success = $array_DictionaryFieldAny__float__int___element->read($stream); if (!$success) { return false; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php index 36edf02..2b3cc62 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php @@ -49,9 +49,6 @@ public function read($stream) { $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - if (is_null($array_DictionaryFieldAny__float__int___element)) { - $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - } $success = $array_DictionaryFieldAny__float__int___element->read($stream); if (!$success) { return false; diff --git a/internal/tlcodegen/tlgen_lang_php.go b/internal/tlcodegen/tlgen_lang_php.go index 599b110..70de28d 100644 --- a/internal/tlcodegen/tlgen_lang_php.go +++ b/internal/tlcodegen/tlgen_lang_php.go @@ -23,7 +23,7 @@ type TypeRWPHPData interface { // PhpDefaultValue return default value for field of this type (can be null) PhpDefaultValue() string PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) - PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string + PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string } diff --git a/internal/tlcodegen/type_rw_bool_php.go b/internal/tlcodegen/type_rw_bool_php.go index d80155c..5a6da2b 100644 --- a/internal/tlcodegen/type_rw_bool_php.go +++ b/internal/tlcodegen/type_rw_bool_php.go @@ -28,7 +28,7 @@ func (trw *TypeRWBool) PhpDefaultValue() string { func (trw *TypeRWBool) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrapper]bool) { } -func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWBool) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { if !bare { return []string{ fmt.Sprintf( diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index 06e5c39..2d7dabb 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -39,7 +39,7 @@ func (trw *TypeRWMaybe) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrap trw.element.t.PhpIterateReachableTypes(reachableTypes) } -func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { if !bare { result := []string{ fmt.Sprintf( @@ -52,14 +52,15 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, args *Ty "}", "if ($maybeContainsValue) {", } - if trw.element.t == trw.getInnerTarget().t { + if trw.element.t == trw.getInnerTarget().t && initIfDefault { result = append(result, fmt.Sprintf(" if (is_null(%[1]s)) {", targetName), fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.element.t.trw.PhpDefaultInit()), " }", ) + initIfDefault = false } - bodyReader := trw.element.t.trw.PhpReadMethodCall(targetName, trw.element.bare, args) + bodyReader := trw.element.t.trw.PhpReadMethodCall(targetName, trw.element.bare, initIfDefault, args) for i, _ := range bodyReader { bodyReader[i] = " " + bodyReader[i] } diff --git a/internal/tlcodegen/type_rw_primitive_php.go b/internal/tlcodegen/type_rw_primitive_php.go index 7f1ef8b..23496d5 100644 --- a/internal/tlcodegen/type_rw_primitive_php.go +++ b/internal/tlcodegen/type_rw_primitive_php.go @@ -58,7 +58,7 @@ func (trw *TypeRWPrimitive) phpIOMethodsSuffix() string { } } -func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWPrimitive) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { if !bare { panic("can't be boxed") } diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index feb102c..d66f8a2 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -381,7 +381,7 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { shift += 1 } tree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) - fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, &tree) + fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, true, &tree) for _, line := range fieldRead { code.WriteString(textTab() + line + "\n") } @@ -909,7 +909,7 @@ func (trw *TypeRWStruct) PhpConstructorNeedsUnion() (unionParent *TypeRWWrapper) return nil } -func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { if specialCase := PHPSpecialMembersTypes(trw.wr); specialCase != "" { return []string{fmt.Sprintf("$success = RPC_READ%s($stream, %s);", ifString(bare, "", "_boxed"), targetName)} } @@ -926,7 +926,7 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args *T ) } newArgs := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(0, args) - result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, &newArgs)...) + result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, trw.Fields[0].bare, initIfDefault, &newArgs)...) return result } if trw.ResultType == nil && trw.wr.PHPIsTrueType() { @@ -958,19 +958,25 @@ func (trw *TypeRWStruct) PhpReadMethodCall(targetName string, bare bool, args *T "}", ) } - result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, bare, args)...) + result = append(result, trw.Fields[0].t.trw.PhpReadMethodCall(targetName, bare, initIfDefault, args)...) return result } } - return []string{ - fmt.Sprintf("if (is_null(%[1]s)) {", targetName), - fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), - "}", + result := make([]string, 0) + if initIfDefault { + result = append(result, + fmt.Sprintf("if (is_null(%[1]s)) {", targetName), + fmt.Sprintf(" %[1]s = %[2]s;", targetName, trw.PhpDefaultInit()), + "}", + ) + } + result = append(result, fmt.Sprintf("$success = %[2]s->read%[1]s($stream%[3]s);", ifString(bare, "", "_boxed"), targetName, phpFormatArgs(args.ListAllValues())), "if (!$success) {", " return false;", "}", - } + ) + return result } func (trw *TypeRWStruct) PhpWriteMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index 8f1cf2f..428471a 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -41,14 +41,14 @@ func (trw *TypeRWBrackets) PhpIterateReachableTypes(reachableTypes *map[*TypeRWW trw.element.t.PhpIterateReachableTypes(reachableTypes) } -func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { index := fmt.Sprintf("$i%d", len(trw.PhpClassName(false, true))) result := make([]string, 0) switch { // actual vector case trw.vectorLike && !trw.dictLike: elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) - elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, args) + elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, false, args) for i := range elementRead { elementRead[i] = " " + elementRead[i] } @@ -57,8 +57,14 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args "if (!$success) {", " return false;", "}", - // TODO MAKE MORE EFFICIENT - fmt.Sprintf("%[1]s = [];", targetName), + ) + if initIfDefault { + result = append(result, + // TODO MAKE MORE EFFICIENT + fmt.Sprintf("%[1]s = [];", targetName), + ) + } + result = append(result, fmt.Sprintf("for(%[1]s = 0; %[1]s < $vector_size; %[1]s++) {", index), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) @@ -73,13 +79,17 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) tupleSize := *args.children[0].value //elementArgs := args[1:] - elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, args.children[1]) + elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, false, args.children[1]) for i := range elementRead { elementRead[i] = " " + elementRead[i] } + if initIfDefault { + result = append(result, + // TODO MAKE MORE EFFICIENT + fmt.Sprintf("%[1]s = [];", targetName), + ) + } result = append(result, - // TODO MAKE MORE EFFICIENT - fmt.Sprintf("%[1]s = [];", targetName), fmt.Sprintf("for(%[1]s = 0; %[1]s < %[2]s; %[1]s++) {", index, tupleSize), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) @@ -93,11 +103,11 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, args case trw.dictLike: keyElement := fmt.Sprintf("$%s___key", trw.PhpClassName(false, true)) valueElement := fmt.Sprintf("$%s___value", trw.PhpClassName(false, true)) - keyRead := trw.dictKeyField.t.trw.PhpReadMethodCall(keyElement, trw.dictKeyField.bare, args) + keyRead := trw.dictKeyField.t.trw.PhpReadMethodCall(keyElement, trw.dictKeyField.bare, true, args) for i := range keyRead { keyRead[i] = " " + keyRead[i] } - valueRead := trw.dictValueField.t.trw.PhpReadMethodCall(valueElement, trw.dictValueField.bare, args) + valueRead := trw.dictValueField.t.trw.PhpReadMethodCall(valueElement, trw.dictValueField.bare, true, args) for i := range valueRead { valueRead[i] = " " + valueRead[i] } diff --git a/internal/tlcodegen/type_rw_union_php.go b/internal/tlcodegen/type_rw_union_php.go index 9a7bf26..358e904 100644 --- a/internal/tlcodegen/type_rw_union_php.go +++ b/internal/tlcodegen/type_rw_union_php.go @@ -120,7 +120,7 @@ func (trw *TypeRWUnion) PhpIterateReachableTypes(reachableTypes *map[*TypeRWWrap } } -func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, args *TypeArgumentsTree) []string { +func (trw *TypeRWUnion) PhpReadMethodCall(targetName string, bare bool, initIfDefault bool, args *TypeArgumentsTree) []string { if bare { panic("union can't be bare") } From 97a90bd7ba94bd80a18c62934e809aaf1e8642eb Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 20 Jan 2025 14:05:50 +0300 Subject: [PATCH 25/37] make names for array objects more short + add comments below them --- ..._vrutoyTopLevelContainerWithDependency.php | 7 ++-- .../benchmarks_vrutoytopLevelUnionBig.php | 7 ++-- .../VK/TL/cases/Types/cases_replace7.php | 12 +++--- .../VK/TL/cases/Types/cases_replace7plus.php | 12 +++--- .../TL/cases/Types/cases_replace7plusplus.php | 12 +++--- .../cases_testAllPossibleFieldConfigs.php | 42 +++++++++++-------- .../VK/TL/cases/Types/cases_testArray.php | 7 ++-- .../cases_testBeforeReadBitValidation.php | 14 ++++--- .../VK/TL/cases/Types/cases_testDictAny.php | 7 ++-- .../TL/cases/Types/cases_testOutFieldMask.php | 7 ++-- .../VK/TL/cases/Types/cases_testTuple.php | 7 ++-- .../VK/TL/cases/Types/cases_testVector.php | 7 ++-- .../Types/cases_bytes_testArray.php | 7 ++-- .../Types/cases_bytes_testDictAny.php | 7 ++-- .../Types/cases_bytes_testTuple.php | 7 ++-- .../Types/cases_bytes_testVector.php | 7 ++-- internal/tlcodegen/type_rw_tuple_php.go | 6 ++- 17 files changed, 101 insertions(+), 74 deletions(-) diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php index 09a964f..11e414c 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoyTopLevelContainerWithDependency.php @@ -53,12 +53,13 @@ public function read($stream) { } $this->value = []; for($i28 = 0; $i28 < $this->n; $i28++) { - $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - $success = $array_benchmarks_VruPosition___element->read($stream); + /** @var TL\benchmarks\Types\benchmarks_vruposition */ + $obj28 = new TL\benchmarks\Types\benchmarks_vruposition(); + $success = $obj28->read($stream); if (!$success) { return false; } - $this->value[] = $array_benchmarks_VruPosition___element; + $this->value[] = $obj28; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php index 3e94f94..83a09fc 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/benchmarks/Types/benchmarks_vrutoytopLevelUnionBig.php @@ -48,12 +48,13 @@ public function read($stream) { } $this->next_positions = []; for($i28 = 0; $i28 < $vector_size; $i28++) { - $array_benchmarks_VruPosition___element = new TL\benchmarks\Types\benchmarks_vruposition(); - $success = $array_benchmarks_VruPosition___element->read($stream); + /** @var TL\benchmarks\Types\benchmarks_vruposition */ + $obj28 = new TL\benchmarks\Types\benchmarks_vruposition(); + $success = $obj28->read($stream); if (!$success) { return false; } - $this->next_positions[] = $array_benchmarks_VruPosition___element; + $this->next_positions[] = $obj28; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php index 8b2554a..141f101 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7.php @@ -62,16 +62,18 @@ public function read($stream) { } $this->a = []; for($i15 = 0; $i15 < $this->n; $i15++) { - $array_array_int___element = []; + /** @var int[] */ + $obj15 = []; for($i9 = 0; $i9 < $this->m; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $array_array_int___element[] = $array_int___element; + $obj15[] = $obj9; } - $this->a[] = $array_array_int___element; + $this->a[] = $obj15; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php index 3f25d6f..d13a0b1 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plus.php @@ -64,16 +64,18 @@ public function read($stream) { if (($this->n & (1 << 0)) != 0) { $this->a = []; for($i15 = 0; $i15 < $this->n; $i15++) { - $array_array_int___element = []; + /** @var int[] */ + $obj15 = []; for($i9 = 0; $i9 < $this->m; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $array_array_int___element[] = $array_int___element; + $obj15[] = $obj9; } - $this->a[] = $array_array_int___element; + $this->a[] = $obj15; } } else { $this->a = null; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php index f4adb3f..d291135 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_replace7plusplus.php @@ -64,16 +64,18 @@ public function read($stream) { if (($this->N & (1 << 0)) != 0) { $this->A = []; for($i15 = 0; $i15 < $this->N; $i15++) { - $array_array_int___element = []; + /** @var int[] */ + $obj15 = []; for($i9 = 0; $i9 < $this->M; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $array_array_int___element[] = $array_int___element; + $obj15[] = $obj9; } - $this->A[] = $array_array_int___element; + $this->A[] = $obj15; } } else { $this->A = null; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php index 068ba17..fb5cf96 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testAllPossibleFieldConfigs.php @@ -123,21 +123,23 @@ public function read($stream, $outer) { $this->f01 = true; $this->f02 = []; for($i9 = 0; $i9 < $this->local; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f02[] = $array_int___element; + $this->f02[] = $obj9; } $this->f03 = []; for($i9 = 0; $i9 < $outer; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f03[] = $array_int___element; + $this->f03[] = $obj9; } if (($this->local & (1 << 0)) != 0) { [$this->f10, $success] = $stream->read_int32(); @@ -155,12 +157,13 @@ public function read($stream, $outer) { if (($this->local & (1 << 2)) != 0) { $this->f12 = []; for($i9 = 0; $i9 < $this->local; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f12[] = $array_int___element; + $this->f12[] = $obj9; } } else { $this->f12 = null; @@ -168,12 +171,13 @@ public function read($stream, $outer) { if (($this->local & (1 << 3)) != 0) { $this->f13 = []; for($i9 = 0; $i9 < $outer; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f13[] = $array_int___element; + $this->f13[] = $obj9; } } else { $this->f13 = null; @@ -194,12 +198,13 @@ public function read($stream, $outer) { if (($outer & (1 << 2)) != 0) { $this->f22 = []; for($i9 = 0; $i9 < $this->local; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f22[] = $array_int___element; + $this->f22[] = $obj9; } } else { $this->f22 = null; @@ -207,12 +212,13 @@ public function read($stream, $outer) { if (($outer & (1 << 3)) != 0) { $this->f23 = []; for($i9 = 0; $i9 < $outer; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f23[] = $array_int___element; + $this->f23[] = $obj9; } } else { $this->f23 = null; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php index dc6add0..d73334b 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testArray.php @@ -53,12 +53,13 @@ public function read($stream) { } $this->arr = []; for($i9 = 0; $i9 < $this->n; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->arr[] = $array_int___element; + $this->arr[] = $obj9; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php index e6a7af1..8e760a3 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testBeforeReadBitValidation.php @@ -61,12 +61,13 @@ public function read($stream) { if (($this->n & (1 << 0)) != 0) { $this->a = []; for($i9 = 0; $i9 < $this->n; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->a[] = $array_int___element; + $this->a[] = $obj9; } } else { $this->a = null; @@ -74,12 +75,13 @@ public function read($stream) { if (($this->n & (1 << 1)) != 0) { $this->b = []; for($i9 = 0; $i9 < $this->n; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->b[] = $array_int___element; + $this->b[] = $obj9; } } else { $this->b = null; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php index 85fbcbb..a9d5db3 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testDictAny.php @@ -48,12 +48,13 @@ public function read($stream) { } $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { - $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - $success = $array_DictionaryFieldAny__float__int___element->read($stream); + /** @var TL\_common\Types\dictionaryFieldAny__float__int */ + $obj36 = new TL\_common\Types\dictionaryFieldAny__float__int(); + $success = $obj36->read($stream); if (!$success) { return false; } - $this->dict[] = $array_DictionaryFieldAny__float__int___element; + $this->dict[] = $obj36; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php index e4f5cbc..c557110 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testOutFieldMask.php @@ -71,12 +71,13 @@ public function read($stream, $f) { } $this->f3 = []; for($i9 = 0; $i9 < $f; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->f3[] = $array_int___element; + $this->f3[] = $obj9; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php index 3752b2f..3bad371 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testTuple.php @@ -44,12 +44,13 @@ public function read_boxed($stream) { public function read($stream) { $this->tpl = []; for($i9 = 0; $i9 < 4; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->tpl[] = $array_int___element; + $this->tpl[] = $obj9; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php index 55fea5d..d3a8e33 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases/Types/cases_testVector.php @@ -48,12 +48,13 @@ public function read($stream) { } $this->arr = []; for($i9 = 0; $i9 < $vector_size; $i9++) { - $array_int___element = 0; - [$array_int___element, $success] = $stream->read_int32(); + /** @var int */ + $obj9 = 0; + [$obj9, $success] = $stream->read_int32(); if (!$success) { return false; } - $this->arr[] = $array_int___element; + $this->arr[] = $obj9; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testArray.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testArray.php index 0965d5f..753cc60 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testArray.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testArray.php @@ -53,12 +53,13 @@ public function read($stream) { } $this->arr = []; for($i12 = 0; $i12 < $this->n; $i12++) { - $array_string___element = ''; - [$array_string___element, $success] = $stream->read_string(); + /** @var string */ + $obj12 = ''; + [$obj12, $success] = $stream->read_string(); if (!$success) { return false; } - $this->arr[] = $array_string___element; + $this->arr[] = $obj12; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php index 2b3cc62..24f7f71 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testDictAny.php @@ -48,12 +48,13 @@ public function read($stream) { } $this->dict = []; for($i36 = 0; $i36 < $vector_size; $i36++) { - $array_DictionaryFieldAny__float__int___element = new TL\_common\Types\dictionaryFieldAny__float__int(); - $success = $array_DictionaryFieldAny__float__int___element->read($stream); + /** @var TL\_common\Types\dictionaryFieldAny__float__int */ + $obj36 = new TL\_common\Types\dictionaryFieldAny__float__int(); + $success = $obj36->read($stream); if (!$success) { return false; } - $this->dict[] = $array_DictionaryFieldAny__float__int___element; + $this->dict[] = $obj36; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php index fb927d0..02e545e 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testTuple.php @@ -44,12 +44,13 @@ public function read_boxed($stream) { public function read($stream) { $this->tpl = []; for($i12 = 0; $i12 < 4; $i12++) { - $array_string___element = ''; - [$array_string___element, $success] = $stream->read_string(); + /** @var string */ + $obj12 = ''; + [$obj12, $success] = $stream->read_string(); if (!$success) { return false; } - $this->tpl[] = $array_string___element; + $this->tpl[] = $obj12; } return true; } diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php index 73f7c7c..6dba077 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/cases_bytes/Types/cases_bytes_testVector.php @@ -48,12 +48,13 @@ public function read($stream) { } $this->arr = []; for($i12 = 0; $i12 < $vector_size; $i12++) { - $array_string___element = ''; - [$array_string___element, $success] = $stream->read_string(); + /** @var string */ + $obj12 = ''; + [$obj12, $success] = $stream->read_string(); if (!$success) { return false; } - $this->arr[] = $array_string___element; + $this->arr[] = $obj12; } return true; } diff --git a/internal/tlcodegen/type_rw_tuple_php.go b/internal/tlcodegen/type_rw_tuple_php.go index 428471a..d76ed96 100644 --- a/internal/tlcodegen/type_rw_tuple_php.go +++ b/internal/tlcodegen/type_rw_tuple_php.go @@ -47,7 +47,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, initI switch { // actual vector case trw.vectorLike && !trw.dictLike: - elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) + elementName := fmt.Sprintf("$obj%d", len(trw.PhpClassName(false, true))) elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, false, args) for i := range elementRead { elementRead[i] = " " + elementRead[i] @@ -66,6 +66,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, initI } result = append(result, fmt.Sprintf("for(%[1]s = 0; %[1]s < $vector_size; %[1]s++) {", index), + fmt.Sprintf(" /** @var %[1]s */", trw.element.t.trw.PhpTypeName(true, true)), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) result = append(result, elementRead...) @@ -76,7 +77,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, initI return result // tuple with size as last argument case !trw.vectorLike && !trw.dictLike: - elementName := fmt.Sprintf("$%s___element", trw.PhpClassName(false, true)) + elementName := fmt.Sprintf("$obj%d", len(trw.PhpClassName(false, true))) tupleSize := *args.children[0].value //elementArgs := args[1:] elementRead := trw.element.t.trw.PhpReadMethodCall(elementName, trw.element.bare, false, args.children[1]) @@ -91,6 +92,7 @@ func (trw *TypeRWBrackets) PhpReadMethodCall(targetName string, bare bool, initI } result = append(result, fmt.Sprintf("for(%[1]s = 0; %[1]s < %[2]s; %[1]s++) {", index, tupleSize), + fmt.Sprintf(" /** @var %[1]s */", trw.element.t.trw.PhpTypeName(true, true)), fmt.Sprintf(" %[2]s = %[1]s;", trw.element.t.trw.PhpDefaultInit(), elementName), ) result = append(result, elementRead...) From a0004958869b7915ed0cd09966140469eb915614 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Mon, 20 Jan 2025 16:04:16 +0300 Subject: [PATCH 26/37] fix colors in tests --- internal/tlcodegen/test/codegen_test/php/test_basictl.php | 6 +++--- internal/tlcodegen/test/codegen_test/php/test_cases.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/php/test_basictl.php b/internal/tlcodegen/test/codegen_test/php/test_basictl.php index c7d3280..1077a93 100644 --- a/internal/tlcodegen/test/codegen_test/php/test_basictl.php +++ b/internal/tlcodegen/test/codegen_test/php/test_basictl.php @@ -124,18 +124,18 @@ function bool_to_string(bool $x): string foreach ($tests as $test_name => $test) { $test_result = $test->test_read_write_interaction(); -// println("Test \"" . $test_name . "\": " . bool_to_string($test_result)); if (!$test_result) { $failed_tests[] = $test_name; } } if (count($failed_tests) == 0) { - printf("\033[01;32mAll tests are passed!\033[0m\n"); + printf("\n\033[01;32mAll tests are passed!\033[0m\n\n"); } else { - printf("Failed %d tests:\n", count($failed_tests)); + printf("\n\033[01;31mFailed %d tests:\033[01;0m\n", count($failed_tests)); foreach ($failed_tests as $failed_test) { printf("\t%s\n", $failed_test); } + printf("\n"); } ?> \ No newline at end of file diff --git a/internal/tlcodegen/test/codegen_test/php/test_cases.php b/internal/tlcodegen/test/codegen_test/php/test_cases.php index e3ec5c5..030985d 100644 --- a/internal/tlcodegen/test/codegen_test/php/test_cases.php +++ b/internal/tlcodegen/test/codegen_test/php/test_cases.php @@ -87,4 +87,4 @@ function string_to_hex(string $data): string { } } -printf("\n\033[01;32mAll tests are passed!\033[01;0m\n"); \ No newline at end of file +printf("\n\033[01;32mAll tests are passed!\033[01;0m\n\n"); \ No newline at end of file From 4d183e2154fd42b14cab329b72bc93a4fac21dfd Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 14:51:47 +0300 Subject: [PATCH 27/37] sort json --- .../codegen_test/data/test-objects-bytes.json | 596 +++++++++--------- 1 file changed, 298 insertions(+), 298 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json index 07cbcd1..492a32d 100644 --- a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json @@ -1,300 +1,300 @@ { - "Tests": { - "TestDictionaryInt": { - "TestingType": "cases.testDictInt", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000002 00000001 00000001 00000002 00000002" - } - ] - }, - "TestDictionaryAny": { - "TestingType": "cases.testDictAny", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000002 00000000 3ff00000 00000001 cccccccd 4000cccc 00000002" - } - ] - }, - "TestEnum": { - "TestingType": "cases.testEnumContainer", - "Successes": [ - { - "Bytes": "6c6c55ac" - }, - { - "Bytes": "86ea88ce" - } - ] - }, - "TestLocalFieldMaskRecursive": { - "TestingType": "cases.testRecursiveFieldMask", - "Successes": [ - { - "Bytes": "00000001 00000002 00000004" - }, - { - "Bytes": "00000001 00000002 00000000" - }, - { - "Bytes": "00000000" - }, - { - "Bytes": "0000000f 00000000" - }, - { - "Bytes": "00000001 0000000f 00000000" - }, - { - "Bytes": "0000001f 00000002 0000000f" - }, - { - "Bytes": "00000001 0000001f 0000000f" - }, - { - "Bytes": "00000019 0000001f 0000000f" - } - ] - }, - "TestBeforeReadBitValidation": { - "TestingType": "cases.testBeforeReadBitValidation", - "Successes": [ - { - "Bytes": "00000003 00000001 00000001 00000001 00000001 00000001 00000001" - } - ] - }, - "TestReadWithDifferentNatDependencies": { - "TestingType": "cases.testAllPossibleFieldConfigsContainer", - "Successes": [ - { - "Bytes": "00000000 00000000 000000ef" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000001 00000000 00000001 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000001 00000000 00000000 00000001 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000001 00000000 00000001 000000ef" - }, - { - "Bytes": "00000000 00000001 00000000 00000001 000000ef" - }, - { - "Bytes": "00000000 00000001 00000000 00000001 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000002 00000000 00000002 00000002" - }, - { - "Bytes": "00000000 00000003 00000000 00000003 00000003 00000003 00000000" - }, - { - "Bytes": "00000000 00000001 00000000 00000001 00000000" - }, - { - "Bytes": "00000000 00000002 00000000 00000002 00000002" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000004 00000000 00000004 00000004 00000004 00000004 00000004 00000004 00000004 00000004" - }, - { - "Bytes": "00000000 00000002 00000000 00000002 00000002" - }, - { - "Bytes": "00000001 00000008 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000001 00000001 00000000" - }, - { - "Bytes": "00000000 00000002 00000000 00000002 00000002" - }, - { - "Bytes": "00000001 00000000 00000000 00000001 000000ef" - }, - { - "Bytes": "00000001 00000000 00000000 00000001 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000000 00000000 00000000" - }, - { - "Bytes": "00000004 00000002 00000000 00000002 00000002 00000004 00000004 00000004 00000004 00000002 00000002" - }, - { - "Bytes": "00000004 00000000 00000000 00000004 00000004 00000004 00000004" - }, - { - "Bytes": "00000000 00000002 00000000 00000002 00000002" - }, - { - "Bytes": "00000008 00000000 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008" - }, - { - "Bytes": "00000000 00000000 00000000" - } - ] - }, - "TestDictionaryString": { - "TestingType": "cases.testDictString", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000002 00316b02 00000001 00326b02 00000002" - } - ] - }, - "TestOuterFieldMask": { - "TestingType": "cases.testOutFieldMaskContainer", - "Successes": [ - { - "Bytes": "00000001 00000001 00000001" - }, - { - "Bytes": "00000000" - }, - { - "Bytes": "00000001 00000000 00000001" - } - ] - }, - "TestVector": { - "TestingType": "cases.testVector", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000003 00000001 00000002 00000003" - } - ] - }, - "TestTuple": { - "TestingType": "cases.testTuple", - "Successes": [ - { - "Bytes": "00000001 00000002 00000003 00000004" - } - ] - }, - "TestLocalFieldMask": { - "TestingType": "cases.testLocalFieldmask", - "Successes": [ - { - "Bytes": "00000003 00000002" - }, - { - "Bytes": "00000002" - }, - { - "Bytes": "00000001 00000002" - }, - { - "Bytes": "00000001 00000000" - } - ] - }, - "TestReadOrder": { - "TestingType": "cases.replace7", - "Successes": [ - { - "Bytes": "00000001 00000002 00000001 00000002" - } - ] - }, - "TestArray": { - "TestingType": "cases.testArray", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000003 00000001 00000002 00000003" - } - ] - }, - "TestMaybe": { - "TestingType": "cases.testMaybe", - "Successes": [ - { - "Bytes": "27930a7b" - }, - { - "Bytes": "3f9c8ef8 00000000" - }, - { - "Bytes": "3f9c8ef8 00000001" - } - ] - }, - "TestUnion": { - "TestingType": "cases.testUnionContainer", - "Successes": [ - { - "Bytes": "4b4f09b1 00000001" - }, - { - "Bytes": "464f96c4 00003201" - }, - { - "Bytes": "4b4f09b1 00000000" - } - ] - }, - "TestRecursiveTypes": { - "TestingType": "cases.myCycle2", - "Successes": [ - { - "Bytes": "00000000" - }, - { - "Bytes": "00000001 00000000" - }, - { - "Bytes": "00000001 00000001 00000000" - }, - { - "Bytes": "00000001 00000001 00000001 00000002" - }, - { - "Bytes": "00000001 00000001 00000001 00000000" - } - ] - } - } + "Tests": { + "TestArray": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000003 00000001 00000002 00000003" + } + ], + "TestingType": "cases.testArray" + }, + "TestBeforeReadBitValidation": { + "Successes": [ + { + "Bytes": "00000003 00000001 00000001 00000001 00000001 00000001 00000001" + } + ], + "TestingType": "cases.testBeforeReadBitValidation" + }, + "TestDictionaryAny": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000002 00000000 3ff00000 00000001 cccccccd 4000cccc 00000002" + } + ], + "TestingType": "cases.testDictAny" + }, + "TestDictionaryInt": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000002 00000001 00000001 00000002 00000002" + } + ], + "TestingType": "cases.testDictInt" + }, + "TestDictionaryString": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000002 00316b02 00000001 00326b02 00000002" + } + ], + "TestingType": "cases.testDictString" + }, + "TestEnum": { + "Successes": [ + { + "Bytes": "6c6c55ac" + }, + { + "Bytes": "86ea88ce" + } + ], + "TestingType": "cases.testEnumContainer" + }, + "TestLocalFieldMask": { + "Successes": [ + { + "Bytes": "00000003 00000002" + }, + { + "Bytes": "00000002" + }, + { + "Bytes": "00000001 00000002" + }, + { + "Bytes": "00000001 00000000" + } + ], + "TestingType": "cases.testLocalFieldmask" + }, + "TestLocalFieldMaskRecursive": { + "Successes": [ + { + "Bytes": "00000001 00000002 00000004" + }, + { + "Bytes": "00000001 00000002 00000000" + }, + { + "Bytes": "00000000" + }, + { + "Bytes": "0000000f 00000000" + }, + { + "Bytes": "00000001 0000000f 00000000" + }, + { + "Bytes": "0000001f 00000002 0000000f" + }, + { + "Bytes": "00000001 0000001f 0000000f" + }, + { + "Bytes": "00000019 0000001f 0000000f" + } + ], + "TestingType": "cases.testRecursiveFieldMask" + }, + "TestMaybe": { + "Successes": [ + { + "Bytes": "27930a7b" + }, + { + "Bytes": "3f9c8ef8 00000000" + }, + { + "Bytes": "3f9c8ef8 00000001" + } + ], + "TestingType": "cases.testMaybe" + }, + "TestOuterFieldMask": { + "Successes": [ + { + "Bytes": "00000001 00000001 00000001" + }, + { + "Bytes": "00000000" + }, + { + "Bytes": "00000001 00000000 00000001" + } + ], + "TestingType": "cases.testOutFieldMaskContainer" + }, + "TestReadOrder": { + "Successes": [ + { + "Bytes": "00000001 00000002 00000001 00000002" + } + ], + "TestingType": "cases.replace7" + }, + "TestReadWithDifferentNatDependencies": { + "Successes": [ + { + "Bytes": "00000000 00000000 000000ef" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000001 00000000 00000001 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000001 00000000 00000000 00000001 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000001 00000000 00000001 000000ef" + }, + { + "Bytes": "00000000 00000001 00000000 00000001 000000ef" + }, + { + "Bytes": "00000000 00000001 00000000 00000001 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000002 00000000 00000002 00000002" + }, + { + "Bytes": "00000000 00000003 00000000 00000003 00000003 00000003 00000000" + }, + { + "Bytes": "00000000 00000001 00000000 00000001 00000000" + }, + { + "Bytes": "00000000 00000002 00000000 00000002 00000002" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000004 00000000 00000004 00000004 00000004 00000004 00000004 00000004 00000004 00000004" + }, + { + "Bytes": "00000000 00000002 00000000 00000002 00000002" + }, + { + "Bytes": "00000001 00000008 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000001 00000001 00000000" + }, + { + "Bytes": "00000000 00000002 00000000 00000002 00000002" + }, + { + "Bytes": "00000001 00000000 00000000 00000001 000000ef" + }, + { + "Bytes": "00000001 00000000 00000000 00000001 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000000 00000000 00000000" + }, + { + "Bytes": "00000004 00000002 00000000 00000002 00000002 00000004 00000004 00000004 00000004 00000002 00000002" + }, + { + "Bytes": "00000004 00000000 00000000 00000004 00000004 00000004 00000004" + }, + { + "Bytes": "00000000 00000002 00000000 00000002 00000002" + }, + { + "Bytes": "00000008 00000000 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008" + }, + { + "Bytes": "00000000 00000000 00000000" + } + ], + "TestingType": "cases.testAllPossibleFieldConfigsContainer" + }, + "TestRecursiveTypes": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000001 00000000" + }, + { + "Bytes": "00000001 00000001 00000000" + }, + { + "Bytes": "00000001 00000001 00000001 00000002" + }, + { + "Bytes": "00000001 00000001 00000001 00000000" + } + ], + "TestingType": "cases.myCycle2" + }, + "TestTuple": { + "Successes": [ + { + "Bytes": "00000001 00000002 00000003 00000004" + } + ], + "TestingType": "cases.testTuple" + }, + "TestUnion": { + "Successes": [ + { + "Bytes": "4b4f09b1 00000001" + }, + { + "Bytes": "464f96c4 00003201" + }, + { + "Bytes": "4b4f09b1 00000000" + } + ], + "TestingType": "cases.testUnionContainer" + }, + "TestVector": { + "Successes": [ + { + "Bytes": "00000000" + }, + { + "Bytes": "00000003 00000001 00000002 00000003" + } + ], + "TestingType": "cases.testVector" + } + } } \ No newline at end of file From 9647fa3b70d8969f2d1dab6be70a01e87bb2dea9 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 14:54:33 +0300 Subject: [PATCH 28/37] change order --- .../codegen_test/data/test-objects-bytes.json | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json index 492a32d..12127f0 100644 --- a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json @@ -1,6 +1,7 @@ { "Tests": { "TestArray": { + "TestingType": "cases.testArray", "Successes": [ { "Bytes": "00000000" @@ -8,18 +9,18 @@ { "Bytes": "00000003 00000001 00000002 00000003" } - ], - "TestingType": "cases.testArray" + ] }, "TestBeforeReadBitValidation": { + "TestingType": "cases.testBeforeReadBitValidation", "Successes": [ { "Bytes": "00000003 00000001 00000001 00000001 00000001 00000001 00000001" } - ], - "TestingType": "cases.testBeforeReadBitValidation" + ] }, "TestDictionaryAny": { + "TestingType": "cases.testDictAny", "Successes": [ { "Bytes": "00000000" @@ -27,10 +28,10 @@ { "Bytes": "00000002 00000000 3ff00000 00000001 cccccccd 4000cccc 00000002" } - ], - "TestingType": "cases.testDictAny" + ] }, "TestDictionaryInt": { + "TestingType": "cases.testDictInt", "Successes": [ { "Bytes": "00000000" @@ -38,10 +39,10 @@ { "Bytes": "00000002 00000001 00000001 00000002 00000002" } - ], - "TestingType": "cases.testDictInt" + ] }, "TestDictionaryString": { + "TestingType": "cases.testDictString", "Successes": [ { "Bytes": "00000000" @@ -49,10 +50,10 @@ { "Bytes": "00000002 00316b02 00000001 00326b02 00000002" } - ], - "TestingType": "cases.testDictString" + ] }, "TestEnum": { + "TestingType": "cases.testEnumContainer", "Successes": [ { "Bytes": "6c6c55ac" @@ -60,10 +61,10 @@ { "Bytes": "86ea88ce" } - ], - "TestingType": "cases.testEnumContainer" + ] }, "TestLocalFieldMask": { + "TestingType": "cases.testLocalFieldmask", "Successes": [ { "Bytes": "00000003 00000002" @@ -77,10 +78,10 @@ { "Bytes": "00000001 00000000" } - ], - "TestingType": "cases.testLocalFieldmask" + ] }, "TestLocalFieldMaskRecursive": { + "TestingType": "cases.testRecursiveFieldMask", "Successes": [ { "Bytes": "00000001 00000002 00000004" @@ -106,10 +107,10 @@ { "Bytes": "00000019 0000001f 0000000f" } - ], - "TestingType": "cases.testRecursiveFieldMask" + ] }, "TestMaybe": { + "TestingType": "cases.testMaybe", "Successes": [ { "Bytes": "27930a7b" @@ -120,10 +121,10 @@ { "Bytes": "3f9c8ef8 00000001" } - ], - "TestingType": "cases.testMaybe" + ] }, "TestOuterFieldMask": { + "TestingType": "cases.testOutFieldMaskContainer", "Successes": [ { "Bytes": "00000001 00000001 00000001" @@ -134,18 +135,18 @@ { "Bytes": "00000001 00000000 00000001" } - ], - "TestingType": "cases.testOutFieldMaskContainer" + ] }, "TestReadOrder": { + "TestingType": "cases.replace7", "Successes": [ { "Bytes": "00000001 00000002 00000001 00000002" } - ], - "TestingType": "cases.replace7" + ] }, "TestReadWithDifferentNatDependencies": { + "TestingType": "cases.testAllPossibleFieldConfigsContainer", "Successes": [ { "Bytes": "00000000 00000000 000000ef" @@ -240,10 +241,10 @@ { "Bytes": "00000000 00000000 00000000" } - ], - "TestingType": "cases.testAllPossibleFieldConfigsContainer" + ] }, "TestRecursiveTypes": { + "TestingType": "cases.myCycle2", "Successes": [ { "Bytes": "00000000" @@ -260,18 +261,18 @@ { "Bytes": "00000001 00000001 00000001 00000000" } - ], - "TestingType": "cases.myCycle2" + ] }, "TestTuple": { + "TestingType": "cases.testTuple", "Successes": [ { "Bytes": "00000001 00000002 00000003 00000004" } - ], - "TestingType": "cases.testTuple" + ] }, "TestUnion": { + "TestingType": "cases.testUnionContainer", "Successes": [ { "Bytes": "4b4f09b1 00000001" @@ -282,10 +283,10 @@ { "Bytes": "4b4f09b1 00000000" } - ], - "TestingType": "cases.testUnionContainer" + ] }, "TestVector": { + "TestingType": "cases.testVector", "Successes": [ { "Bytes": "00000000" @@ -293,8 +294,7 @@ { "Bytes": "00000003 00000001 00000002 00000003" } - ], - "TestingType": "cases.testVector" + ] } } } \ No newline at end of file From 9d10447c510c16add7614bae7bde7bea2ed9ca80 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 15:45:58 +0300 Subject: [PATCH 29/37] add system to add new tests for cases --- .../codegen_test/casetests/bytes_read_test.go | 127 ++++++++++++++++-- .../codegen_test/data/test-objects-bytes.json | 3 + 2 files changed, 121 insertions(+), 9 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go index a5c9dff..b12e050 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go +++ b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go @@ -9,6 +9,7 @@ package casetests import ( "encoding/json" "fmt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/tlcases" "github.com/vkcom/tl/internal/utils" "math/rand" "os" @@ -151,20 +152,71 @@ func TestAllTLObjectsReadJsonByRandomBytes(t *testing.T) { } } -func TestGeneralCasesBytes(t *testing.T) { - const PathToJsonData = "../data/test-objects-bytes.json" - data, readErr := os.ReadFile(PathToJsonData) +const PathToBytesData = "../data/test-objects-bytes.json" - if readErr != nil { - t.Fatalf("testing data is not provided") +func TestAppendNewCasesForTesting(t *testing.T) { + tests, success := initTestData(t) + if !success { return } - tests := allTestsBytes{map[string]mappingTestSamplesBytes{}} - err := json.Unmarshal(data, &tests) + type Sample struct { + sample meta.Object + testName string + } - if err != nil { - t.Fatalf("can't unmarshall test data") + // write your samples here + newSamples := []Sample{ + {testName: "TestReadOrder", sample: &tlcases.Replace7{N: 2, M: 1, A: [][]int32{[]int32{2}, []int32{1}}}}, + } + + newSamplesCount := 0 + + for i, sample := range newSamples { + success, err := addSample(&tests, sample.testName, sample.sample) + if success { + newSamplesCount += 1 + } else if err != nil { + t.Fatalf("Incorrent test sample #%[1]d for \"%[2]s\" was provided", i, sample.sample.TLName()) + return + } + } + + fmt.Println("") + + if newSamplesCount != 0 { + bytes, err := json.MarshalIndent(&tests, "", "\t") + + if err != nil { + t.Fatalf("can't marshal new values") + return + } + + file, err := os.Create(PathToBytesData) + + if err != nil { + t.Fatalf("can't open file with test cases") + return + } + defer file.Close() + + _, err = file.Write(bytes) + if err != nil { + t.Fatalf("can't overwrite file with test cases") + return + } + + fmt.Printf("To \"%s\" were added %d test cases\n", PathToBytesData, newSamplesCount) + } else { + fmt.Printf("Nothing to add to \"%s\"\n", PathToBytesData) + } + + fmt.Println("") +} + +func TestGeneralCasesBytes(t *testing.T) { + tests, success := initTestData(t) + if !success { return } @@ -182,3 +234,60 @@ func TestGeneralCasesBytes(t *testing.T) { }) } } + +func checkExistenceOfTest(tests *allTestsBytes, testName, typeName, bytesHex string) (testCanBeAdded bool, testExists bool, testNameToAdd string) { + for testNameValue, test := range tests.Tests { + // testName exists, but it is not for this type then return false + if testNameValue == testName { + if test.TestingType != typeName { + return false, false, "" + } + } else { + // testName different, but maybe it is for same type + if test.TestingType != typeName { + continue + } + } + + for _, success := range test.Successes { + if success.Bytes == bytesHex { + return true, true, testNameValue + } + } + } + return true, false, testName +} + +func addSample(tests *allTestsBytes, testName string, sample meta.Object) (bool, error) { + bytes, err := sample.WriteGeneral(nil) + if err != nil { + return false, err + } + hexBytes := utils.SprintHexDump(bytes) + canAdd, exists, placeToAdd := checkExistenceOfTest(tests, testName, sample.TLName(), hexBytes) + if canAdd && !exists { + successes := tests.Tests[placeToAdd] + successes.Successes = append(successes.Successes, MappingSuccessBytes{Bytes: hexBytes}) + tests.Tests[placeToAdd] = successes + return true, nil + } + return false, nil +} + +func initTestData(t *testing.T) (_ allTestsBytes, success bool) { + data, readErr := os.ReadFile(PathToBytesData) + + if readErr != nil { + t.Fatalf("testing data is not provided") + return allTestsBytes{}, false + } + + tests := allTestsBytes{map[string]mappingTestSamplesBytes{}} + err := json.Unmarshal(data, &tests) + + if err != nil { + t.Fatalf("can't unmarshall test data") + return allTestsBytes{}, false + } + return tests, true +} diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json index 12127f0..1c7ff38 100644 --- a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json @@ -142,6 +142,9 @@ "Successes": [ { "Bytes": "00000001 00000002 00000001 00000002" + }, + { + "Bytes": "00000002 00000001 00000002 00000001" } ] }, From 36ca8f56350dde6e5984e4adf9bf5a3bfe290387 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 15:48:47 +0300 Subject: [PATCH 30/37] fix in arguments for php --- internal/tlcodegen/type_rw_struct_php.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index d66f8a2..666aa46 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -70,8 +70,14 @@ func (trw *TypeRWStruct) phpGetFieldArgsTree(currentType *TypeRWWrapper, current actualArgRef := currentTypeRef.Args[i] if actualArg.isNat { if actualArg.isArith { - value := strconv.FormatUint(uint64(actualArg.Arith.Res), 10) - (*tree).children[i].value = &value + if actualArgRef.IsArith { + value := strconv.FormatUint(uint64(actualArg.Arith.Res), 10) + (*tree).children[i].value = &value + } else { + // argument resolving to constant by in definition it is outer nat + _, index := trw.PHPFindNatByName(actualArgRef.T.String()) + (*tree).children[i].CloneValuesFrom((*genericsToTrees)[trw.wr.origTL[0].TemplateArguments[index].FieldName]) + } } else { isLocal, index := trw.PHPFindNatByName(actualArgRef.T.String()) if isLocal { @@ -380,6 +386,10 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) { ) shift += 1 } + if trw.PhpClassName(false, true) == "test_dataIgnoreFlags__test_DataIgnoreFlags__test_DataIgnoreFlags__int" && + field.originalName == "t" { + print("debug") + } tree := trw.PHPGetFieldNatDependenciesValuesAsTypeTree(i, nil) fieldRead := field.t.trw.PhpReadMethodCall("$this->"+field.originalName, field.bare, true, &tree) for _, line := range fieldRead { From c8b8b2b82efae316936f9dddd9041059c716c7b5 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 16:37:14 +0300 Subject: [PATCH 31/37] add new tests --- .../codegen_test/casetests/bytes_read_test.go | 126 +++++++++++++++++- .../codegen_test/data/test-objects-bytes.json | 16 +++ .../test/gen/cases/constants/constants.go | 6 + .../test/gen/cases/factory/factory.go | 4 + .../gen/cases/factory_bytes/factory_bytes.go | 4 + .../tlcodegen/test/gen/cases/meta/meta.go | 2 + internal/tlcodegen/test/gen/cases/tl/tl.go | 78 ++++++----- .../test/gen/cases/tlcases/tlcases.go | 16 +++ internal/tlcodegen/test/tls/cases.tl | 10 ++ 9 files changed, 226 insertions(+), 36 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go index b12e050..6bdbf8f 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go +++ b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go @@ -9,11 +9,14 @@ package casetests import ( "encoding/json" "fmt" - "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/tlcases" + "github.com/vkcom/tl/internal/utils" "math/rand" "os" + common "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/tl" + cases "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/tlcases" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/factory" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/meta" "github.com/vkcom/tl/pkg/basictl" @@ -163,21 +166,131 @@ func TestAppendNewCasesForTesting(t *testing.T) { type Sample struct { sample meta.Object testName string + // if "" then check is skipped + expectingHexValue string } // write your samples here newSamples := []Sample{ - {testName: "TestReadOrder", sample: &tlcases.Replace7{N: 2, M: 1, A: [][]int32{[]int32{2}, []int32{1}}}}, + { + testName: "TestReadOrder", + sample: &cases.Replace7{N: 2, M: 1, A: [][]int32{[]int32{2}, []int32{1}}}, + expectingHexValue: "00000002 00000001 00000002 00000001", + }, + { + testName: "TestInplace", + sample: &cases.TestInplaceStructArgs{ + A1: 1, + A2: 2, + A3: 3, + Arg: cases.Inplace1Int{Value: cases.Inplace2Int{Value: cases.Inplace3TupleInt2{ + Value: common.PairTupleTupleInt2TupleTupleInt2{ + X: common.TupleTupleInt2{[2]int32{3, 4}}, + Y: common.TupleTupleInt2{[2]int32{5, 6}, [2]int32{7, 8}}, + }, + }}}, + }, + expectingHexValue: "00000001 00000002 00000003 00000003 00000004 00000005 00000006 00000007 00000008", + }, + { + testName: "TestInplace2", + sample: &cases.TestInplaceStructArgs2{ + A1: 1, + A2: 2, + A3: 3, + Arg: cases.Inplace1PairTupleIntTupleInt{Value: cases.Inplace2PairTupleIntTupleInt{Value: cases.Inplace3TuplePairTupleIntTupleInt2{ + Value: common.PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2{ + X: common.TupleTuplePairTupleIntTupleInt2{ + common.TuplePairTupleIntTupleInt2{ + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 4, + 5, + 6, + }, + Y: common.TupleInt{ + 7, + 8, + }, + }, + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 9, + 10, + 11, + }, + Y: common.TupleInt{ + 12, + 13, + }, + }, + }, + }, + Y: common.TupleTuplePairTupleIntTupleInt2{ + common.TuplePairTupleIntTupleInt2{ + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 14, + 15, + 16, + }, + Y: common.TupleInt{ + 17, + 18, + }, + }, + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 19, + 20, + 21, + }, + Y: common.TupleInt{ + 22, + 23, + }, + }, + }, + common.TuplePairTupleIntTupleInt2{ + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 24, + 25, + 26, + }, + Y: common.TupleInt{ + 27, + 28, + }, + }, + common.PairTupleIntTupleInt{ + X: common.TupleInt{ + 29, + 30, + 31, + }, + Y: common.TupleInt{ + 32, + 33, + }, + }, + }, + }, + }, + }}}, + }, + expectingHexValue: "00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 0000000a 0000000b 0000000c 0000000d 0000000e 0000000f 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 0000001a 0000001b 0000001c 0000001d 0000001e 0000001f 00000020 00000021", + }, } newSamplesCount := 0 for i, sample := range newSamples { - success, err := addSample(&tests, sample.testName, sample.sample) + success, err := addSample(&tests, sample.testName, sample.sample, sample.expectingHexValue) if success { newSamplesCount += 1 } else if err != nil { - t.Fatalf("Incorrent test sample #%[1]d for \"%[2]s\" was provided", i, sample.sample.TLName()) + t.Fatalf("Incorrent test sample #%[1]d for \"%[2]s\" was provided, error message: %s", i, sample.sample.TLName(), err.Error()) return } } @@ -258,12 +371,15 @@ func checkExistenceOfTest(tests *allTestsBytes, testName, typeName, bytesHex str return true, false, testName } -func addSample(tests *allTestsBytes, testName string, sample meta.Object) (bool, error) { +func addSample(tests *allTestsBytes, testName string, sample meta.Object, expectingHex string) (bool, error) { bytes, err := sample.WriteGeneral(nil) if err != nil { return false, err } hexBytes := utils.SprintHexDump(bytes) + if expectingHex != "" && hexBytes != expectingHex { + return false, fmt.Errorf("bytes are different from expecting:\n\tactual: %s\n\texpected: %s", hexBytes, expectingHex) + } canAdd, exists, placeToAdd := checkExistenceOfTest(tests, testName, sample.TLName(), hexBytes) if canAdd && !exists { successes := tests.Tests[placeToAdd] diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json index 1c7ff38..b026690 100644 --- a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json @@ -63,6 +63,22 @@ } ] }, + "TestInplace": { + "TestingType": "", + "Successes": [ + { + "Bytes": "00000001 00000002 00000003 00000003 00000004 00000005 00000006 00000007 00000008" + } + ] + }, + "TestInplace2": { + "TestingType": "", + "Successes": [ + { + "Bytes": "00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 0000000a 0000000b 0000000c 0000000d 0000000e 0000000f 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 0000001a 0000001b 0000001c 0000001d 0000001e 0000001f 00000020 00000021" + } + ] + }, "TestLocalFieldMask": { "TestingType": "cases.testLocalFieldmask", "Successes": [ diff --git a/internal/tlcodegen/test/gen/cases/constants/constants.go b/internal/tlcodegen/test/gen/cases/constants/constants.go index 4ae1659..878b46a 100644 --- a/internal/tlcodegen/test/gen/cases/constants/constants.go +++ b/internal/tlcodegen/test/gen/cases/constants/constants.go @@ -15,6 +15,9 @@ const ( BenchmarksVrutoyTopLevelContainerWithDependency = 0xc176008e // benchmarks.vrutoyTopLevelContainerWithDependency BenchmarksVrutoytopLevelUnionBig = 0xef556bee // benchmarks.vrutoytopLevelUnionBig BenchmarksVrutoytopLevelUnionEmpty = 0xce27c770 // benchmarks.vrutoytopLevelUnionEmpty + CasesInplace1 = 0x5533e8e9 // cases.inplace1 + CasesInplace2 = 0x869fcff5 // cases.inplace2 + CasesInplace3 = 0x4ffb95cb // cases.inplace3 CasesMyCycle1 = 0xd3ca919d // cases.myCycle1 CasesMyCycle2 = 0x5444c9a2 // cases.myCycle2 CasesMyCycle3 = 0x7624f86b // cases.myCycle3 @@ -32,6 +35,8 @@ const ( CasesTestEnum2 = 0x86ea88ce // cases.testEnum2 CasesTestEnum3 = 0x69b83e2f // cases.testEnum3 CasesTestEnumContainer = 0xcb684231 // cases.testEnumContainer + CasesTestInplaceStructArgs = 0xa9e4441e // cases.testInplaceStructArgs + CasesTestInplaceStructArgs2 = 0xaa9f2480 // cases.testInplaceStructArgs2 CasesTestLocalFieldmask = 0xf68fd3f9 // cases.testLocalFieldmask CasesTestMaybe = 0xd6602613 // cases.testMaybe CasesTestOutFieldMask = 0xbd6b4b3c // cases.testOutFieldMask @@ -61,6 +66,7 @@ const ( Int32 = 0x7934e71f // int32 Int64 = 0xf5609de0 // int64 Long = 0x22076cba // long + Pair = 0xf01604df // pair ResultFalse = 0x27930a7b // resultFalse ResultTrue = 0x3f9c8ef8 // resultTrue String = 0xb5286e24 // string diff --git a/internal/tlcodegen/test/gen/cases/factory/factory.go b/internal/tlcodegen/test/gen/cases/factory/factory.go index e40e16b..4d8e95a 100644 --- a/internal/tlcodegen/test/gen/cases/factory/factory.go +++ b/internal/tlcodegen/test/gen/cases/factory/factory.go @@ -31,6 +31,8 @@ import ( "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestDictInt" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestDictString" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestEnumContainer" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestLocalFieldmask" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestMaybe" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestOutFieldMaskContainer" @@ -122,6 +124,8 @@ func init() { meta.SetGlobalFactoryCreateForEnumElement(0x86ea88ce) meta.SetGlobalFactoryCreateForEnumElement(0x69b83e2f) meta.SetGlobalFactoryCreateForObject(0xcb684231, func() meta.Object { var ret tlCasesTestEnumContainer.CasesTestEnumContainer; return &ret }) + meta.SetGlobalFactoryCreateForObject(0xa9e4441e, func() meta.Object { var ret tlCasesTestInplaceStructArgs.CasesTestInplaceStructArgs; return &ret }) + meta.SetGlobalFactoryCreateForObject(0xaa9f2480, func() meta.Object { var ret tlCasesTestInplaceStructArgs2.CasesTestInplaceStructArgs2; return &ret }) meta.SetGlobalFactoryCreateForObject(0xf68fd3f9, func() meta.Object { var ret tlCasesTestLocalFieldmask.CasesTestLocalFieldmask; return &ret }) meta.SetGlobalFactoryCreateForObject(0xd6602613, func() meta.Object { var ret tlCasesTestMaybe.CasesTestMaybe; return &ret }) meta.SetGlobalFactoryCreateForObject(0x1850ffe4, func() meta.Object { diff --git a/internal/tlcodegen/test/gen/cases/factory_bytes/factory_bytes.go b/internal/tlcodegen/test/gen/cases/factory_bytes/factory_bytes.go index ac5b42d..6ee1ed1 100644 --- a/internal/tlcodegen/test/gen/cases/factory_bytes/factory_bytes.go +++ b/internal/tlcodegen/test/gen/cases/factory_bytes/factory_bytes.go @@ -31,6 +31,8 @@ import ( "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestDictInt" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestDictString" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestEnumContainer" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestLocalFieldmask" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestMaybe" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestOutFieldMaskContainer" @@ -122,6 +124,8 @@ func init() { meta.SetGlobalFactoryCreateForEnumElementBytes(0x86ea88ce) meta.SetGlobalFactoryCreateForEnumElementBytes(0x69b83e2f) meta.SetGlobalFactoryCreateForObjectBytes(0xcb684231, func() meta.Object { var ret tlCasesTestEnumContainer.CasesTestEnumContainer; return &ret }) + meta.SetGlobalFactoryCreateForObjectBytes(0xa9e4441e, func() meta.Object { var ret tlCasesTestInplaceStructArgs.CasesTestInplaceStructArgs; return &ret }) + meta.SetGlobalFactoryCreateForObjectBytes(0xaa9f2480, func() meta.Object { var ret tlCasesTestInplaceStructArgs2.CasesTestInplaceStructArgs2; return &ret }) meta.SetGlobalFactoryCreateForObjectBytes(0xf68fd3f9, func() meta.Object { var ret tlCasesTestLocalFieldmask.CasesTestLocalFieldmask; return &ret }) meta.SetGlobalFactoryCreateForObjectBytes(0xd6602613, func() meta.Object { var ret tlCasesTestMaybe.CasesTestMaybe; return &ret }) meta.SetGlobalFactoryCreateForObjectBytes(0x1850ffe4, func() meta.Object { diff --git a/internal/tlcodegen/test/gen/cases/meta/meta.go b/internal/tlcodegen/test/gen/cases/meta/meta.go index f132b92..8b5c8de 100644 --- a/internal/tlcodegen/test/gen/cases/meta/meta.go +++ b/internal/tlcodegen/test/gen/cases/meta/meta.go @@ -334,6 +334,8 @@ func init() { fillObject("cases.testEnum2#86ea88ce", "#86ea88ce", &TLItem{tag: 0x86ea88ce, annotations: 0x0, tlName: "cases.testEnum2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) fillObject("cases.testEnum3#69b83e2f", "#69b83e2f", &TLItem{tag: 0x69b83e2f, annotations: 0x0, tlName: "cases.testEnum3", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) fillObject("cases.testEnumContainer#cb684231", "#cb684231", &TLItem{tag: 0xcb684231, annotations: 0x0, tlName: "cases.testEnumContainer", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("cases.testInplaceStructArgs#a9e4441e", "#a9e4441e", &TLItem{tag: 0xa9e4441e, annotations: 0x0, tlName: "cases.testInplaceStructArgs", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("cases.testInplaceStructArgs2#aa9f2480", "#aa9f2480", &TLItem{tag: 0xaa9f2480, annotations: 0x0, tlName: "cases.testInplaceStructArgs2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) fillObject("cases.testLocalFieldmask#f68fd3f9", "#f68fd3f9", &TLItem{tag: 0xf68fd3f9, annotations: 0x0, tlName: "cases.testLocalFieldmask", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) fillObject("cases.testMaybe#d6602613", "#d6602613", &TLItem{tag: 0xd6602613, annotations: 0x0, tlName: "cases.testMaybe", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) fillObject("cases.testOutFieldMaskContainer#1850ffe4", "#1850ffe4", &TLItem{tag: 0x1850ffe4, annotations: 0x0, tlName: "cases.testOutFieldMaskContainer", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) diff --git a/internal/tlcodegen/test/gen/cases/tl/tl.go b/internal/tlcodegen/test/gen/cases/tl/tl.go index 92d14d4..249733f 100644 --- a/internal/tlcodegen/test/gen/cases/tl/tl.go +++ b/internal/tlcodegen/test/gen/cases/tl/tl.go @@ -21,10 +21,18 @@ import ( "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlInt64" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlIntMaybe" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlLong" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlString" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTrue" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt4" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTuplePairTupleIntTupleInt2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleString4" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTupleInt2" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTuplePairTupleIntTupleInt2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlVectorBenchmarksVruPosition" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlVectorDictionaryFieldInt" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlVectorDictionaryFieldString" @@ -33,35 +41,43 @@ import ( ) type ( - DictionaryAnyDoubleInt = tlDictionaryAnyDoubleInt.DictionaryAnyDoubleInt - DictionaryAnyIntInt = tlDictionaryAnyIntInt.DictionaryAnyIntInt - DictionaryAnyIntIntBytes = tlDictionaryAnyIntInt.DictionaryAnyIntIntBytes - DictionaryFieldAnyDoubleInt = tlDictionaryFieldAnyDoubleInt.DictionaryFieldAnyDoubleInt - DictionaryFieldAnyIntInt = tlDictionaryFieldAnyIntInt.DictionaryFieldAnyIntInt - DictionaryFieldInt = tlDictionaryFieldInt.DictionaryFieldInt - DictionaryFieldIntBytes = tlDictionaryFieldInt.DictionaryFieldIntBytes - DictionaryFieldString = tlDictionaryFieldString.DictionaryFieldString - DictionaryFieldStringBytes = tlDictionaryFieldString.DictionaryFieldStringBytes - DictionaryInt = tlDictionaryInt.DictionaryInt - DictionaryIntBytes = tlDictionaryInt.DictionaryIntBytes - DictionaryString = tlDictionaryString.DictionaryString - DictionaryStringBytes = tlDictionaryString.DictionaryStringBytes - Int = tlInt.Int - Int32 = tlInt32.Int32 - Int64 = tlInt64.Int64 - IntMaybe = tlIntMaybe.IntMaybe - Long = tlLong.Long - String = tlString.String - True = tlTrue.True - TupleInt4 = tlTupleInt4.TupleInt4 - TupleString4 = tlTupleString4.TupleString4 - TupleString4Bytes = tlTupleString4.TupleString4Bytes - VectorBenchmarksVruPosition = tlVectorBenchmarksVruPosition.VectorBenchmarksVruPosition - VectorDictionaryFieldInt = tlVectorDictionaryFieldInt.VectorDictionaryFieldInt - VectorDictionaryFieldIntBytes = tlVectorDictionaryFieldInt.VectorDictionaryFieldIntBytes - VectorDictionaryFieldString = tlVectorDictionaryFieldString.VectorDictionaryFieldString - VectorDictionaryFieldStringBytes = tlVectorDictionaryFieldString.VectorDictionaryFieldStringBytes - VectorInt = tlVectorInt.VectorInt - VectorString = tlVectorString.VectorString - VectorStringBytes = tlVectorString.VectorStringBytes + DictionaryAnyDoubleInt = tlDictionaryAnyDoubleInt.DictionaryAnyDoubleInt + DictionaryAnyIntInt = tlDictionaryAnyIntInt.DictionaryAnyIntInt + DictionaryAnyIntIntBytes = tlDictionaryAnyIntInt.DictionaryAnyIntIntBytes + DictionaryFieldAnyDoubleInt = tlDictionaryFieldAnyDoubleInt.DictionaryFieldAnyDoubleInt + DictionaryFieldAnyIntInt = tlDictionaryFieldAnyIntInt.DictionaryFieldAnyIntInt + DictionaryFieldInt = tlDictionaryFieldInt.DictionaryFieldInt + DictionaryFieldIntBytes = tlDictionaryFieldInt.DictionaryFieldIntBytes + DictionaryFieldString = tlDictionaryFieldString.DictionaryFieldString + DictionaryFieldStringBytes = tlDictionaryFieldString.DictionaryFieldStringBytes + DictionaryInt = tlDictionaryInt.DictionaryInt + DictionaryIntBytes = tlDictionaryInt.DictionaryIntBytes + DictionaryString = tlDictionaryString.DictionaryString + DictionaryStringBytes = tlDictionaryString.DictionaryStringBytes + Int = tlInt.Int + Int32 = tlInt32.Int32 + Int64 = tlInt64.Int64 + IntMaybe = tlIntMaybe.IntMaybe + Long = tlLong.Long + PairTupleIntTupleInt = tlPairTupleIntTupleInt.PairTupleIntTupleInt + PairTupleTupleInt2TupleTupleInt2 = tlPairTupleTupleInt2TupleTupleInt2.PairTupleTupleInt2TupleTupleInt2 + PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2 = tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2.PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2 + String = tlString.String + True = tlTrue.True + TupleInt = tlTupleInt.TupleInt + TupleInt2 = tlTupleInt2.TupleInt2 + TupleInt4 = tlTupleInt4.TupleInt4 + TuplePairTupleIntTupleInt2 = tlTuplePairTupleIntTupleInt2.TuplePairTupleIntTupleInt2 + TupleString4 = tlTupleString4.TupleString4 + TupleString4Bytes = tlTupleString4.TupleString4Bytes + TupleTupleInt2 = tlTupleTupleInt2.TupleTupleInt2 + TupleTuplePairTupleIntTupleInt2 = tlTupleTuplePairTupleIntTupleInt2.TupleTuplePairTupleIntTupleInt2 + VectorBenchmarksVruPosition = tlVectorBenchmarksVruPosition.VectorBenchmarksVruPosition + VectorDictionaryFieldInt = tlVectorDictionaryFieldInt.VectorDictionaryFieldInt + VectorDictionaryFieldIntBytes = tlVectorDictionaryFieldInt.VectorDictionaryFieldIntBytes + VectorDictionaryFieldString = tlVectorDictionaryFieldString.VectorDictionaryFieldString + VectorDictionaryFieldStringBytes = tlVectorDictionaryFieldString.VectorDictionaryFieldStringBytes + VectorInt = tlVectorInt.VectorInt + VectorString = tlVectorString.VectorString + VectorStringBytes = tlVectorString.VectorStringBytes ) diff --git a/internal/tlcodegen/test/gen/cases/tlcases/tlcases.go b/internal/tlcodegen/test/gen/cases/tlcases/tlcases.go index 3638f93..1b43ebb 100644 --- a/internal/tlcodegen/test/gen/cases/tlcases/tlcases.go +++ b/internal/tlcodegen/test/gen/cases/tlcases/tlcases.go @@ -10,6 +10,12 @@ package tlcases import ( "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/cycle_42a1a8597f818829cd168dce9785322f" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/cycle_44515dca4b2e76ca676b13645e716786" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesReplace7" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesReplace7plus" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesReplace7plusplus" @@ -25,6 +31,8 @@ import ( "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestEnum2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestEnum3" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestEnumContainer" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestLocalFieldmask" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestMaybe" "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestOutFieldMask" @@ -36,6 +44,12 @@ import ( ) type ( + Inplace1Int = tlCasesInplace1Int.CasesInplace1Int + Inplace1PairTupleIntTupleInt = tlCasesInplace1PairTupleIntTupleInt.CasesInplace1PairTupleIntTupleInt + Inplace2Int = tlCasesInplace2Int.CasesInplace2Int + Inplace2PairTupleIntTupleInt = tlCasesInplace2PairTupleIntTupleInt.CasesInplace2PairTupleIntTupleInt + Inplace3TupleInt2 = tlCasesInplace3TupleInt2.CasesInplace3TupleInt2 + Inplace3TuplePairTupleIntTupleInt2 = tlCasesInplace3TuplePairTupleIntTupleInt2.CasesInplace3TuplePairTupleIntTupleInt2 MyCycle1 = cycle_44515dca4b2e76ca676b13645e716786.CasesMyCycle1 MyCycle2 = cycle_44515dca4b2e76ca676b13645e716786.CasesMyCycle2 MyCycle3 = cycle_44515dca4b2e76ca676b13645e716786.CasesMyCycle3 @@ -51,6 +65,8 @@ type ( TestDictString = tlCasesTestDictString.CasesTestDictString TestEnum = tlCasesTestEnum.CasesTestEnum TestEnumContainer = tlCasesTestEnumContainer.CasesTestEnumContainer + TestInplaceStructArgs = tlCasesTestInplaceStructArgs.CasesTestInplaceStructArgs + TestInplaceStructArgs2 = tlCasesTestInplaceStructArgs2.CasesTestInplaceStructArgs2 TestLocalFieldmask = tlCasesTestLocalFieldmask.CasesTestLocalFieldmask TestMaybe = tlCasesTestMaybe.CasesTestMaybe TestOutFieldMask = tlCasesTestOutFieldMask.CasesTestOutFieldMask diff --git a/internal/tlcodegen/test/tls/cases.tl b/internal/tlcodegen/test/tls/cases.tl index 3e252b5..5daf8bc 100644 --- a/internal/tlcodegen/test/tls/cases.tl +++ b/internal/tlcodegen/test/tls/cases.tl @@ -19,6 +19,8 @@ true = True; resultFalse#27930a7b {t:Type} = Maybe t; resultTrue#3f9c8ef8 {t:Type} t = Maybe t; +pair {X:Type} {Y:Type} x:X y:Y = Pair X Y; + // BLOCK: TEST RECURSIVE TYPES cases.myCycle1 fields_mask:# a:fields_mask.0?cases.myCycle2 = cases.MyCycle1; cases.myCycle2 fields_mask:# a:fields_mask.0?cases.myCycle3 = cases.MyCycle2; @@ -82,6 +84,14 @@ cases.replace7 n:# m:# a:n*[m*[int]] = cases.Replace7; cases.replace7plus n:# m:# a:n.0?n*[m*[int]] = cases.Replace7plus; cases.replace7plusplus N:# M:# A:N.0?N*[M*[int]] = cases.Replace7plusplus; +// BLOCK: TEST INPLACING ARGUMENTS +cases.testInplaceStructArgs a1:# a2:# a3:# arg:cases.inplace1 = cases.TestInplaceStructArgs; +cases.testInplaceStructArgs2 a1:# a2:# a3:# arg:cases.inplace1, tuple>> = cases.TestInplaceStructArgs2; + +cases.inplace1 {a1:#} {a2:#} {a3:#} {X:Type} value:cases.inplace2 = cases.Inplace1 a1 a2 a3 X; +cases.inplace2 {a1:#} {a2:#} {a3:#} {X:Type} value:cases.inplace3> = cases.Inplace2 a1 a2 a3 X; +cases.inplace3 {a1:#} {a2:#} {a3:#} {X:Type} value:pair, tuple> = cases.Inplace3 a1 a2 a3 X; + // BLOCK: Bytes vesrion cases_bytes.testArray n:# arr:n*[string] = cases_bytes.TestArray; cases_bytes.testVector arr:(vector string) = cases_bytes.TestVector; From 2aa257d6e9365a19823f1cbf4bc5474deb895e7e Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 17:00:00 +0300 Subject: [PATCH 32/37] update test --- .../codegen_test/casetests/bytes_read_test.go | 3 +++ .../codegen_test/data/test-objects-bytes.json | 4 ++-- .../test/gen/cases_php/VK/TL/factory.php | 17 +++++++++++++++++ .../tlcodegen/test/gen/cases_php/VK/TL/meta.php | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go index 6bdbf8f..3b545f2 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go +++ b/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go @@ -383,6 +383,9 @@ func addSample(tests *allTestsBytes, testName string, sample meta.Object, expect canAdd, exists, placeToAdd := checkExistenceOfTest(tests, testName, sample.TLName(), hexBytes) if canAdd && !exists { successes := tests.Tests[placeToAdd] + if successes.Successes == nil { + successes.TestingType = sample.TLName() + } successes.Successes = append(successes.Successes, MappingSuccessBytes{Bytes: hexBytes}) tests.Tests[placeToAdd] = successes return true, nil diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json index b026690..97ce7f4 100644 --- a/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-bytes.json @@ -64,7 +64,7 @@ ] }, "TestInplace": { - "TestingType": "", + "TestingType": "cases.testInplaceStructArgs", "Successes": [ { "Bytes": "00000001 00000002 00000003 00000003 00000004 00000005 00000006 00000007 00000008" @@ -72,7 +72,7 @@ ] }, "TestInplace2": { - "TestingType": "", + "TestingType": "cases.testInplaceStructArgs2", "Successes": [ { "Bytes": "00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 0000000a 0000000b 0000000c 0000000d 0000000e 0000000f 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 0000001a 0000001b 0000001c 0000001d 0000001e 0000001f 00000020 00000021" diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php index a0d7d16..811cd4a 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/factory.php @@ -31,6 +31,12 @@ include "cases_bytes/Types/cases_bytes_testEnumContainer.php"; include "cases_bytes/Types/cases_bytes_testTuple.php"; include "cases_bytes/Types/cases_bytes_testVector.php"; +include "cases/Types/cases_inplace1__int.php"; +include "cases/Types/cases_inplace1__Pair__array_int__array_int.php"; +include "cases/Types/cases_inplace2__int.php"; +include "cases/Types/cases_inplace2__Pair__array_int__array_int.php"; +include "cases/Types/cases_inplace3__array_int.php"; +include "cases/Types/cases_inplace3__array_Pair__array_int__array_int.php"; include "cases/Types/cases_myCycle1.php"; include "cases/Types/cases_myCycle2.php"; include "cases/Types/cases_myCycle3.php"; @@ -49,6 +55,8 @@ include "cases/Types/cases_testEnum2.php"; include "cases/Types/cases_testEnum3.php"; include "cases/Types/cases_testEnumContainer.php"; +include "cases/Types/cases_testInplaceStructArgs.php"; +include "cases/Types/cases_testInplaceStructArgs2.php"; include "cases/Types/cases_testLocalFieldmask.php"; include "cases/Types/cases_testMaybe.php"; include "cases/Types/cases_testOutFieldMask.php"; @@ -61,6 +69,9 @@ include "cases/Types/cases_testUnionContainer.php"; include "cases/Types/cases_testVector.php"; include "_common/Types/dictionaryFieldAny__float__int.php"; +include "_common/Types/pair__array_int__array_int.php"; +include "_common/Types/pair__array_array_int__array_array_int.php"; +include "_common/Types/pair__array_array_Pair__array_int__array_int__array_array_Pair__array_int__array_int.php"; class tl_factory { /** @var mixed[] */ // TODO @@ -167,6 +178,12 @@ function __construct() { $itemcb684231 = function () { return new TL\cases\Types\cases_testEnumContainer(); }; $this->tl_factory_by_name["cases.testEnumContainer"] = $itemcb684231; $this->tl_factory_by_tag[0xcb684231] = $itemcb684231; + $itema9e4441e = function () { return new TL\cases\Types\cases_testInplaceStructArgs(); }; + $this->tl_factory_by_name["cases.testInplaceStructArgs"] = $itema9e4441e; + $this->tl_factory_by_tag[0xa9e4441e] = $itema9e4441e; + $itemaa9f2480 = function () { return new TL\cases\Types\cases_testInplaceStructArgs2(); }; + $this->tl_factory_by_name["cases.testInplaceStructArgs2"] = $itemaa9f2480; + $this->tl_factory_by_tag[0xaa9f2480] = $itemaa9f2480; $itemf68fd3f9 = function () { return new TL\cases\Types\cases_testLocalFieldmask(); }; $this->tl_factory_by_name["cases.testLocalFieldmask"] = $itemf68fd3f9; $this->tl_factory_by_tag[0xf68fd3f9] = $itemf68fd3f9; diff --git a/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php b/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php index 1e60bf9..05bbbcb 100644 --- a/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php +++ b/internal/tlcodegen/test/gen/cases_php/VK/TL/meta.php @@ -161,6 +161,12 @@ function __construct() { $itemcb684231 = new tl_item(0xcb684231, 0x0, "cases.testEnumContainer"); $this->tl_item_by_name["cases.testEnumContainer"] = $itemcb684231; $this->tl_item_by_tag[0xcb684231] = $itemcb684231; + $itema9e4441e = new tl_item(0xa9e4441e, 0x0, "cases.testInplaceStructArgs"); + $this->tl_item_by_name["cases.testInplaceStructArgs"] = $itema9e4441e; + $this->tl_item_by_tag[0xa9e4441e] = $itema9e4441e; + $itemaa9f2480 = new tl_item(0xaa9f2480, 0x0, "cases.testInplaceStructArgs2"); + $this->tl_item_by_name["cases.testInplaceStructArgs2"] = $itemaa9f2480; + $this->tl_item_by_tag[0xaa9f2480] = $itemaa9f2480; $itemf68fd3f9 = new tl_item(0xf68fd3f9, 0x0, "cases.testLocalFieldmask"); $this->tl_item_by_name["cases.testLocalFieldmask"] = $itemf68fd3f9; $this->tl_item_by_tag[0xf68fd3f9] = $itemf68fd3f9; From 7737a129fa9098303c363fe2b870cbd17a8edeb7 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 17:19:02 +0300 Subject: [PATCH 33/37] multi lang testing --- Makefile | 4 ++++ internal/tlcodegen/test/codegen_test/Makefile | 15 +++++++++++++++ internal/tlcodegen/test/codegen_test/cpp/Makefile | 12 +++++++++--- .../casetests/basics/easyjson/base_readers.go | 0 .../basics/easyjson/base_readers_test.go | 0 .../{ => golang}/casetests/bytes_read_test.go | 2 +- .../casetests/json_read_benchmark_test.go | 0 .../{ => golang}/casetests/json_read_test.go | 2 +- 8 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 internal/tlcodegen/test/codegen_test/Makefile rename internal/tlcodegen/test/codegen_test/{ => golang}/casetests/basics/easyjson/base_readers.go (100%) rename internal/tlcodegen/test/codegen_test/{ => golang}/casetests/basics/easyjson/base_readers_test.go (100%) rename internal/tlcodegen/test/codegen_test/{ => golang}/casetests/bytes_read_test.go (99%) rename internal/tlcodegen/test/codegen_test/{ => golang}/casetests/json_read_benchmark_test.go (100%) rename internal/tlcodegen/test/codegen_test/{ => golang}/casetests/json_read_test.go (98%) diff --git a/Makefile b/Makefile index 5eb4f8e..de2a7f5 100644 --- a/Makefile +++ b/Makefile @@ -154,6 +154,10 @@ cpp: $(MAKE) cpp_gen $(MAKE) cpp_build +.PHONY: test_multi_lang_cases +test_multi_lang_cases: + @cd internal/tlcodegen/test/codegen_test/; \ + $(MAKE) run-all-languages-tests; .PHONY: test test: diff --git a/internal/tlcodegen/test/codegen_test/Makefile b/internal/tlcodegen/test/codegen_test/Makefile new file mode 100644 index 0000000..a5f8185 --- /dev/null +++ b/internal/tlcodegen/test/codegen_test/Makefile @@ -0,0 +1,15 @@ + +run-all-languages-tests: + make run-php-tests; \ + make run-cpp-tests; \ + make run-golang-tests; + +run-php-tests: + cd php && make run-all-tests + +run-cpp-tests: + #cd cpp && make run-all-tests + +run-golang-tests: + @cd golang; \ + go test ./... \ No newline at end of file diff --git a/internal/tlcodegen/test/codegen_test/cpp/Makefile b/internal/tlcodegen/test/codegen_test/cpp/Makefile index 6e47dba..cddbb48 100644 --- a/internal/tlcodegen/test/codegen_test/cpp/Makefile +++ b/internal/tlcodegen/test/codegen_test/cpp/Makefile @@ -5,10 +5,16 @@ SCHEMA_DIR = $(CPP_DIR)/schema_cpp CC = g++ CFLAGS = -std=c++17 -O3 -Wno-noexcept-type -g -Wall -Wextra -Werror=return-type -Wno-unused-parameter +build-test-gen: + @cd ../../../../../; \ + $(MAKE) build; \ + $(MAKE) cpp_gen_test_data; + # run in project root "make cpp_gen_test_data" -run-all-tests: - make run-objects-test - make run-functions-test +run-all-tests: build-test-gen + make run-objects-test; \ + make run-functions-test; \ + make clean-build; clean-build: rm -rf build diff --git a/internal/tlcodegen/test/codegen_test/casetests/basics/easyjson/base_readers.go b/internal/tlcodegen/test/codegen_test/golang/casetests/basics/easyjson/base_readers.go similarity index 100% rename from internal/tlcodegen/test/codegen_test/casetests/basics/easyjson/base_readers.go rename to internal/tlcodegen/test/codegen_test/golang/casetests/basics/easyjson/base_readers.go diff --git a/internal/tlcodegen/test/codegen_test/casetests/basics/easyjson/base_readers_test.go b/internal/tlcodegen/test/codegen_test/golang/casetests/basics/easyjson/base_readers_test.go similarity index 100% rename from internal/tlcodegen/test/codegen_test/casetests/basics/easyjson/base_readers_test.go rename to internal/tlcodegen/test/codegen_test/golang/casetests/basics/easyjson/base_readers_test.go diff --git a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go b/internal/tlcodegen/test/codegen_test/golang/casetests/bytes_read_test.go similarity index 99% rename from internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go rename to internal/tlcodegen/test/codegen_test/golang/casetests/bytes_read_test.go index 3b545f2..3919c05 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go +++ b/internal/tlcodegen/test/codegen_test/golang/casetests/bytes_read_test.go @@ -155,7 +155,7 @@ func TestAllTLObjectsReadJsonByRandomBytes(t *testing.T) { } } -const PathToBytesData = "../data/test-objects-bytes.json" +const PathToBytesData = "../../data/test-objects-bytes.json" func TestAppendNewCasesForTesting(t *testing.T) { tests, success := initTestData(t) diff --git a/internal/tlcodegen/test/codegen_test/casetests/json_read_benchmark_test.go b/internal/tlcodegen/test/codegen_test/golang/casetests/json_read_benchmark_test.go similarity index 100% rename from internal/tlcodegen/test/codegen_test/casetests/json_read_benchmark_test.go rename to internal/tlcodegen/test/codegen_test/golang/casetests/json_read_benchmark_test.go diff --git a/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go b/internal/tlcodegen/test/codegen_test/golang/casetests/json_read_test.go similarity index 98% rename from internal/tlcodegen/test/codegen_test/casetests/json_read_test.go rename to internal/tlcodegen/test/codegen_test/golang/casetests/json_read_test.go index 9c75a0a..564bd51 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go +++ b/internal/tlcodegen/test/codegen_test/golang/casetests/json_read_test.go @@ -178,7 +178,7 @@ func TestAllTLObjectsReadJsonByRandom(t *testing.T) { } func TestGeneralCases(t *testing.T) { - const PathToJsonData = "../data/test-objects-json.json" + const PathToJsonData = "../../data/test-objects-json.json" data, readErr := os.ReadFile(PathToJsonData) if readErr != nil { From 8628c2714e8b40050e3adcf516d361967a7e42db Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 20:20:54 +0300 Subject: [PATCH 34/37] fix multi lang testing with cpp --- internal/tlcodegen/test/codegen_test/Makefile | 5 +- .../codegen_test/{ => golang}/codegen_test.go | 6 +- .../goldmaster_invariants_test.go | 2 +- .../tlcodegen/test/gen/cases_cpp/Makefile | 4 +- .../__common_namespace/types/tuple.hpp | 5 + .../test/gen/cases_cpp/__factory/details.cpp | 34 + .../test/gen/cases_cpp/__meta/details.cpp | 6 + .../test/gen/cases_cpp/cases/details.cpp | 816 ++++++++++++++++++ .../gen/cases_cpp/cases/headers/cases_int.hpp | 10 + .../cases_cpp/cases/headers/cases_tuple.hpp | 81 ++ .../test/gen/schema/constants/constants.go | 1 - .../tlcodegen/test/gen/schema/meta/meta.go | 306 +++---- internal/tlcodegen/test/tls/schema.tl | 2 +- 13 files changed, 1121 insertions(+), 157 deletions(-) rename internal/tlcodegen/test/codegen_test/{ => golang}/codegen_test.go (96%) rename internal/tlcodegen/test/codegen_test/{ => golang}/goldmaster_invariants_test.go (98%) diff --git a/internal/tlcodegen/test/codegen_test/Makefile b/internal/tlcodegen/test/codegen_test/Makefile index a5f8185..67f43d8 100644 --- a/internal/tlcodegen/test/codegen_test/Makefile +++ b/internal/tlcodegen/test/codegen_test/Makefile @@ -8,8 +8,9 @@ run-php-tests: cd php && make run-all-tests run-cpp-tests: - #cd cpp && make run-all-tests + cd cpp && make run-all-tests run-golang-tests: - @cd golang; \ + cd ../../../.. && make goldmaster_nocompile; + cd golang; go test ./... \ No newline at end of file diff --git a/internal/tlcodegen/test/codegen_test/codegen_test.go b/internal/tlcodegen/test/codegen_test/golang/codegen_test.go similarity index 96% rename from internal/tlcodegen/test/codegen_test/codegen_test.go rename to internal/tlcodegen/test/codegen_test/golang/codegen_test.go index 2fbd9d7..e0eacbc 100644 --- a/internal/tlcodegen/test/codegen_test/codegen_test.go +++ b/internal/tlcodegen/test/codegen_test/golang/codegen_test.go @@ -1,4 +1,4 @@ -package codegen_test +package golang_test import ( "encoding/json" @@ -44,7 +44,7 @@ type writeTest struct { } func TestWriteArgs(t *testing.T) { - const PathToJsonData = "data/test-functions-bytes.json" + const PathToJsonData = "../data/test-functions-bytes.json" data, readErr := os.ReadFile(PathToJsonData) if readErr != nil { @@ -99,7 +99,7 @@ func checkFunctionReadWrite(t *testing.T, fnType string, fnJsonValue string, res } func TestReadResult(t *testing.T) { - const PathToJsonData = "data/test-functions-bytes.json" + const PathToJsonData = "../data/test-functions-bytes.json" data, readErr := os.ReadFile(PathToJsonData) if readErr != nil { diff --git a/internal/tlcodegen/test/codegen_test/goldmaster_invariants_test.go b/internal/tlcodegen/test/codegen_test/golang/goldmaster_invariants_test.go similarity index 98% rename from internal/tlcodegen/test/codegen_test/goldmaster_invariants_test.go rename to internal/tlcodegen/test/codegen_test/golang/goldmaster_invariants_test.go index 7cef806..b3bd56a 100644 --- a/internal/tlcodegen/test/codegen_test/goldmaster_invariants_test.go +++ b/internal/tlcodegen/test/codegen_test/golang/goldmaster_invariants_test.go @@ -1,4 +1,4 @@ -package codegen +package golang import ( "github.com/stretchr/testify/assert" diff --git a/internal/tlcodegen/test/gen/cases_cpp/Makefile b/internal/tlcodegen/test/gen/cases_cpp/Makefile index 5f43347..b584828 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/Makefile +++ b/internal/tlcodegen/test/gen/cases_cpp/Makefile @@ -10,14 +10,14 @@ main.o: main.cpp __build/__meta.o: __meta/headers.hpp __meta/details.cpp $(CC) $(CFLAGS) -o __build/__meta.o -c __meta/details.cpp -__build/__factory.o: __factory/headers.hpp __factory/details.cpp cases/types/cases.testVector.hpp cases/types/cases.testUnionContainer.hpp cases/types/cases.testUnion2.hpp cases/types/cases.testUnion1.hpp cases/types/cases.testTuple.hpp cases/types/cases.testRecursiveFieldMask.hpp cases/types/cases.testOutFieldMaskContainer.hpp cases/types/cases.testMaybe.hpp cases/types/cases.testLocalFieldmask.hpp cases/types/cases.testEnumContainer.hpp cases/types/cases.testDictString.hpp cases/types/cases.testDictInt.hpp cases/types/cases.testDictAny.hpp cases/types/cases.testBeforeReadBitValidation.hpp cases/types/cases.testArray.hpp cases/types/cases.testAllPossibleFieldConfigsContainer.hpp cases/types/cases.replace7plusplus.hpp cases/types/cases.replace7plus.hpp cases/types/cases.replace7.hpp cases/types/cases.myCycle1.hpp cases/types/cases.myCycle2.hpp cases/types/cases.myCycle3.hpp cases_bytes/types/cases_bytes.testVector.hpp cases_bytes/types/cases_bytes.testTuple.hpp cases_bytes/types/cases_bytes.testEnumContainer.hpp cases/types/cases.TestEnumItems.hpp cases_bytes/types/cases_bytes.TestEnumItems.hpp cases_bytes/types/cases_bytes.testDictStringString.hpp cases_bytes/types/cases_bytes.testDictString.hpp cases_bytes/types/cases_bytes.testDictInt.hpp cases_bytes/types/cases_bytes.testDictAny.hpp cases_bytes/types/cases_bytes.testArray.hpp benchmarks/types/benchmarks.vrutoyTopLevelContainerWithDependency.hpp benchmarks/types/benchmarks.vrutoyTopLevelContainer.hpp benchmarks/types/benchmarks.vrutoytopLevelUnionEmpty.hpp benchmarks/types/benchmarks.vrutoytopLevelUnionBig.hpp benchmarks/types/benchmarks.vruposition.hpp __common_namespace/types/true.hpp benchmarks/types/benchmarks.vruhash.hpp +__build/__factory.o: __factory/headers.hpp __factory/details.cpp cases/types/cases.testVector.hpp cases/types/cases.testUnionContainer.hpp cases/types/cases.testUnion2.hpp cases/types/cases.testUnion1.hpp cases/types/cases.testTuple.hpp cases/types/cases.testRecursiveFieldMask.hpp cases/types/cases.testOutFieldMaskContainer.hpp cases/types/cases.testMaybe.hpp cases/types/cases.testLocalFieldmask.hpp cases/types/cases.testInplaceStructArgs2.hpp cases/types/cases.testInplaceStructArgs.hpp cases/types/cases.testEnumContainer.hpp cases/types/cases.testDictString.hpp cases/types/cases.testDictInt.hpp cases/types/cases.testDictAny.hpp cases/types/cases.testBeforeReadBitValidation.hpp cases/types/cases.testArray.hpp cases/types/cases.testAllPossibleFieldConfigsContainer.hpp cases/types/cases.replace7plusplus.hpp cases/types/cases.replace7plus.hpp cases/types/cases.replace7.hpp cases/types/cases.myCycle1.hpp cases/types/cases.myCycle2.hpp cases/types/cases.myCycle3.hpp cases_bytes/types/cases_bytes.testVector.hpp cases_bytes/types/cases_bytes.testTuple.hpp cases_bytes/types/cases_bytes.testEnumContainer.hpp cases/types/cases.TestEnumItems.hpp cases_bytes/types/cases_bytes.TestEnumItems.hpp cases_bytes/types/cases_bytes.testDictStringString.hpp cases_bytes/types/cases_bytes.testDictString.hpp cases_bytes/types/cases_bytes.testDictInt.hpp cases_bytes/types/cases_bytes.testDictAny.hpp cases_bytes/types/cases_bytes.testArray.hpp benchmarks/types/benchmarks.vrutoyTopLevelContainerWithDependency.hpp benchmarks/types/benchmarks.vrutoyTopLevelContainer.hpp benchmarks/types/benchmarks.vrutoytopLevelUnionEmpty.hpp benchmarks/types/benchmarks.vrutoytopLevelUnionBig.hpp benchmarks/types/benchmarks.vruposition.hpp __common_namespace/types/true.hpp benchmarks/types/benchmarks.vruhash.hpp $(CC) $(CFLAGS) -o __build/__factory.o -c __factory/details.cpp __build/__common_namespace.o: __common_namespace/details.cpp __common_namespace/details.cpp __common_namespace/headers/dictionary.hpp __common_namespace/headers/dictionaryAny.hpp __common_namespace/headers/dictionaryField.hpp __common_namespace/headers/dictionaryFieldAny.hpp __common_namespace/headers/int.hpp __common_namespace/headers/int32.hpp __common_namespace/headers/int64.hpp __common_namespace/headers/long.hpp __common_namespace/headers/string.hpp __common_namespace/headers/true.hpp __common_namespace/headers/vector.hpp $(CC) $(CFLAGS) -o __build/__common_namespace.o -c __common_namespace/details.cpp __build/benchmarks.o: benchmarks/details.cpp benchmarks/details.cpp benchmarks/headers/benchmarks.VrutoyTopLevelUnion.hpp benchmarks/headers/benchmarks.vruhash.hpp benchmarks/headers/benchmarks.vruposition.hpp benchmarks/headers/benchmarks.vrutoyPositions.hpp benchmarks/headers/benchmarks.vrutoyTopLevelContainer.hpp benchmarks/headers/benchmarks.vrutoyTopLevelContainerWithDependency.hpp benchmarks/headers/benchmarks.vrutoytopLevelUnionBig.hpp benchmarks/headers/benchmarks.vrutoytopLevelUnionEmpty.hpp benchmarks/headers/benchmarks_vector.hpp $(CC) $(CFLAGS) -o __build/benchmarks.o -c benchmarks/details.cpp -__build/cases.o: cases/details.cpp cases/details.cpp cases/headers/cases.TestEnum.hpp cases/headers/cases.TestEnumItems.hpp cases/headers/cases.TestUnion.hpp cases/headers/cases.myCycle1.hpp cases/headers/cases.myCycle2.hpp cases/headers/cases.myCycle3.hpp cases/headers/cases.replace7.hpp cases/headers/cases.replace7plus.hpp cases/headers/cases.replace7plusplus.hpp cases/headers/cases.testAllPossibleFieldConfigs.hpp cases/headers/cases.testAllPossibleFieldConfigsContainer.hpp cases/headers/cases.testArray.hpp cases/headers/cases.testBeforeReadBitValidation.hpp cases/headers/cases.testDictAny.hpp cases/headers/cases.testDictInt.hpp cases/headers/cases.testDictString.hpp cases/headers/cases.testEnumContainer.hpp cases/headers/cases.testLocalFieldmask.hpp cases/headers/cases.testMaybe.hpp cases/headers/cases.testOutFieldMask.hpp cases/headers/cases.testOutFieldMaskContainer.hpp cases/headers/cases.testRecursiveFieldMask.hpp cases/headers/cases.testTuple.hpp cases/headers/cases.testUnion1.hpp cases/headers/cases.testUnion2.hpp cases/headers/cases.testUnionContainer.hpp cases/headers/cases.testVector.hpp cases/headers/cases_int.hpp cases/headers/cases_tuple.hpp cases/headers/cases_vector.hpp +__build/cases.o: cases/details.cpp cases/details.cpp cases/headers/cases.TestEnum.hpp cases/headers/cases.TestEnumItems.hpp cases/headers/cases.TestUnion.hpp cases/headers/cases.inplace1.hpp cases/headers/cases.inplace2.hpp cases/headers/cases.inplace3.hpp cases/headers/cases.myCycle1.hpp cases/headers/cases.myCycle2.hpp cases/headers/cases.myCycle3.hpp cases/headers/cases.replace7.hpp cases/headers/cases.replace7plus.hpp cases/headers/cases.replace7plusplus.hpp cases/headers/cases.testAllPossibleFieldConfigs.hpp cases/headers/cases.testAllPossibleFieldConfigsContainer.hpp cases/headers/cases.testArray.hpp cases/headers/cases.testBeforeReadBitValidation.hpp cases/headers/cases.testDictAny.hpp cases/headers/cases.testDictInt.hpp cases/headers/cases.testDictString.hpp cases/headers/cases.testEnumContainer.hpp cases/headers/cases.testInplaceStructArgs.hpp cases/headers/cases.testInplaceStructArgs2.hpp cases/headers/cases.testLocalFieldmask.hpp cases/headers/cases.testMaybe.hpp cases/headers/cases.testOutFieldMask.hpp cases/headers/cases.testOutFieldMaskContainer.hpp cases/headers/cases.testRecursiveFieldMask.hpp cases/headers/cases.testTuple.hpp cases/headers/cases.testUnion1.hpp cases/headers/cases.testUnion2.hpp cases/headers/cases.testUnionContainer.hpp cases/headers/cases.testVector.hpp cases/headers/cases_int.hpp cases/headers/cases_pair.hpp cases/headers/cases_tuple.hpp cases/headers/cases_vector.hpp $(CC) $(CFLAGS) -o __build/cases.o -c cases/details.cpp __build/cases_bytes.o: cases_bytes/details.cpp cases_bytes/details.cpp cases_bytes/headers/cases_bytes.TestEnum.hpp cases_bytes/headers/cases_bytes.TestEnumItems.hpp cases_bytes/headers/cases_bytes.testArray.hpp cases_bytes/headers/cases_bytes.testDictAny.hpp cases_bytes/headers/cases_bytes.testDictInt.hpp cases_bytes/headers/cases_bytes.testDictString.hpp cases_bytes/headers/cases_bytes.testDictStringString.hpp cases_bytes/headers/cases_bytes.testEnumContainer.hpp cases_bytes/headers/cases_bytes.testTuple.hpp cases_bytes/headers/cases_bytes.testVector.hpp cases_bytes/headers/cases_bytes_dictionary.hpp cases_bytes/headers/cases_bytes_dictionaryField.hpp cases_bytes/headers/cases_bytes_string.hpp cases_bytes/headers/cases_bytes_tuple.hpp cases_bytes/headers/cases_bytes_vector.hpp $(CC) $(CFLAGS) -o __build/cases_bytes.o -c cases_bytes/details.cpp diff --git a/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/types/tuple.hpp b/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/types/tuple.hpp index 5238759..9f00b0d 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/types/tuple.hpp +++ b/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/types/tuple.hpp @@ -3,6 +3,11 @@ #include "../../a_tlgen_helpers_code.hpp" +namespace tl2 { +template +using Tuple = std::vector; +} // namespace tl2 + namespace tl2 { template using Tuplen = std::array; diff --git a/internal/tlcodegen/test/gen/cases_cpp/__factory/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/__factory/details.cpp index 6beb188..95cd67d 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/__factory/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/__factory/details.cpp @@ -10,6 +10,8 @@ #include "../cases/types/cases.testOutFieldMaskContainer.hpp" #include "../cases/types/cases.testMaybe.hpp" #include "../cases/types/cases.testLocalFieldmask.hpp" +#include "../cases/types/cases.testInplaceStructArgs2.hpp" +#include "../cases/types/cases.testInplaceStructArgs.hpp" #include "../cases/types/cases.testEnumContainer.hpp" #include "../cases/types/cases.testDictString.hpp" #include "../cases/types/cases.testDictInt.hpp" @@ -571,6 +573,38 @@ void tl2::factory::set_all_factories() { return std::make_unique(); }); + struct tl2_cases_TestInplaceStructArgs_tl_object : public tl2::meta::tl_object { + tl2::cases::TestInplaceStructArgs object; + + bool read(basictl::tl_istream &s) override {return object.read(s);} + bool write(basictl::tl_ostream &s) override {return object.write(s);} + + bool read_boxed(basictl::tl_istream &s) override {return object.read_boxed(s);} + bool write_boxed(basictl::tl_ostream &s) override {return object.write_boxed(s);} + + bool write_json(std::ostream &s) override {return object.write_json(s);} + + }; + tl2::meta::set_create_object_by_name("cases.testInplaceStructArgs", []() -> std::unique_ptr { + return std::make_unique(); + }); + + struct tl2_cases_TestInplaceStructArgs2_tl_object : public tl2::meta::tl_object { + tl2::cases::TestInplaceStructArgs2 object; + + bool read(basictl::tl_istream &s) override {return object.read(s);} + bool write(basictl::tl_ostream &s) override {return object.write(s);} + + bool read_boxed(basictl::tl_istream &s) override {return object.read_boxed(s);} + bool write_boxed(basictl::tl_ostream &s) override {return object.write_boxed(s);} + + bool write_json(std::ostream &s) override {return object.write_json(s);} + + }; + tl2::meta::set_create_object_by_name("cases.testInplaceStructArgs2", []() -> std::unique_ptr { + return std::make_unique(); + }); + struct tl2_cases_TestLocalFieldmask_tl_object : public tl2::meta::tl_object { tl2::cases::TestLocalFieldmask object; diff --git a/internal/tlcodegen/test/gen/cases_cpp/__meta/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/__meta/details.cpp index 3de7366..55cee6a 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/__meta/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/__meta/details.cpp @@ -155,6 +155,12 @@ tl_items::tl_items() { auto item3412607537 = std::shared_ptr(new tl2::meta::tl_item{.tag=0xcb684231,.annotations=0x0,.name="cases.testEnumContainer",.create_object=no_object_generator,.create_function=no_function_generator}); (this->items)["cases.testEnumContainer"] = item3412607537; (this->items_by_tag)[0xcb684231] = item3412607537; + auto item2850309150 = std::shared_ptr(new tl2::meta::tl_item{.tag=0xa9e4441e,.annotations=0x0,.name="cases.testInplaceStructArgs",.create_object=no_object_generator,.create_function=no_function_generator}); + (this->items)["cases.testInplaceStructArgs"] = item2850309150; + (this->items_by_tag)[0xa9e4441e] = item2850309150; + auto item2862556288 = std::shared_ptr(new tl2::meta::tl_item{.tag=0xaa9f2480,.annotations=0x0,.name="cases.testInplaceStructArgs2",.create_object=no_object_generator,.create_function=no_function_generator}); + (this->items)["cases.testInplaceStructArgs2"] = item2862556288; + (this->items_by_tag)[0xaa9f2480] = item2862556288; auto item4136621049 = std::shared_ptr(new tl2::meta::tl_item{.tag=0xf68fd3f9,.annotations=0x0,.name="cases.testLocalFieldmask",.create_object=no_object_generator,.create_function=no_function_generator}); (this->items)["cases.testLocalFieldmask"] = item4136621049; (this->items_by_tag)[0xf68fd3f9] = item4136621049; diff --git a/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp index 8c251ee..b5e303e 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp @@ -12,6 +12,9 @@ #include "headers/cases.testMaybe.hpp" #include "headers/cases_int.hpp" #include "headers/cases.testLocalFieldmask.hpp" +#include "headers/cases.testInplaceStructArgs2.hpp" +#include "headers/cases_pair.hpp" +#include "headers/cases.testInplaceStructArgs.hpp" #include "headers/cases.testEnumContainer.hpp" #include "headers/cases.testDictString.hpp" #include "headers/cases.testDictInt.hpp" @@ -26,6 +29,9 @@ #include "headers/cases.myCycle1.hpp" #include "headers/cases.myCycle2.hpp" #include "headers/cases.myCycle3.hpp" +#include "headers/cases.inplace1.hpp" +#include "headers/cases.inplace2.hpp" +#include "headers/cases.inplace3.hpp" #include "headers/cases.TestEnum.hpp" #include "headers/cases.TestEnumItems.hpp" #include "../__common_namespace/headers/dictionary.hpp" @@ -34,6 +40,74 @@ #include "../__common_namespace/headers/true.hpp" +void tl2::details::BuiltinTuple2IntReset(std::array& item) { + for(auto && el : item) { + el = 0; + } +} + +bool tl2::details::BuiltinTuple2IntWriteJSON(std::ostream &s, const std::array& item) { + s << "["; + size_t index = 0; + for(auto && el : item) { + s << el; + if (index != item.size() - 1) { + s << ","; + } + index++; + } + s << "]"; + return true; +} + +bool tl2::details::BuiltinTuple2IntRead(::basictl::tl_istream & s, std::array& item) { + for(auto && el : item) { + if (!s.int_read(el)) { return false; } + } + return true; +} + +bool tl2::details::BuiltinTuple2IntWrite(::basictl::tl_ostream & s, const std::array& item) { + for(const auto & el : item) { + if (!s.int_write(el)) { return false;} + } + return true; +} + +void tl2::details::BuiltinTuple2PairTupleIntTupleIntReset(std::array<::tl2::Pair, std::vector>, 2>& item) { + for(auto && el : item) { + ::tl2::details::PairTupleIntTupleIntReset(el); + } +} + +bool tl2::details::BuiltinTuple2PairTupleIntTupleIntWriteJSON(std::ostream &s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + s << "["; + size_t index = 0; + for(auto && el : item) { + if (!::tl2::details::PairTupleIntTupleIntWriteJSON(s, el, nat_tXn, nat_tYn)) { return false; } + if (index != item.size() - 1) { + s << ","; + } + index++; + } + s << "]"; + return true; +} + +bool tl2::details::BuiltinTuple2PairTupleIntTupleIntRead(::basictl::tl_istream & s, std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + for(auto && el : item) { + if (!::tl2::details::PairTupleIntTupleIntRead(s, el, nat_tXn, nat_tYn)) { return false; } + } + return true; +} + +bool tl2::details::BuiltinTuple2PairTupleIntTupleIntWrite(::basictl::tl_ostream & s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + for(const auto & el : item) { + if (!::tl2::details::PairTupleIntTupleIntWrite(s, el, nat_tXn, nat_tYn)) { return false; } + } + return true; +} + void tl2::details::BuiltinTuple4IntReset(std::array& item) { for(auto && el : item) { el = 0; @@ -148,6 +222,86 @@ bool tl2::details::BuiltinTupleTupleIntWrite(::basictl::tl_ostream & s, const st return true; } +void tl2::details::BuiltinTupleTupleInt2Reset(std::vector>& item) { + item.resize(0); +} + +bool tl2::details::BuiltinTupleTupleInt2WriteJSON(std::ostream & s, const std::vector>& item, uint32_t nat_n) { + if (item.size() != nat_n) { + // TODO add exception + return false; + } + s << "["; + size_t index = 0; + for(const auto & el : item) { + if (!::tl2::details::BuiltinTuple2IntWriteJSON(s, el)) { return false; } + if (index != item.size() - 1) { + s << ","; + } + index++; + } + s << "]"; + return true; +} + +bool tl2::details::BuiltinTupleTupleInt2Read(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n) { + // TODO - check length sanity + item.resize(nat_n); + for(auto && el : item) { + if (!::tl2::details::BuiltinTuple2IntRead(s, el)) { return false; } + } + return true; +} + +bool tl2::details::BuiltinTupleTupleInt2Write(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n) { + if (item.size() != nat_n) + return s.set_error_sequence_length(); + for(const auto & el : item) { + if (!::tl2::details::BuiltinTuple2IntWrite(s, el)) { return false; } + } + return true; +} + +void tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Reset(std::vector, std::vector>, 2>>& item) { + item.resize(0); +} + +bool tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(std::ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn) { + if (item.size() != nat_n) { + // TODO add exception + return false; + } + s << "["; + size_t index = 0; + for(const auto & el : item) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntWriteJSON(s, el, nat_ttXn, nat_ttYn)) { return false; } + if (index != item.size() - 1) { + s << ","; + } + index++; + } + s << "]"; + return true; +} + +bool tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn) { + // TODO - check length sanity + item.resize(nat_n); + for(auto && el : item) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntRead(s, el, nat_ttXn, nat_ttYn)) { return false; } + } + return true; +} + +bool tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn) { + if (item.size() != nat_n) + return s.set_error_sequence_length(); + for(const auto & el : item) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntWrite(s, el, nat_ttXn, nat_ttYn)) { return false; } + } + return true; +} + void tl2::details::BuiltinVectorIntReset(std::vector& item) { item.resize(0); // TODO - unwrap } @@ -185,6 +339,198 @@ bool tl2::details::BuiltinVectorIntWrite(::basictl::tl_ostream & s, const std::v return true; } +void tl2::details::CasesInplace1IntReset(::tl2::cases::Inplace1& item) { + ::tl2::details::CasesInplace2IntReset(item.value); +} + +bool tl2::details::CasesInplace1IntWriteJSON(std::ostream& s, const ::tl2::cases::Inplace1& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::CasesInplace2IntWriteJSON(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace1IntRead(::basictl::tl_istream & s, ::tl2::cases::Inplace1& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::CasesInplace2IntRead(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + return true; +} + +bool tl2::details::CasesInplace1IntWrite(::basictl::tl_ostream & s, const ::tl2::cases::Inplace1& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::CasesInplace2IntWrite(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + return true; +} + +bool tl2::details::CasesInplace1IntReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace1& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_read_exact_tag(0x5533e8e9)) { return false; } + return tl2::details::CasesInplace1IntRead(s, item, nat_a1, nat_a2, nat_a3); +} + +bool tl2::details::CasesInplace1IntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace1& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_write(0x5533e8e9)) { return false; } + return tl2::details::CasesInplace1IntWrite(s, item, nat_a1, nat_a2, nat_a3); +} + +void tl2::details::CasesInplace1PairTupleIntTupleIntReset(::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item) { + ::tl2::details::CasesInplace2PairTupleIntTupleIntReset(item.value); +} + +bool tl2::details::CasesInplace1PairTupleIntTupleIntWriteJSON(std::ostream& s, const ::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::CasesInplace2PairTupleIntTupleIntWriteJSON(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace1PairTupleIntTupleIntRead(::basictl::tl_istream & s, ::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!::tl2::details::CasesInplace2PairTupleIntTupleIntRead(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + return true; +} + +bool tl2::details::CasesInplace1PairTupleIntTupleIntWrite(::basictl::tl_ostream & s, const ::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!::tl2::details::CasesInplace2PairTupleIntTupleIntWrite(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + return true; +} + +bool tl2::details::CasesInplace1PairTupleIntTupleIntReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!s.nat_read_exact_tag(0x5533e8e9)) { return false; } + return tl2::details::CasesInplace1PairTupleIntTupleIntRead(s, item, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn); +} + +bool tl2::details::CasesInplace1PairTupleIntTupleIntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace1<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!s.nat_write(0x5533e8e9)) { return false; } + return tl2::details::CasesInplace1PairTupleIntTupleIntWrite(s, item, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn); +} + +void tl2::details::CasesInplace2IntReset(::tl2::cases::Inplace2& item) { + ::tl2::details::CasesInplace3TupleInt2Reset(item.value); +} + +bool tl2::details::CasesInplace2IntWriteJSON(std::ostream& s, const ::tl2::cases::Inplace2& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::CasesInplace3TupleInt2WriteJSON(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace2IntRead(::basictl::tl_istream & s, ::tl2::cases::Inplace2& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::CasesInplace3TupleInt2Read(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + return true; +} + +bool tl2::details::CasesInplace2IntWrite(::basictl::tl_ostream & s, const ::tl2::cases::Inplace2& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::CasesInplace3TupleInt2Write(s, item.value, nat_a2, nat_a3, nat_a1)) { return false; } + return true; +} + +bool tl2::details::CasesInplace2IntReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace2& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_read_exact_tag(0x869fcff5)) { return false; } + return tl2::details::CasesInplace2IntRead(s, item, nat_a1, nat_a2, nat_a3); +} + +bool tl2::details::CasesInplace2IntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace2& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_write(0x869fcff5)) { return false; } + return tl2::details::CasesInplace2IntWrite(s, item, nat_a1, nat_a2, nat_a3); +} + +void tl2::details::CasesInplace2PairTupleIntTupleIntReset(::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item) { + ::tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Reset(item.value); +} + +bool tl2::details::CasesInplace2PairTupleIntTupleIntWriteJSON(std::ostream& s, const ::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::CasesInplace3TuplePairTupleIntTupleInt2WriteJSON(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace2PairTupleIntTupleIntRead(::basictl::tl_istream & s, ::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!::tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Read(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + return true; +} + +bool tl2::details::CasesInplace2PairTupleIntTupleIntWrite(::basictl::tl_ostream & s, const ::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!::tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Write(s, item.value, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn)) { return false; } + return true; +} + +bool tl2::details::CasesInplace2PairTupleIntTupleIntReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!s.nat_read_exact_tag(0x869fcff5)) { return false; } + return tl2::details::CasesInplace2PairTupleIntTupleIntRead(s, item, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn); +} + +bool tl2::details::CasesInplace2PairTupleIntTupleIntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace2<::tl2::Pair, std::vector>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XXn, uint32_t nat_XYn) { + if (!s.nat_write(0x869fcff5)) { return false; } + return tl2::details::CasesInplace2PairTupleIntTupleIntWrite(s, item, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn); +} + +void tl2::details::CasesInplace3TupleInt2Reset(::tl2::cases::Inplace3>& item) { + ::tl2::details::PairTupleTupleInt2TupleTupleInt2Reset(item.value); +} + +bool tl2::details::CasesInplace3TupleInt2WriteJSON(std::ostream& s, const ::tl2::cases::Inplace3>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::PairTupleTupleInt2TupleTupleInt2WriteJSON(s, item.value, nat_a2, nat_a3)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace3TupleInt2Read(::basictl::tl_istream & s, ::tl2::cases::Inplace3>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::PairTupleTupleInt2TupleTupleInt2Read(s, item.value, nat_a2, nat_a3)) { return false; } + return true; +} + +bool tl2::details::CasesInplace3TupleInt2Write(::basictl::tl_ostream & s, const ::tl2::cases::Inplace3>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!::tl2::details::PairTupleTupleInt2TupleTupleInt2Write(s, item.value, nat_a2, nat_a3)) { return false; } + return true; +} + +bool tl2::details::CasesInplace3TupleInt2ReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace3>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_read_exact_tag(0x4ffb95cb)) { return false; } + return tl2::details::CasesInplace3TupleInt2Read(s, item, nat_a1, nat_a2, nat_a3); +} + +bool tl2::details::CasesInplace3TupleInt2WriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace3>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3) { + if (!s.nat_write(0x4ffb95cb)) { return false; } + return tl2::details::CasesInplace3TupleInt2Write(s, item, nat_a1, nat_a2, nat_a3); +} + +void tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Reset(::tl2::cases::Inplace3, std::vector>, 2>>& item) { + ::tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Reset(item.value); +} + +bool tl2::details::CasesInplace3TuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const ::tl2::cases::Inplace3, std::vector>, 2>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XtXn, uint32_t nat_XtYn) { + s << "{"; + s << "\"value\":"; + if (!::tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2WriteJSON(s, item.value, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, ::tl2::cases::Inplace3, std::vector>, 2>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XtXn, uint32_t nat_XtYn) { + if (!::tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Read(s, item.value, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3)) { return false; } + return true; +} + +bool tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const ::tl2::cases::Inplace3, std::vector>, 2>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XtXn, uint32_t nat_XtYn) { + if (!::tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Write(s, item.value, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3)) { return false; } + return true; +} + +bool tl2::details::CasesInplace3TuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, ::tl2::cases::Inplace3, std::vector>, 2>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XtXn, uint32_t nat_XtYn) { + if (!s.nat_read_exact_tag(0x4ffb95cb)) { return false; } + return tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Read(s, item, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn); +} + +bool tl2::details::CasesInplace3TuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::Inplace3, std::vector>, 2>>& item, uint32_t nat_a1, uint32_t nat_a2, uint32_t nat_a3, uint32_t nat_XtXn, uint32_t nat_XtYn) { + if (!s.nat_write(0x4ffb95cb)) { return false; } + return tl2::details::CasesInplace3TuplePairTupleIntTupleInt2Write(s, item, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn); +} + bool tl2::cases::MyCycle1::write_json(std::ostream& s)const { if (!::tl2::details::CasesMyCycle1WriteJSON(s, *this)) { return false; } return true; @@ -1592,6 +1938,190 @@ bool tl2::details::CasesTestEnumContainerWriteBoxed(::basictl::tl_ostream & s, c return tl2::details::CasesTestEnumContainerWrite(s, item); } +bool tl2::cases::TestInplaceStructArgs::write_json(std::ostream& s)const { + if (!::tl2::details::CasesTestInplaceStructArgsWriteJSON(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs::read(::basictl::tl_istream & s) { + if (!::tl2::details::CasesTestInplaceStructArgsRead(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs::write(::basictl::tl_ostream & s)const { + if (!::tl2::details::CasesTestInplaceStructArgsWrite(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs::read_boxed(::basictl::tl_istream & s) { + if (!::tl2::details::CasesTestInplaceStructArgsReadBoxed(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs::write_boxed(::basictl::tl_ostream & s)const { + if (!::tl2::details::CasesTestInplaceStructArgsWriteBoxed(s, *this)) { return false; } + return true; +} + +void tl2::details::CasesTestInplaceStructArgsReset(::tl2::cases::TestInplaceStructArgs& item) { + item.a1 = 0; + item.a2 = 0; + item.a3 = 0; + ::tl2::details::CasesInplace1IntReset(item.arg); +} + +bool tl2::details::CasesTestInplaceStructArgsWriteJSON(std::ostream& s, const ::tl2::cases::TestInplaceStructArgs& item) { + auto add_comma = false; + s << "{"; + if (item.a1 != 0) { + add_comma = true; + s << "\"a1\":"; + s << item.a1; + } + if (item.a2 != 0) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"a2\":"; + s << item.a2; + } + if (item.a3 != 0) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"a3\":"; + s << item.a3; + } + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"arg\":"; + if (!::tl2::details::CasesInplace1IntWriteJSON(s, item.arg, item.a1, item.a2, item.a3)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesTestInplaceStructArgsRead(::basictl::tl_istream & s, ::tl2::cases::TestInplaceStructArgs& item) { + if (!s.nat_read(item.a1)) { return false; } + if (!s.nat_read(item.a2)) { return false; } + if (!s.nat_read(item.a3)) { return false; } + if (!::tl2::details::CasesInplace1IntRead(s, item.arg, item.a1, item.a2, item.a3)) { return false; } + return true; +} + +bool tl2::details::CasesTestInplaceStructArgsWrite(::basictl::tl_ostream & s, const ::tl2::cases::TestInplaceStructArgs& item) { + if (!s.nat_write(item.a1)) { return false;} + if (!s.nat_write(item.a2)) { return false;} + if (!s.nat_write(item.a3)) { return false;} + if (!::tl2::details::CasesInplace1IntWrite(s, item.arg, item.a1, item.a2, item.a3)) { return false; } + return true; +} + +bool tl2::details::CasesTestInplaceStructArgsReadBoxed(::basictl::tl_istream & s, ::tl2::cases::TestInplaceStructArgs& item) { + if (!s.nat_read_exact_tag(0xa9e4441e)) { return false; } + return tl2::details::CasesTestInplaceStructArgsRead(s, item); +} + +bool tl2::details::CasesTestInplaceStructArgsWriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::TestInplaceStructArgs& item) { + if (!s.nat_write(0xa9e4441e)) { return false; } + return tl2::details::CasesTestInplaceStructArgsWrite(s, item); +} + +bool tl2::cases::TestInplaceStructArgs2::write_json(std::ostream& s)const { + if (!::tl2::details::CasesTestInplaceStructArgs2WriteJSON(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs2::read(::basictl::tl_istream & s) { + if (!::tl2::details::CasesTestInplaceStructArgs2Read(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs2::write(::basictl::tl_ostream & s)const { + if (!::tl2::details::CasesTestInplaceStructArgs2Write(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs2::read_boxed(::basictl::tl_istream & s) { + if (!::tl2::details::CasesTestInplaceStructArgs2ReadBoxed(s, *this)) { return false; } + return true; +} + +bool tl2::cases::TestInplaceStructArgs2::write_boxed(::basictl::tl_ostream & s)const { + if (!::tl2::details::CasesTestInplaceStructArgs2WriteBoxed(s, *this)) { return false; } + return true; +} + +void tl2::details::CasesTestInplaceStructArgs2Reset(::tl2::cases::TestInplaceStructArgs2& item) { + item.a1 = 0; + item.a2 = 0; + item.a3 = 0; + ::tl2::details::CasesInplace1PairTupleIntTupleIntReset(item.arg); +} + +bool tl2::details::CasesTestInplaceStructArgs2WriteJSON(std::ostream& s, const ::tl2::cases::TestInplaceStructArgs2& item) { + auto add_comma = false; + s << "{"; + if (item.a1 != 0) { + add_comma = true; + s << "\"a1\":"; + s << item.a1; + } + if (item.a2 != 0) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"a2\":"; + s << item.a2; + } + if (item.a3 != 0) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"a3\":"; + s << item.a3; + } + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"arg\":"; + if (!::tl2::details::CasesInplace1PairTupleIntTupleIntWriteJSON(s, item.arg, item.a1, item.a2, item.a3, item.a3, item.a2)) { return false; } + s << "}"; + return true; +} + +bool tl2::details::CasesTestInplaceStructArgs2Read(::basictl::tl_istream & s, ::tl2::cases::TestInplaceStructArgs2& item) { + if (!s.nat_read(item.a1)) { return false; } + if (!s.nat_read(item.a2)) { return false; } + if (!s.nat_read(item.a3)) { return false; } + if (!::tl2::details::CasesInplace1PairTupleIntTupleIntRead(s, item.arg, item.a1, item.a2, item.a3, item.a3, item.a2)) { return false; } + return true; +} + +bool tl2::details::CasesTestInplaceStructArgs2Write(::basictl::tl_ostream & s, const ::tl2::cases::TestInplaceStructArgs2& item) { + if (!s.nat_write(item.a1)) { return false;} + if (!s.nat_write(item.a2)) { return false;} + if (!s.nat_write(item.a3)) { return false;} + if (!::tl2::details::CasesInplace1PairTupleIntTupleIntWrite(s, item.arg, item.a1, item.a2, item.a3, item.a3, item.a2)) { return false; } + return true; +} + +bool tl2::details::CasesTestInplaceStructArgs2ReadBoxed(::basictl::tl_istream & s, ::tl2::cases::TestInplaceStructArgs2& item) { + if (!s.nat_read_exact_tag(0xaa9f2480)) { return false; } + return tl2::details::CasesTestInplaceStructArgs2Read(s, item); +} + +bool tl2::details::CasesTestInplaceStructArgs2WriteBoxed(::basictl::tl_ostream & s, const ::tl2::cases::TestInplaceStructArgs2& item) { + if (!s.nat_write(0xaa9f2480)) { return false; } + return tl2::details::CasesTestInplaceStructArgs2Write(s, item); +} + bool tl2::cases::TestLocalFieldmask::write_json(std::ostream& s)const { if (!::tl2::details::CasesTestLocalFieldmaskWriteJSON(s, *this)) { return false; } return true; @@ -2466,6 +2996,205 @@ bool tl2::details::IntMaybeWriteBoxed(::basictl::tl_ostream & s, const std::opti return true; } +void tl2::details::PairTupleIntTupleIntReset(::tl2::Pair, std::vector>& item) { + item.x.clear(); + item.y.clear(); +} + +bool tl2::details::PairTupleIntTupleIntWriteJSON(std::ostream& s, const ::tl2::Pair, std::vector>& item, uint32_t nat_X, uint32_t nat_Y) { + auto add_comma = false; + s << "{"; + if ((item.x.size() != 0) || (nat_X != 0)) { + add_comma = true; + s << "\"x\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.x, nat_X)) { return false; } + } + if ((item.y.size() != 0) || (nat_Y != 0)) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"y\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.y, nat_Y)) { return false; } + } + s << "}"; + return true; +} + +bool tl2::details::PairTupleIntTupleIntRead(::basictl::tl_istream & s, ::tl2::Pair, std::vector>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!::tl2::details::BuiltinTupleIntRead(s, item.x, nat_X)) { return false; } + if (!::tl2::details::BuiltinTupleIntRead(s, item.y, nat_Y)) { return false; } + return true; +} + +bool tl2::details::PairTupleIntTupleIntWrite(::basictl::tl_ostream & s, const ::tl2::Pair, std::vector>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!::tl2::details::BuiltinTupleIntWrite(s, item.x, nat_X)) { return false; } + if (!::tl2::details::BuiltinTupleIntWrite(s, item.y, nat_Y)) { return false; } + return true; +} + +bool tl2::details::PairTupleIntTupleIntReadBoxed(::basictl::tl_istream & s, ::tl2::Pair, std::vector>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!s.nat_read_exact_tag(0xf01604df)) { return false; } + return tl2::details::PairTupleIntTupleIntRead(s, item, nat_X, nat_Y); +} + +bool tl2::details::PairTupleIntTupleIntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::Pair, std::vector>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!s.nat_write(0xf01604df)) { return false; } + return tl2::details::PairTupleIntTupleIntWrite(s, item, nat_X, nat_Y); +} + +void tl2::details::PairTupleTupleInt2TupleTupleInt2Reset(::tl2::Pair>, std::vector>>& item) { + item.x.clear(); + item.y.clear(); +} + +bool tl2::details::PairTupleTupleInt2TupleTupleInt2WriteJSON(std::ostream& s, const ::tl2::Pair>, std::vector>>& item, uint32_t nat_X, uint32_t nat_Y) { + auto add_comma = false; + s << "{"; + if ((item.x.size() != 0) || (nat_X != 0)) { + add_comma = true; + s << "\"x\":"; + if (!::tl2::details::BuiltinTupleTupleInt2WriteJSON(s, item.x, nat_X)) { return false; } + } + if ((item.y.size() != 0) || (nat_Y != 0)) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"y\":"; + if (!::tl2::details::BuiltinTupleTupleInt2WriteJSON(s, item.y, nat_Y)) { return false; } + } + s << "}"; + return true; +} + +bool tl2::details::PairTupleTupleInt2TupleTupleInt2Read(::basictl::tl_istream & s, ::tl2::Pair>, std::vector>>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!::tl2::details::BuiltinTupleTupleInt2Read(s, item.x, nat_X)) { return false; } + if (!::tl2::details::BuiltinTupleTupleInt2Read(s, item.y, nat_Y)) { return false; } + return true; +} + +bool tl2::details::PairTupleTupleInt2TupleTupleInt2Write(::basictl::tl_ostream & s, const ::tl2::Pair>, std::vector>>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!::tl2::details::BuiltinTupleTupleInt2Write(s, item.x, nat_X)) { return false; } + if (!::tl2::details::BuiltinTupleTupleInt2Write(s, item.y, nat_Y)) { return false; } + return true; +} + +bool tl2::details::PairTupleTupleInt2TupleTupleInt2ReadBoxed(::basictl::tl_istream & s, ::tl2::Pair>, std::vector>>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!s.nat_read_exact_tag(0xf01604df)) { return false; } + return tl2::details::PairTupleTupleInt2TupleTupleInt2Read(s, item, nat_X, nat_Y); +} + +bool tl2::details::PairTupleTupleInt2TupleTupleInt2WriteBoxed(::basictl::tl_ostream & s, const ::tl2::Pair>, std::vector>>& item, uint32_t nat_X, uint32_t nat_Y) { + if (!s.nat_write(0xf01604df)) { return false; } + return tl2::details::PairTupleTupleInt2TupleTupleInt2Write(s, item, nat_X, nat_Y); +} + +void tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Reset(::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item) { + item.x.clear(); + item.y.clear(); +} + +bool tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const ::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item, uint32_t nat_XttXn, uint32_t nat_XttYn, uint32_t nat_Xn, uint32_t nat_YttXn, uint32_t nat_YttYn, uint32_t nat_Yn) { + auto add_comma = false; + s << "{"; + if ((item.x.size() != 0) || (nat_XttXn != 0)) { + add_comma = true; + s << "\"x\":"; + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(s, item.x, nat_Xn, nat_XttXn, nat_XttYn)) { return false; } + } + if ((item.y.size() != 0) || (nat_YttXn != 0)) { + if (add_comma) { + s << ","; + } + add_comma = true; + s << "\"y\":"; + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(s, item.y, nat_Yn, nat_YttXn, nat_YttYn)) { return false; } + } + s << "}"; + return true; +} + +bool tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, ::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item, uint32_t nat_XttXn, uint32_t nat_XttYn, uint32_t nat_Xn, uint32_t nat_YttXn, uint32_t nat_YttYn, uint32_t nat_Yn) { + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Read(s, item.x, nat_Xn, nat_XttXn, nat_XttYn)) { return false; } + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Read(s, item.y, nat_Yn, nat_YttXn, nat_YttYn)) { return false; } + return true; +} + +bool tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const ::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item, uint32_t nat_XttXn, uint32_t nat_XttYn, uint32_t nat_Xn, uint32_t nat_YttXn, uint32_t nat_YttYn, uint32_t nat_Yn) { + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Write(s, item.x, nat_Xn, nat_XttXn, nat_XttYn)) { return false; } + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Write(s, item.y, nat_Yn, nat_YttXn, nat_YttYn)) { return false; } + return true; +} + +bool tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, ::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item, uint32_t nat_XttXn, uint32_t nat_XttYn, uint32_t nat_Xn, uint32_t nat_YttXn, uint32_t nat_YttYn, uint32_t nat_Yn) { + if (!s.nat_read_exact_tag(0xf01604df)) { return false; } + return tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Read(s, item, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn); +} + +bool tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const ::tl2::Pair, std::vector>, 2>>, std::vector, std::vector>, 2>>>& item, uint32_t nat_XttXn, uint32_t nat_XttYn, uint32_t nat_Xn, uint32_t nat_YttXn, uint32_t nat_YttYn, uint32_t nat_Yn) { + if (!s.nat_write(0xf01604df)) { return false; } + return tl2::details::PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2Write(s, item, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn); +} + +void tl2::details::TupleIntReset(std::vector& item) { + item.clear(); +} + +bool tl2::details::TupleIntWriteJSON(std::ostream& s, const std::vector& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleIntRead(::basictl::tl_istream & s, std::vector& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleIntRead(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleIntWrite(::basictl::tl_ostream & s, const std::vector& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleIntWrite(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleIntReadBoxed(::basictl::tl_istream & s, std::vector& item, uint32_t nat_n) { + if (!s.nat_read_exact_tag(0x9770768a)) { return false; } + return tl2::details::TupleIntRead(s, item, nat_n); +} + +bool tl2::details::TupleIntWriteBoxed(::basictl::tl_ostream & s, const std::vector& item, uint32_t nat_n) { + if (!s.nat_write(0x9770768a)) { return false; } + return tl2::details::TupleIntWrite(s, item, nat_n); +} + +void tl2::details::TupleInt2Reset(std::array& item) { + ::tl2::details::BuiltinTuple2IntReset(item); +} + +bool tl2::details::TupleInt2WriteJSON(std::ostream& s, const std::array& item) { + if (!::tl2::details::BuiltinTuple2IntWriteJSON(s, item)) { return false; } + return true; +} + +bool tl2::details::TupleInt2Read(::basictl::tl_istream & s, std::array& item) { + if (!::tl2::details::BuiltinTuple2IntRead(s, item)) { return false; } + return true; +} + +bool tl2::details::TupleInt2Write(::basictl::tl_ostream & s, const std::array& item) { + if (!::tl2::details::BuiltinTuple2IntWrite(s, item)) { return false; } + return true; +} + +bool tl2::details::TupleInt2ReadBoxed(::basictl::tl_istream & s, std::array& item) { + if (!s.nat_read_exact_tag(0x9770768a)) { return false; } + return tl2::details::TupleInt2Read(s, item); +} + +bool tl2::details::TupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::array& item) { + if (!s.nat_write(0x9770768a)) { return false; } + return tl2::details::TupleInt2Write(s, item); +} + void tl2::details::TupleInt4Reset(std::array& item) { ::tl2::details::BuiltinTuple4IntReset(item); } @@ -2495,6 +3224,93 @@ bool tl2::details::TupleInt4WriteBoxed(::basictl::tl_ostream & s, const std::arr return tl2::details::TupleInt4Write(s, item); } +void tl2::details::TuplePairTupleIntTupleInt2Reset(std::array<::tl2::Pair, std::vector>, 2>& item) { + ::tl2::details::BuiltinTuple2PairTupleIntTupleIntReset(item); +} + +bool tl2::details::TuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntWriteJSON(s, item, nat_tXn, nat_tYn)) { return false; } + return true; +} + +bool tl2::details::TuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntRead(s, item, nat_tXn, nat_tYn)) { return false; } + return true; +} + +bool tl2::details::TuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + if (!::tl2::details::BuiltinTuple2PairTupleIntTupleIntWrite(s, item, nat_tXn, nat_tYn)) { return false; } + return true; +} + +bool tl2::details::TuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + if (!s.nat_read_exact_tag(0x9770768a)) { return false; } + return tl2::details::TuplePairTupleIntTupleInt2Read(s, item, nat_tXn, nat_tYn); +} + +bool tl2::details::TuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn) { + if (!s.nat_write(0x9770768a)) { return false; } + return tl2::details::TuplePairTupleIntTupleInt2Write(s, item, nat_tXn, nat_tYn); +} + +void tl2::details::TupleTupleInt2Reset(std::vector>& item) { + item.clear(); +} + +bool tl2::details::TupleTupleInt2WriteJSON(std::ostream& s, const std::vector>& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTupleInt2WriteJSON(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleTupleInt2Read(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTupleInt2Read(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleTupleInt2Write(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTupleInt2Write(s, item, nat_n)) { return false; } + return true; +} + +bool tl2::details::TupleTupleInt2ReadBoxed(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n) { + if (!s.nat_read_exact_tag(0x9770768a)) { return false; } + return tl2::details::TupleTupleInt2Read(s, item, nat_n); +} + +bool tl2::details::TupleTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n) { + if (!s.nat_write(0x9770768a)) { return false; } + return tl2::details::TupleTupleInt2Write(s, item, nat_n); +} + +void tl2::details::TupleTuplePairTupleIntTupleInt2Reset(std::vector, std::vector>, 2>>& item) { + item.clear(); +} + +bool tl2::details::TupleTuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(s, item, nat_n, nat_ttXn, nat_ttYn)) { return false; } + return true; +} + +bool tl2::details::TupleTuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Read(s, item, nat_n, nat_ttXn, nat_ttYn)) { return false; } + return true; +} + +bool tl2::details::TupleTuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n) { + if (!::tl2::details::BuiltinTupleTuplePairTupleIntTupleInt2Write(s, item, nat_n, nat_ttXn, nat_ttYn)) { return false; } + return true; +} + +bool tl2::details::TupleTuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n) { + if (!s.nat_read_exact_tag(0x9770768a)) { return false; } + return tl2::details::TupleTuplePairTupleIntTupleInt2Read(s, item, nat_ttXn, nat_ttYn, nat_n); +} + +bool tl2::details::TupleTuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n) { + if (!s.nat_write(0x9770768a)) { return false; } + return tl2::details::TupleTuplePairTupleIntTupleInt2Write(s, item, nat_ttXn, nat_ttYn, nat_n); +} + void tl2::details::VectorIntReset(std::vector& item) { item.clear(); } diff --git a/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_int.hpp b/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_int.hpp index dfc8ecc..d6c71e6 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_int.hpp +++ b/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_int.hpp @@ -5,6 +5,16 @@ namespace tl2 { namespace details { +void BuiltinTuple2IntReset(std::array& item); + +bool BuiltinTuple2IntWriteJSON(std::ostream & s, const std::array& item); +bool BuiltinTuple2IntRead(::basictl::tl_istream & s, std::array& item); +bool BuiltinTuple2IntWrite(::basictl::tl_ostream & s, const std::array& item); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + void BuiltinTuple4IntReset(std::array& item); bool BuiltinTuple4IntWriteJSON(std::ostream & s, const std::array& item); diff --git a/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_tuple.hpp b/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_tuple.hpp index 14a60aa..84c49e1 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_tuple.hpp +++ b/internal/tlcodegen/test/gen/cases_cpp/cases/headers/cases_tuple.hpp @@ -2,10 +2,55 @@ #include "../../a_tlgen_helpers_code.hpp" #include "../../__common_namespace/types/tuple.hpp" +#include "../../__common_namespace/types/pair.hpp" #include "../../__common_namespace/types/int.hpp" namespace tl2 { namespace details { +void BuiltinTupleTupleInt2Reset(std::vector>& item); + +bool BuiltinTupleTupleInt2WriteJSON(std::ostream & s, const std::vector>& item, uint32_t nat_n); +bool BuiltinTupleTupleInt2Read(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n); +bool BuiltinTupleTupleInt2Write(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + +void BuiltinTupleTuplePairTupleIntTupleInt2Reset(std::vector, std::vector>, 2>>& item); + +bool BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(std::ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn); +bool BuiltinTupleTuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn); +bool BuiltinTupleTuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_n, uint32_t nat_ttXn, uint32_t nat_ttYn); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + +void TupleIntReset(std::vector& item); + +bool TupleIntWriteJSON(std::ostream& s, const std::vector& item, uint32_t nat_n); +bool TupleIntRead(::basictl::tl_istream & s, std::vector& item, uint32_t nat_n); +bool TupleIntWrite(::basictl::tl_ostream & s, const std::vector& item, uint32_t nat_n); +bool TupleIntReadBoxed(::basictl::tl_istream & s, std::vector& item, uint32_t nat_n); +bool TupleIntWriteBoxed(::basictl::tl_ostream & s, const std::vector& item, uint32_t nat_n); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + +void TupleInt2Reset(std::array& item); + +bool TupleInt2WriteJSON(std::ostream& s, const std::array& item); +bool TupleInt2Read(::basictl::tl_istream & s, std::array& item); +bool TupleInt2Write(::basictl::tl_ostream & s, const std::array& item); +bool TupleInt2ReadBoxed(::basictl::tl_istream & s, std::array& item); +bool TupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::array& item); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + void TupleInt4Reset(std::array& item); bool TupleInt4WriteJSON(std::ostream& s, const std::array& item); @@ -16,3 +61,39 @@ bool TupleInt4WriteBoxed(::basictl::tl_ostream & s, const std::array }} // namespace tl2::details +namespace tl2 { namespace details { + +void TuplePairTupleIntTupleInt2Reset(std::array<::tl2::Pair, std::vector>, 2>& item); + +bool TuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn); +bool TuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn); +bool TuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn); +bool TuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn); +bool TuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::array<::tl2::Pair, std::vector>, 2>& item, uint32_t nat_tXn, uint32_t nat_tYn); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + +void TupleTupleInt2Reset(std::vector>& item); + +bool TupleTupleInt2WriteJSON(std::ostream& s, const std::vector>& item, uint32_t nat_n); +bool TupleTupleInt2Read(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n); +bool TupleTupleInt2Write(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n); +bool TupleTupleInt2ReadBoxed(::basictl::tl_istream & s, std::vector>& item, uint32_t nat_n); +bool TupleTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::vector>& item, uint32_t nat_n); + +}} // namespace tl2::details + +namespace tl2 { namespace details { + +void TupleTuplePairTupleIntTupleInt2Reset(std::vector, std::vector>, 2>>& item); + +bool TupleTuplePairTupleIntTupleInt2WriteJSON(std::ostream& s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n); +bool TupleTuplePairTupleIntTupleInt2Read(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n); +bool TupleTuplePairTupleIntTupleInt2Write(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n); +bool TupleTuplePairTupleIntTupleInt2ReadBoxed(::basictl::tl_istream & s, std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n); +bool TupleTuplePairTupleIntTupleInt2WriteBoxed(::basictl::tl_ostream & s, const std::vector, std::vector>, 2>>& item, uint32_t nat_ttXn, uint32_t nat_ttYn, uint32_t nat_n); + +}} // namespace tl2::details + diff --git a/internal/tlcodegen/test/gen/schema/constants/constants.go b/internal/tlcodegen/test/gen/schema/constants/constants.go index 760b01e..00d1285 100644 --- a/internal/tlcodegen/test/gen/schema/constants/constants.go +++ b/internal/tlcodegen/test/gen/schema/constants/constants.go @@ -179,5 +179,4 @@ const ( WithFlags10 = 0xcdca5ce1 // withFlags10 WithFlags11 = 0x832c48e0 // withFlags11 WithFloat = 0x071b8685 // withFloat - WithNatParam = 0xf738d0a5 // withNatParam ) diff --git a/internal/tlcodegen/test/gen/schema/meta/meta.go b/internal/tlcodegen/test/gen/schema/meta/meta.go index 9a0f723..768794a 100644 --- a/internal/tlcodegen/test/gen/schema/meta/meta.go +++ b/internal/tlcodegen/test/gen/schema/meta/meta.go @@ -14,6 +14,11 @@ import ( "github.com/vkcom/tl/pkg/basictl" ) +func SchemaGenerator() string { return "(devel)" } +func SchemaURL() string { return "" } +func SchemaCommit() string { return "" } +func SchemaTimestamp() uint32 { return 0 } + // We can create only types which have zero type arguments and zero nat arguments type Object interface { TLName() string // returns type's TL name. For union, returns constructor name depending on actual union value @@ -121,9 +126,13 @@ func CreateObjectFromNameBytes(name string) Object { } type TLItem struct { - tag uint32 - annotations uint32 - tlName string + tag uint32 + annotations uint32 + tlName string + + resultTypeContainsUnionTypes bool + argumentsTypesContainUnionTypes bool + createFunction func() Function createFunctionLong func() Function createObject func() Object @@ -138,6 +147,9 @@ func (item TLItem) CreateObject() Object { return item.createObject() } func (item TLItem) IsFunction() bool { return item.createFunction != nil } func (item TLItem) CreateFunction() Function { return item.createFunction() } +func (item TLItem) HasUnionTypesInResult() bool { return item.resultTypeContainsUnionTypes } +func (item TLItem) HasUnionTypesInArguments() bool { return item.argumentsTypesContainUnionTypes } + // For transcoding short-long version during Long ID transition func (item TLItem) HasFunctionLong() bool { return item.createFunctionLong != nil } func (item TLItem) CreateFunctionLong() Function { return item.createFunctionLong() } @@ -290,148 +302,148 @@ func fillFunction(n1 string, n2 string, item *TLItem) { } func init() { - fillFunction("antispam.getPattern#3de14136", "#3de14136", &TLItem{tag: 0x3de14136, annotations: 0x1, tlName: "antispam.getPattern"}) - fillObject("antispam.patternFound#a7688492", "#a7688492", &TLItem{tag: 0xa7688492, annotations: 0x0, tlName: "antispam.patternFound"}) - fillObject("antispam.patternNotFound#2c22e225", "#2c22e225", &TLItem{tag: 0x2c22e225, annotations: 0x0, tlName: "antispam.patternNotFound"}) - fillObject("benchObject#b697e865", "#b697e865", &TLItem{tag: 0xb697e865, annotations: 0x0, tlName: "benchObject"}) - fillObject("boolStat#92cbcbfa", "#92cbcbfa", &TLItem{tag: 0x92cbcbfa, annotations: 0x0, tlName: "boolStat"}) - fillFunction("boxedArray#95dcc8b7", "#95dcc8b7", &TLItem{tag: 0x95dcc8b7, annotations: 0x1, tlName: "boxedArray"}) - fillFunction("boxedInt#5688ebaf", "#5688ebaf", &TLItem{tag: 0x5688ebaf, annotations: 0x1, tlName: "boxedInt"}) - fillFunction("boxedString#548994db", "#548994db", &TLItem{tag: 0x548994db, annotations: 0x1, tlName: "boxedString"}) - fillFunction("boxedTuple#30c9d533", "#30c9d533", &TLItem{tag: 0x30c9d533, annotations: 0x1, tlName: "boxedTuple"}) - fillFunction("boxedTupleSlice1#25230d40", "#25230d40", &TLItem{tag: 0x25230d40, annotations: 0x1, tlName: "boxedTupleSlice1"}) - fillFunction("boxedTupleSlice2#1cdf4705", "#1cdf4705", &TLItem{tag: 0x1cdf4705, annotations: 0x1, tlName: "boxedTupleSlice2"}) - fillFunction("boxedTupleSlice3#a19b8106", "#a19b8106", &TLItem{tag: 0xa19b8106, annotations: 0x1, tlName: "boxedTupleSlice3"}) - fillFunction("boxedVector32#bbadef07", "#bbadef07", &TLItem{tag: 0xbbadef07, annotations: 0x1, tlName: "boxedVector32"}) - fillFunction("boxedVector32BoxedElem#591cecd4", "#591cecd4", &TLItem{tag: 0x591cecd4, annotations: 0x1, tlName: "boxedVector32BoxedElem"}) - fillFunction("boxedVector64#83659ba8", "#83659ba8", &TLItem{tag: 0x83659ba8, annotations: 0x1, tlName: "boxedVector64"}) - fillObject("double#2210c154", "#2210c154", &TLItem{tag: 0x2210c154, annotations: 0x0, tlName: "double"}) - fillObject("fieldConflict1#f314bd09", "#f314bd09", &TLItem{tag: 0xf314bd09, annotations: 0x0, tlName: "fieldConflict1"}) - fillObject("fieldConflict2#1bba76b8", "#1bba76b8", &TLItem{tag: 0x1bba76b8, annotations: 0x0, tlName: "fieldConflict2"}) - fillObject("fieldConflict3#2cf6e157", "#2cf6e157", &TLItem{tag: 0x2cf6e157, annotations: 0x0, tlName: "fieldConflict3"}) - fillObject("fieldConflict4#d93c186a", "#d93c186a", &TLItem{tag: 0xd93c186a, annotations: 0x0, tlName: "fieldConflict4"}) - fillObject("float#824dab22", "#824dab22", &TLItem{tag: 0x824dab22, annotations: 0x0, tlName: "float"}) - fillFunction("get_arrays#90658cdb", "#90658cdb", &TLItem{tag: 0x90658cdb, annotations: 0x1, tlName: "get_arrays"}) - fillFunction("getDouble#39711d7b", "#39711d7b", &TLItem{tag: 0x39711d7b, annotations: 0x1, tlName: "getDouble"}) - fillFunction("getFloat#25a7bc68", "#25a7bc68", &TLItem{tag: 0x25a7bc68, annotations: 0x1, tlName: "getFloat"}) - fillFunction("getMaybeIface#6b055ae4", "#6b055ae4", &TLItem{tag: 0x6b055ae4, annotations: 0x1, tlName: "getMaybeIface"}) - fillFunction("getMyDictOfInt#166f962c", "#166f962c", &TLItem{tag: 0x166f962c, annotations: 0x1, tlName: "getMyDictOfInt"}) - fillFunction("getMyDouble#b660ad10", "#b660ad10", &TLItem{tag: 0xb660ad10, annotations: 0x1, tlName: "getMyDouble"}) - fillFunction("getMyValue#b3df27fe", "#b3df27fe", &TLItem{tag: 0xb3df27fe, annotations: 0x1, tlName: "getMyValue"}) - fillFunction("getNonOptNat#67665961", "#67665961", &TLItem{tag: 0x67665961, annotations: 0x1, tlName: "getNonOptNat"}) - fillFunction("getStats#baa6da35", "#baa6da35", &TLItem{tag: 0xbaa6da35, annotations: 0x1, tlName: "getStats"}) - fillObject("int#a8509bda", "#a8509bda", &TLItem{tag: 0xa8509bda, annotations: 0x0, tlName: "int"}) - fillObject("integer#7e194796", "#7e194796", &TLItem{tag: 0x7e194796, annotations: 0x0, tlName: "integer"}) - fillObject("issue3498#f54b7b0a", "#f54b7b0a", &TLItem{tag: 0xf54b7b0a, annotations: 0x0, tlName: "issue3498"}) - fillObject("long#22076cba", "#22076cba", &TLItem{tag: 0x22076cba, annotations: 0x0, tlName: "long"}) - fillObject("myAnonMcValue#569310db", "#569310db", &TLItem{tag: 0x569310db, annotations: 0x0, tlName: "myAnonMcValue"}) - fillObject("myBoxedArray#288f64f0", "#288f64f0", &TLItem{tag: 0x288f64f0, annotations: 0x0, tlName: "myBoxedArray"}) - fillObject("myBoxedTupleSlice#25d1a1be", "#25d1a1be", &TLItem{tag: 0x25d1a1be, annotations: 0x0, tlName: "myBoxedTupleSlice"}) - fillObject("myBoxedVectorSlice#57d164bb", "#57d164bb", &TLItem{tag: 0x57d164bb, annotations: 0x0, tlName: "myBoxedVectorSlice"}) - fillObject("myDictOfInt#b8019a3d", "#b8019a3d", &TLItem{tag: 0xb8019a3d, annotations: 0x0, tlName: "myDictOfInt"}) - fillObject("myDouble#90a6c726", "#90a6c726", &TLItem{tag: 0x90a6c726, annotations: 0x0, tlName: "myDouble"}) - fillObject("myInt#c12375b7", "#c12375b7", &TLItem{tag: 0xc12375b7, annotations: 0x0, tlName: "myInt"}) - fillObject("myMaybe1#32c541fe", "#32c541fe", &TLItem{tag: 0x32c541fe, annotations: 0x0, tlName: "myMaybe1"}) - fillObject("myMaybe2#ef6d355c", "#ef6d355c", &TLItem{tag: 0xef6d355c, annotations: 0x0, tlName: "myMaybe2"}) - fillObject("myMcValue#e2ffd978", "#e2ffd978", &TLItem{tag: 0xe2ffd978, annotations: 0x0, tlName: "myMcValue"}) - fillObject("myMcValueTuple#1287d116", "#1287d116", &TLItem{tag: 0x1287d116, annotations: 0x0, tlName: "myMcValueTuple"}) - fillObject("myMcValueVector#761d6d58", "#761d6d58", &TLItem{tag: 0x761d6d58, annotations: 0x0, tlName: "myMcValueVector"}) - fillObject("myString#c8bfa969", "#c8bfa969", &TLItem{tag: 0xc8bfa969, annotations: 0x0, tlName: "myString"}) - fillObject("myTwoDicts#a859581d", "#a859581d", &TLItem{tag: 0xa859581d, annotations: 0x0, tlName: "myTwoDicts"}) - fillObject("nonOptNat#45366605", "#45366605", &TLItem{tag: 0x45366605, annotations: 0x0, tlName: "nonOptNat"}) - fillObject("pkg2.foo#e144703d", "#e144703d", &TLItem{tag: 0xe144703d, annotations: 0x0, tlName: "pkg2.foo"}) - fillObject("pkg2.t1#638206ec", "#638206ec", &TLItem{tag: 0x638206ec, annotations: 0x0, tlName: "pkg2.t1"}) - fillObject("pkg2.t2#d6e5af9c", "#d6e5af9c", &TLItem{tag: 0xd6e5af9c, annotations: 0x0, tlName: "pkg2.t2"}) - fillObject("rpcInvokeReqExtra#f3ef81a9", "#f3ef81a9", &TLItem{tag: 0xf3ef81a9, annotations: 0x0, tlName: "rpcInvokeReqExtra"}) - fillFunction("service1.add#481df8be", "#481df8be", &TLItem{tag: 0x481df8be, annotations: 0x1, tlName: "service1.add"}) - fillFunction("service1.addOrGet#6a42faad", "#6a42faad", &TLItem{tag: 0x6a42faad, annotations: 0x1, tlName: "service1.addOrGet"}) - fillFunction("service1.addOrIncr#90c4b402", "#90c4b402", &TLItem{tag: 0x90c4b402, annotations: 0x1, tlName: "service1.addOrIncr"}) - fillFunction("service1.append#04dec671", "#04dec671", &TLItem{tag: 0x04dec671, annotations: 0x1, tlName: "service1.append"}) - fillFunction("service1.cas#51851964", "#51851964", &TLItem{tag: 0x51851964, annotations: 0x1, tlName: "service1.cas"}) - fillFunction("service1.decr#eb179ce7", "#eb179ce7", &TLItem{tag: 0xeb179ce7, annotations: 0x1, tlName: "service1.decr"}) - fillFunction("service1.delete#83277767", "#83277767", &TLItem{tag: 0x83277767, annotations: 0x1, tlName: "service1.delete"}) - fillFunction("service1.disableExpiration#f1c39c2d", "#f1c39c2d", &TLItem{tag: 0xf1c39c2d, annotations: 0x1, tlName: "service1.disableExpiration"}) - fillFunction("service1.disableKeysStat#79d6160f", "#79d6160f", &TLItem{tag: 0x79d6160f, annotations: 0x1, tlName: "service1.disableKeysStat"}) - fillFunction("service1.enableExpiration#2b51ad67", "#2b51ad67", &TLItem{tag: 0x2b51ad67, annotations: 0x1, tlName: "service1.enableExpiration"}) - fillFunction("service1.enableKeysStat#29a7090e", "#29a7090e", &TLItem{tag: 0x29a7090e, annotations: 0x1, tlName: "service1.enableKeysStat"}) - fillFunction("service1.exists#e0284c9e", "#e0284c9e", &TLItem{tag: 0xe0284c9e, annotations: 0x1, tlName: "service1.exists"}) - fillFunction("service1.get#29099b19", "#29099b19", &TLItem{tag: 0x29099b19, annotations: 0x1, tlName: "service1.get"}) - fillFunction("service1.getExpireTime#5a731070", "#5a731070", &TLItem{tag: 0x5a731070, annotations: 0x1, tlName: "service1.getExpireTime"}) - fillFunction("service1.getKeysStat#06cecd58", "#06cecd58", &TLItem{tag: 0x06cecd58, annotations: 0x1, tlName: "service1.getKeysStat"}) - fillFunction("service1.getKeysStatPeriods#8cdf39e3", "#8cdf39e3", &TLItem{tag: 0x8cdf39e3, annotations: 0x1, tlName: "service1.getKeysStatPeriods"}) - fillFunction("service1.getWildcard#2f2abf13", "#2f2abf13", &TLItem{tag: 0x2f2abf13, annotations: 0x1, tlName: "service1.getWildcard"}) - fillFunction("service1.getWildcardDict#72bbc81b", "#72bbc81b", &TLItem{tag: 0x72bbc81b, annotations: 0x1, tlName: "service1.getWildcardDict"}) - fillFunction("service1.getWildcardList#56b6ead4", "#56b6ead4", &TLItem{tag: 0x56b6ead4, annotations: 0x1, tlName: "service1.getWildcardList"}) - fillFunction("service1.getWildcardWithFlags#5f6a1f78", "#5f6a1f78", &TLItem{tag: 0x5f6a1f78, annotations: 0x1, tlName: "service1.getWildcardWithFlags"}) - fillFunction("service1.incr#0f96b56e", "#0f96b56e", &TLItem{tag: 0x0f96b56e, annotations: 0x1, tlName: "service1.incr"}) - fillObject("service1.keysStat#f0f6bc68", "#f0f6bc68", &TLItem{tag: 0xf0f6bc68, annotations: 0x0, tlName: "service1.keysStat"}) - fillObject("service1.longvalue#082e0945", "#082e0945", &TLItem{tag: 0x082e0945, annotations: 0x0, tlName: "service1.longvalue"}) - fillObject("service1.longvalueWithTime#a04606ec", "#a04606ec", &TLItem{tag: 0xa04606ec, annotations: 0x0, tlName: "service1.longvalueWithTime"}) - fillObject("service1.not_found#1d670b96", "#1d670b96", &TLItem{tag: 0x1d670b96, annotations: 0x0, tlName: "service1.not_found"}) - fillFunction("service1.replace#7f2c447d", "#7f2c447d", &TLItem{tag: 0x7f2c447d, annotations: 0x1, tlName: "service1.replace"}) - fillFunction("service1.replaceOrIncr#9d1bdcfd", "#9d1bdcfd", &TLItem{tag: 0x9d1bdcfd, annotations: 0x1, tlName: "service1.replaceOrIncr"}) - fillFunction("service1.set#05ae5f66", "#05ae5f66", &TLItem{tag: 0x05ae5f66, annotations: 0x1, tlName: "service1.set"}) - fillFunction("service1.setOrIncr#772e390d", "#772e390d", &TLItem{tag: 0x772e390d, annotations: 0x1, tlName: "service1.setOrIncr"}) - fillObject("service1.strvalue#5faa0c52", "#5faa0c52", &TLItem{tag: 0x5faa0c52, annotations: 0x0, tlName: "service1.strvalue"}) - fillObject("service1.strvalueWithTime#98b1a484", "#98b1a484", &TLItem{tag: 0x98b1a484, annotations: 0x0, tlName: "service1.strvalueWithTime"}) - fillFunction("service1.touch#b737aa03", "#b737aa03", &TLItem{tag: 0xb737aa03, annotations: 0x1, tlName: "service1.touch"}) - fillFunction("service2.addOrIncrMany#5aa52489", "#5aa52489", &TLItem{tag: 0x5aa52489, annotations: 0x2, tlName: "service2.addOrIncrMany"}) - fillFunction("service2.set#0d31f63d", "#0d31f63d", &TLItem{tag: 0x0d31f63d, annotations: 0x4, tlName: "service2.set"}) - fillFunction("service2.setObjectTtl#6f98f025", "#6f98f025", &TLItem{tag: 0x6f98f025, annotations: 0x4, tlName: "service2.setObjectTtl"}) - fillFunction("service3.createProduct#b7d92bd9", "#b7d92bd9", &TLItem{tag: 0xb7d92bd9, annotations: 0x1, tlName: "service3.createProduct"}) - fillFunction("service3.deleteAllProducts#4494acc2", "#4494acc2", &TLItem{tag: 0x4494acc2, annotations: 0x1, tlName: "service3.deleteAllProducts"}) - fillFunction("service3.deleteGroupedProducts#e468e614", "#e468e614", &TLItem{tag: 0xe468e614, annotations: 0x1, tlName: "service3.deleteGroupedProducts"}) - fillFunction("service3.deleteProduct#6867e707", "#6867e707", &TLItem{tag: 0x6867e707, annotations: 0x1, tlName: "service3.deleteProduct"}) - fillFunction("service3.getLastVisitTimestamp#9a4c788d", "#9a4c788d", &TLItem{tag: 0x9a4c788d, annotations: 0x1, tlName: "service3.getLastVisitTimestamp"}) - fillFunction("service3.getLimits#eb399467", "#eb399467", &TLItem{tag: 0xeb399467, annotations: 0x1, tlName: "service3.getLimits"}) - fillFunction("service3.getProductStats#261f6898", "#261f6898", &TLItem{tag: 0x261f6898, annotations: 0x1, tlName: "service3.getProductStats"}) - fillFunction("service3.getProducts#eb306233", "#eb306233", &TLItem{tag: 0xeb306233, annotations: 0x1, tlName: "service3.getProducts"}) - fillFunction("service3.getScheduledProducts#f53ad7bd", "#f53ad7bd", &TLItem{tag: 0xf53ad7bd, annotations: 0x1, tlName: "service3.getScheduledProducts"}) - fillObject("service3.groupCountLimit#8c04ea7f", "#8c04ea7f", &TLItem{tag: 0x8c04ea7f, annotations: 0x0, tlName: "service3.groupCountLimit"}) - fillObject("service3.groupSizeLimit#90e59396", "#90e59396", &TLItem{tag: 0x90e59396, annotations: 0x0, tlName: "service3.groupSizeLimit"}) - fillObject("service3.limits#80ee61ca", "#80ee61ca", &TLItem{tag: 0x80ee61ca, annotations: 0x0, tlName: "service3.limits"}) - fillObject("service3.productStatsOld#6319810b", "#6319810b", &TLItem{tag: 0x6319810b, annotations: 0x0, tlName: "service3.productStatsOld"}) - fillFunction("service3.restoreAllProducts#4d839ed0", "#4d839ed0", &TLItem{tag: 0x4d839ed0, annotations: 0x1, tlName: "service3.restoreAllProducts"}) - fillFunction("service3.restoreGroupedProducts#1f17bfac", "#1f17bfac", &TLItem{tag: 0x1f17bfac, annotations: 0x1, tlName: "service3.restoreGroupedProducts"}) - fillFunction("service3.restoreProduct#6170d515", "#6170d515", &TLItem{tag: 0x6170d515, annotations: 0x1, tlName: "service3.restoreProduct"}) - fillFunction("service3.setLastVisitTimestamp#7909b020", "#7909b020", &TLItem{tag: 0x7909b020, annotations: 0x1, tlName: "service3.setLastVisitTimestamp"}) - fillFunction("service3.setLimits#3ad5c19c", "#3ad5c19c", &TLItem{tag: 0x3ad5c19c, annotations: 0x1, tlName: "service3.setLimits"}) - fillObject("service4.modifiedNewsEntry#da19832a", "#da19832a", &TLItem{tag: 0xda19832a, annotations: 0x0, tlName: "service4.modifiedNewsEntry"}) - fillObject("service4.object#a6eeca4f", "#a6eeca4f", &TLItem{tag: 0xa6eeca4f, annotations: 0x0, tlName: "service4.object"}) - fillObject("service5.emptyOutput#11e46879", "#11e46879", &TLItem{tag: 0x11e46879, annotations: 0x0, tlName: "service5.emptyOutput"}) - fillFunction("service5.insert#c911ee2c", "#c911ee2c", &TLItem{tag: 0xc911ee2c, annotations: 0x1, tlName: "service5.insert"}) - fillObject("service5.params#12ae5cb5", "#12ae5cb5", &TLItem{tag: 0x12ae5cb5, annotations: 0x0, tlName: "service5.params"}) - fillFunction("service5.performQuery#019d80a5", "#019d80a5", &TLItem{tag: 0x019d80a5, annotations: 0x1, tlName: "service5.performQuery"}) - fillFunction("service5.query#b3b62513", "#b3b62513", &TLItem{tag: 0xb3b62513, annotations: 0x1, tlName: "service5.query"}) - fillObject("service5.stringOutput#179e9863", "#179e9863", &TLItem{tag: 0x179e9863, annotations: 0x0, tlName: "service5.stringOutput"}) - fillObject("service6.error#738553ef", "#738553ef", &TLItem{tag: 0x738553ef, annotations: 0x0, tlName: "service6.error"}) - fillObject("service6.findResultRow#bd3946e3", "#bd3946e3", &TLItem{tag: 0xbd3946e3, annotations: 0x0, tlName: "service6.findResultRow"}) - fillObject("service6.findWithBoundsResult#3ded850a", "#3ded850a", &TLItem{tag: 0x3ded850a, annotations: 0x0, tlName: "service6.findWithBoundsResult"}) - fillFunction("service6.multiFind#e62178d8", "#e62178d8", &TLItem{tag: 0xe62178d8, annotations: 0x1, tlName: "service6.multiFind"}) - fillFunction("service6.multiFindWithBounds#84b168cf", "#84b168cf", &TLItem{tag: 0x84b168cf, annotations: 0x1, tlName: "service6.multiFindWithBounds"}) - fillObject("statOne#74b0604b", "#74b0604b", &TLItem{tag: 0x74b0604b, annotations: 0x0, tlName: "statOne"}) - fillObject("string#b5286e24", "#b5286e24", &TLItem{tag: 0xb5286e24, annotations: 0x0, tlName: "string"}) - fillFunction("tasks.addTask#2ca073d5", "#2ca073d5", &TLItem{tag: 0x2ca073d5, annotations: 0x1, tlName: "tasks.addTask"}) - fillObject("tasks.cronTask#c90cf28a", "#c90cf28a", &TLItem{tag: 0xc90cf28a, annotations: 0x0, tlName: "tasks.cronTask"}) - fillObject("tasks.cronTaskWithId#3a958001", "#3a958001", &TLItem{tag: 0x3a958001, annotations: 0x0, tlName: "tasks.cronTaskWithId"}) - fillObject("tasks.cronTime#d4177d7f", "#d4177d7f", &TLItem{tag: 0xd4177d7f, annotations: 0x0, tlName: "tasks.cronTime"}) - fillFunction("tasks.getAnyTask#4a9c7dbb", "#4a9c7dbb", &TLItem{tag: 0x4a9c7dbb, annotations: 0x1, tlName: "tasks.getAnyTask"}) - fillFunction("tasks.getQueueSize#d8fcda03", "#d8fcda03", &TLItem{tag: 0xd8fcda03, annotations: 0x1, tlName: "tasks.getQueueSize"}) - fillFunction("tasks.getQueueTypes#5434457a", "#5434457a", &TLItem{tag: 0x5434457a, annotations: 0x1, tlName: "tasks.getQueueTypes"}) - fillFunction("tasks.getTaskFromQueue#6a52b698", "#6a52b698", &TLItem{tag: 0x6a52b698, annotations: 0x1, tlName: "tasks.getTaskFromQueue"}) - fillObject("tasks.queueTypeInfo#38d38d3e", "#38d38d3e", &TLItem{tag: 0x38d38d3e, annotations: 0x0, tlName: "tasks.queueTypeInfo"}) - fillObject("tasks.queueTypeSettings#561fbc09", "#561fbc09", &TLItem{tag: 0x561fbc09, annotations: 0x0, tlName: "tasks.queueTypeSettings"}) - fillObject("tasks.queueTypeStats#e1b785f2", "#e1b785f2", &TLItem{tag: 0xe1b785f2, annotations: 0x0, tlName: "tasks.queueTypeStats"}) - fillObject("tasks.task#7c23bc2c", "#7c23bc2c", &TLItem{tag: 0x7c23bc2c, annotations: 0x0, tlName: "tasks.task"}) - fillObject("tasks.taskInfo#06f0c6a6", "#06f0c6a6", &TLItem{tag: 0x06f0c6a6, annotations: 0x0, tlName: "tasks.taskInfo"}) - fillObject("tasks.taskStatusInProgress#06ef70e7", "#06ef70e7", &TLItem{tag: 0x06ef70e7, annotations: 0x0, tlName: "tasks.taskStatusInProgress"}) - fillObject("tasks.taskStatusNotCurrentlyInEngine#b207caaa", "#b207caaa", &TLItem{tag: 0xb207caaa, annotations: 0x0, tlName: "tasks.taskStatusNotCurrentlyInEngine"}) - fillObject("tasks.taskStatusScheduled#0aca80a9", "#0aca80a9", &TLItem{tag: 0x0aca80a9, annotations: 0x0, tlName: "tasks.taskStatusScheduled"}) - fillObject("tasks.taskStatusWaiting#16739c2c", "#16739c2c", &TLItem{tag: 0x16739c2c, annotations: 0x0, tlName: "tasks.taskStatusWaiting"}) - fillObject("tree_stats.objectLimitValueDouble#5dfb8816", "#5dfb8816", &TLItem{tag: 0x5dfb8816, annotations: 0x0, tlName: "tree_stats.objectLimitValueDouble"}) - fillObject("tree_stats.objectLimitValueLong#73111993", "#73111993", &TLItem{tag: 0x73111993, annotations: 0x0, tlName: "tree_stats.objectLimitValueLong"}) - fillObject("true#3fedd339", "#3fedd339", &TLItem{tag: 0x3fedd339, annotations: 0x0, tlName: "true"}) - fillFunction("unique.get#ce89bbf2", "#ce89bbf2", &TLItem{tag: 0xce89bbf2, annotations: 0x1, tlName: "unique.get"}) - fillFunction("unique.stringToInt#0f766c35", "#0f766c35", &TLItem{tag: 0x0f766c35, annotations: 0x1, tlName: "unique.stringToInt"}) - fillObject("withFloat#071b8685", "#071b8685", &TLItem{tag: 0x071b8685, annotations: 0x0, tlName: "withFloat"}) + fillFunction("antispam.getPattern#3de14136", "#3de14136", &TLItem{tag: 0x3de14136, annotations: 0x1, tlName: "antispam.getPattern", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("antispam.patternFound#a7688492", "#a7688492", &TLItem{tag: 0xa7688492, annotations: 0x0, tlName: "antispam.patternFound", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("antispam.patternNotFound#2c22e225", "#2c22e225", &TLItem{tag: 0x2c22e225, annotations: 0x0, tlName: "antispam.patternNotFound", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("benchObject#b697e865", "#b697e865", &TLItem{tag: 0xb697e865, annotations: 0x0, tlName: "benchObject", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("boolStat#92cbcbfa", "#92cbcbfa", &TLItem{tag: 0x92cbcbfa, annotations: 0x0, tlName: "boolStat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedArray#95dcc8b7", "#95dcc8b7", &TLItem{tag: 0x95dcc8b7, annotations: 0x1, tlName: "boxedArray", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedInt#5688ebaf", "#5688ebaf", &TLItem{tag: 0x5688ebaf, annotations: 0x1, tlName: "boxedInt", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedString#548994db", "#548994db", &TLItem{tag: 0x548994db, annotations: 0x1, tlName: "boxedString", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedTuple#30c9d533", "#30c9d533", &TLItem{tag: 0x30c9d533, annotations: 0x1, tlName: "boxedTuple", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedTupleSlice1#25230d40", "#25230d40", &TLItem{tag: 0x25230d40, annotations: 0x1, tlName: "boxedTupleSlice1", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedTupleSlice2#1cdf4705", "#1cdf4705", &TLItem{tag: 0x1cdf4705, annotations: 0x1, tlName: "boxedTupleSlice2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedTupleSlice3#a19b8106", "#a19b8106", &TLItem{tag: 0xa19b8106, annotations: 0x1, tlName: "boxedTupleSlice3", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedVector32#bbadef07", "#bbadef07", &TLItem{tag: 0xbbadef07, annotations: 0x1, tlName: "boxedVector32", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedVector32BoxedElem#591cecd4", "#591cecd4", &TLItem{tag: 0x591cecd4, annotations: 0x1, tlName: "boxedVector32BoxedElem", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("boxedVector64#83659ba8", "#83659ba8", &TLItem{tag: 0x83659ba8, annotations: 0x1, tlName: "boxedVector64", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("double#2210c154", "#2210c154", &TLItem{tag: 0x2210c154, annotations: 0x0, tlName: "double", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("fieldConflict1#f314bd09", "#f314bd09", &TLItem{tag: 0xf314bd09, annotations: 0x0, tlName: "fieldConflict1", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("fieldConflict2#1bba76b8", "#1bba76b8", &TLItem{tag: 0x1bba76b8, annotations: 0x0, tlName: "fieldConflict2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("fieldConflict3#2cf6e157", "#2cf6e157", &TLItem{tag: 0x2cf6e157, annotations: 0x0, tlName: "fieldConflict3", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("fieldConflict4#d93c186a", "#d93c186a", &TLItem{tag: 0xd93c186a, annotations: 0x0, tlName: "fieldConflict4", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("float#824dab22", "#824dab22", &TLItem{tag: 0x824dab22, annotations: 0x0, tlName: "float", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("get_arrays#90658cdb", "#90658cdb", &TLItem{tag: 0x90658cdb, annotations: 0x1, tlName: "get_arrays", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getDouble#39711d7b", "#39711d7b", &TLItem{tag: 0x39711d7b, annotations: 0x1, tlName: "getDouble", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getFloat#25a7bc68", "#25a7bc68", &TLItem{tag: 0x25a7bc68, annotations: 0x1, tlName: "getFloat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getMaybeIface#6b055ae4", "#6b055ae4", &TLItem{tag: 0x6b055ae4, annotations: 0x1, tlName: "getMaybeIface", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: true}) + fillFunction("getMyDictOfInt#166f962c", "#166f962c", &TLItem{tag: 0x166f962c, annotations: 0x1, tlName: "getMyDictOfInt", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getMyDouble#b660ad10", "#b660ad10", &TLItem{tag: 0xb660ad10, annotations: 0x1, tlName: "getMyDouble", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getMyValue#b3df27fe", "#b3df27fe", &TLItem{tag: 0xb3df27fe, annotations: 0x1, tlName: "getMyValue", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: true}) + fillFunction("getNonOptNat#67665961", "#67665961", &TLItem{tag: 0x67665961, annotations: 0x1, tlName: "getNonOptNat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("getStats#baa6da35", "#baa6da35", &TLItem{tag: 0xbaa6da35, annotations: 0x1, tlName: "getStats", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("int#a8509bda", "#a8509bda", &TLItem{tag: 0xa8509bda, annotations: 0x0, tlName: "int", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("integer#7e194796", "#7e194796", &TLItem{tag: 0x7e194796, annotations: 0x0, tlName: "integer", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("issue3498#f54b7b0a", "#f54b7b0a", &TLItem{tag: 0xf54b7b0a, annotations: 0x0, tlName: "issue3498", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("long#22076cba", "#22076cba", &TLItem{tag: 0x22076cba, annotations: 0x0, tlName: "long", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myAnonMcValue#569310db", "#569310db", &TLItem{tag: 0x569310db, annotations: 0x0, tlName: "myAnonMcValue", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myBoxedArray#288f64f0", "#288f64f0", &TLItem{tag: 0x288f64f0, annotations: 0x0, tlName: "myBoxedArray", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myBoxedTupleSlice#25d1a1be", "#25d1a1be", &TLItem{tag: 0x25d1a1be, annotations: 0x0, tlName: "myBoxedTupleSlice", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myBoxedVectorSlice#57d164bb", "#57d164bb", &TLItem{tag: 0x57d164bb, annotations: 0x0, tlName: "myBoxedVectorSlice", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myDictOfInt#b8019a3d", "#b8019a3d", &TLItem{tag: 0xb8019a3d, annotations: 0x0, tlName: "myDictOfInt", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myDouble#90a6c726", "#90a6c726", &TLItem{tag: 0x90a6c726, annotations: 0x0, tlName: "myDouble", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myInt#c12375b7", "#c12375b7", &TLItem{tag: 0xc12375b7, annotations: 0x0, tlName: "myInt", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myMaybe1#32c541fe", "#32c541fe", &TLItem{tag: 0x32c541fe, annotations: 0x0, tlName: "myMaybe1", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myMaybe2#ef6d355c", "#ef6d355c", &TLItem{tag: 0xef6d355c, annotations: 0x0, tlName: "myMaybe2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myMcValue#e2ffd978", "#e2ffd978", &TLItem{tag: 0xe2ffd978, annotations: 0x0, tlName: "myMcValue", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myMcValueTuple#1287d116", "#1287d116", &TLItem{tag: 0x1287d116, annotations: 0x0, tlName: "myMcValueTuple", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myMcValueVector#761d6d58", "#761d6d58", &TLItem{tag: 0x761d6d58, annotations: 0x0, tlName: "myMcValueVector", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myString#c8bfa969", "#c8bfa969", &TLItem{tag: 0xc8bfa969, annotations: 0x0, tlName: "myString", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("myTwoDicts#a859581d", "#a859581d", &TLItem{tag: 0xa859581d, annotations: 0x0, tlName: "myTwoDicts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("nonOptNat#45366605", "#45366605", &TLItem{tag: 0x45366605, annotations: 0x0, tlName: "nonOptNat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("pkg2.foo#e144703d", "#e144703d", &TLItem{tag: 0xe144703d, annotations: 0x0, tlName: "pkg2.foo", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("pkg2.t1#638206ec", "#638206ec", &TLItem{tag: 0x638206ec, annotations: 0x0, tlName: "pkg2.t1", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("pkg2.t2#d6e5af9c", "#d6e5af9c", &TLItem{tag: 0xd6e5af9c, annotations: 0x0, tlName: "pkg2.t2", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("rpcInvokeReqExtra#f3ef81a9", "#f3ef81a9", &TLItem{tag: 0xf3ef81a9, annotations: 0x0, tlName: "rpcInvokeReqExtra", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.add#481df8be", "#481df8be", &TLItem{tag: 0x481df8be, annotations: 0x1, tlName: "service1.add", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.addOrGet#6a42faad", "#6a42faad", &TLItem{tag: 0x6a42faad, annotations: 0x1, tlName: "service1.addOrGet", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.addOrIncr#90c4b402", "#90c4b402", &TLItem{tag: 0x90c4b402, annotations: 0x1, tlName: "service1.addOrIncr", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.append#04dec671", "#04dec671", &TLItem{tag: 0x04dec671, annotations: 0x1, tlName: "service1.append", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.cas#51851964", "#51851964", &TLItem{tag: 0x51851964, annotations: 0x1, tlName: "service1.cas", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.decr#eb179ce7", "#eb179ce7", &TLItem{tag: 0xeb179ce7, annotations: 0x1, tlName: "service1.decr", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.delete#83277767", "#83277767", &TLItem{tag: 0x83277767, annotations: 0x1, tlName: "service1.delete", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.disableExpiration#f1c39c2d", "#f1c39c2d", &TLItem{tag: 0xf1c39c2d, annotations: 0x1, tlName: "service1.disableExpiration", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.disableKeysStat#79d6160f", "#79d6160f", &TLItem{tag: 0x79d6160f, annotations: 0x1, tlName: "service1.disableKeysStat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.enableExpiration#2b51ad67", "#2b51ad67", &TLItem{tag: 0x2b51ad67, annotations: 0x1, tlName: "service1.enableExpiration", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.enableKeysStat#29a7090e", "#29a7090e", &TLItem{tag: 0x29a7090e, annotations: 0x1, tlName: "service1.enableKeysStat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.exists#e0284c9e", "#e0284c9e", &TLItem{tag: 0xe0284c9e, annotations: 0x1, tlName: "service1.exists", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.get#29099b19", "#29099b19", &TLItem{tag: 0x29099b19, annotations: 0x1, tlName: "service1.get", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getExpireTime#5a731070", "#5a731070", &TLItem{tag: 0x5a731070, annotations: 0x1, tlName: "service1.getExpireTime", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getKeysStat#06cecd58", "#06cecd58", &TLItem{tag: 0x06cecd58, annotations: 0x1, tlName: "service1.getKeysStat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getKeysStatPeriods#8cdf39e3", "#8cdf39e3", &TLItem{tag: 0x8cdf39e3, annotations: 0x1, tlName: "service1.getKeysStatPeriods", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getWildcard#2f2abf13", "#2f2abf13", &TLItem{tag: 0x2f2abf13, annotations: 0x1, tlName: "service1.getWildcard", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getWildcardDict#72bbc81b", "#72bbc81b", &TLItem{tag: 0x72bbc81b, annotations: 0x1, tlName: "service1.getWildcardDict", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getWildcardList#56b6ead4", "#56b6ead4", &TLItem{tag: 0x56b6ead4, annotations: 0x1, tlName: "service1.getWildcardList", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.getWildcardWithFlags#5f6a1f78", "#5f6a1f78", &TLItem{tag: 0x5f6a1f78, annotations: 0x1, tlName: "service1.getWildcardWithFlags", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.incr#0f96b56e", "#0f96b56e", &TLItem{tag: 0x0f96b56e, annotations: 0x1, tlName: "service1.incr", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("service1.keysStat#f0f6bc68", "#f0f6bc68", &TLItem{tag: 0xf0f6bc68, annotations: 0x0, tlName: "service1.keysStat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service1.longvalue#082e0945", "#082e0945", &TLItem{tag: 0x082e0945, annotations: 0x0, tlName: "service1.longvalue", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service1.longvalueWithTime#a04606ec", "#a04606ec", &TLItem{tag: 0xa04606ec, annotations: 0x0, tlName: "service1.longvalueWithTime", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service1.not_found#1d670b96", "#1d670b96", &TLItem{tag: 0x1d670b96, annotations: 0x0, tlName: "service1.not_found", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.replace#7f2c447d", "#7f2c447d", &TLItem{tag: 0x7f2c447d, annotations: 0x1, tlName: "service1.replace", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.replaceOrIncr#9d1bdcfd", "#9d1bdcfd", &TLItem{tag: 0x9d1bdcfd, annotations: 0x1, tlName: "service1.replaceOrIncr", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.set#05ae5f66", "#05ae5f66", &TLItem{tag: 0x05ae5f66, annotations: 0x1, tlName: "service1.set", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.setOrIncr#772e390d", "#772e390d", &TLItem{tag: 0x772e390d, annotations: 0x1, tlName: "service1.setOrIncr", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("service1.strvalue#5faa0c52", "#5faa0c52", &TLItem{tag: 0x5faa0c52, annotations: 0x0, tlName: "service1.strvalue", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service1.strvalueWithTime#98b1a484", "#98b1a484", &TLItem{tag: 0x98b1a484, annotations: 0x0, tlName: "service1.strvalueWithTime", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service1.touch#b737aa03", "#b737aa03", &TLItem{tag: 0xb737aa03, annotations: 0x1, tlName: "service1.touch", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service2.addOrIncrMany#5aa52489", "#5aa52489", &TLItem{tag: 0x5aa52489, annotations: 0x2, tlName: "service2.addOrIncrMany", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service2.set#0d31f63d", "#0d31f63d", &TLItem{tag: 0x0d31f63d, annotations: 0x4, tlName: "service2.set", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service2.setObjectTtl#6f98f025", "#6f98f025", &TLItem{tag: 0x6f98f025, annotations: 0x4, tlName: "service2.setObjectTtl", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.createProduct#b7d92bd9", "#b7d92bd9", &TLItem{tag: 0xb7d92bd9, annotations: 0x1, tlName: "service3.createProduct", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.deleteAllProducts#4494acc2", "#4494acc2", &TLItem{tag: 0x4494acc2, annotations: 0x1, tlName: "service3.deleteAllProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.deleteGroupedProducts#e468e614", "#e468e614", &TLItem{tag: 0xe468e614, annotations: 0x1, tlName: "service3.deleteGroupedProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.deleteProduct#6867e707", "#6867e707", &TLItem{tag: 0x6867e707, annotations: 0x1, tlName: "service3.deleteProduct", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.getLastVisitTimestamp#9a4c788d", "#9a4c788d", &TLItem{tag: 0x9a4c788d, annotations: 0x1, tlName: "service3.getLastVisitTimestamp", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.getLimits#eb399467", "#eb399467", &TLItem{tag: 0xeb399467, annotations: 0x1, tlName: "service3.getLimits", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.getProductStats#261f6898", "#261f6898", &TLItem{tag: 0x261f6898, annotations: 0x1, tlName: "service3.getProductStats", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.getProducts#eb306233", "#eb306233", &TLItem{tag: 0xeb306233, annotations: 0x1, tlName: "service3.getProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.getScheduledProducts#f53ad7bd", "#f53ad7bd", &TLItem{tag: 0xf53ad7bd, annotations: 0x1, tlName: "service3.getScheduledProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service3.groupCountLimit#8c04ea7f", "#8c04ea7f", &TLItem{tag: 0x8c04ea7f, annotations: 0x0, tlName: "service3.groupCountLimit", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service3.groupSizeLimit#90e59396", "#90e59396", &TLItem{tag: 0x90e59396, annotations: 0x0, tlName: "service3.groupSizeLimit", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service3.limits#80ee61ca", "#80ee61ca", &TLItem{tag: 0x80ee61ca, annotations: 0x0, tlName: "service3.limits", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service3.productStatsOld#6319810b", "#6319810b", &TLItem{tag: 0x6319810b, annotations: 0x0, tlName: "service3.productStatsOld", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.restoreAllProducts#4d839ed0", "#4d839ed0", &TLItem{tag: 0x4d839ed0, annotations: 0x1, tlName: "service3.restoreAllProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.restoreGroupedProducts#1f17bfac", "#1f17bfac", &TLItem{tag: 0x1f17bfac, annotations: 0x1, tlName: "service3.restoreGroupedProducts", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.restoreProduct#6170d515", "#6170d515", &TLItem{tag: 0x6170d515, annotations: 0x1, tlName: "service3.restoreProduct", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.setLastVisitTimestamp#7909b020", "#7909b020", &TLItem{tag: 0x7909b020, annotations: 0x1, tlName: "service3.setLastVisitTimestamp", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service3.setLimits#3ad5c19c", "#3ad5c19c", &TLItem{tag: 0x3ad5c19c, annotations: 0x1, tlName: "service3.setLimits", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service4.modifiedNewsEntry#da19832a", "#da19832a", &TLItem{tag: 0xda19832a, annotations: 0x0, tlName: "service4.modifiedNewsEntry", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service4.object#a6eeca4f", "#a6eeca4f", &TLItem{tag: 0xa6eeca4f, annotations: 0x0, tlName: "service4.object", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service5.emptyOutput#11e46879", "#11e46879", &TLItem{tag: 0x11e46879, annotations: 0x0, tlName: "service5.emptyOutput", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service5.insert#c911ee2c", "#c911ee2c", &TLItem{tag: 0xc911ee2c, annotations: 0x1, tlName: "service5.insert", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("service5.params#12ae5cb5", "#12ae5cb5", &TLItem{tag: 0x12ae5cb5, annotations: 0x0, tlName: "service5.params", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service5.performQuery#019d80a5", "#019d80a5", &TLItem{tag: 0x019d80a5, annotations: 0x1, tlName: "service5.performQuery", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service5.query#b3b62513", "#b3b62513", &TLItem{tag: 0xb3b62513, annotations: 0x1, tlName: "service5.query", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("service5.stringOutput#179e9863", "#179e9863", &TLItem{tag: 0x179e9863, annotations: 0x0, tlName: "service5.stringOutput", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service6.error#738553ef", "#738553ef", &TLItem{tag: 0x738553ef, annotations: 0x0, tlName: "service6.error", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service6.findResultRow#bd3946e3", "#bd3946e3", &TLItem{tag: 0xbd3946e3, annotations: 0x0, tlName: "service6.findResultRow", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("service6.findWithBoundsResult#3ded850a", "#3ded850a", &TLItem{tag: 0x3ded850a, annotations: 0x0, tlName: "service6.findWithBoundsResult", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("service6.multiFind#e62178d8", "#e62178d8", &TLItem{tag: 0xe62178d8, annotations: 0x1, tlName: "service6.multiFind", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillFunction("service6.multiFindWithBounds#84b168cf", "#84b168cf", &TLItem{tag: 0x84b168cf, annotations: 0x1, tlName: "service6.multiFindWithBounds", resultTypeContainsUnionTypes: true, argumentsTypesContainUnionTypes: false}) + fillObject("statOne#74b0604b", "#74b0604b", &TLItem{tag: 0x74b0604b, annotations: 0x0, tlName: "statOne", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("string#b5286e24", "#b5286e24", &TLItem{tag: 0xb5286e24, annotations: 0x0, tlName: "string", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("tasks.addTask#2ca073d5", "#2ca073d5", &TLItem{tag: 0x2ca073d5, annotations: 0x1, tlName: "tasks.addTask", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.cronTask#c90cf28a", "#c90cf28a", &TLItem{tag: 0xc90cf28a, annotations: 0x0, tlName: "tasks.cronTask", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.cronTaskWithId#3a958001", "#3a958001", &TLItem{tag: 0x3a958001, annotations: 0x0, tlName: "tasks.cronTaskWithId", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.cronTime#d4177d7f", "#d4177d7f", &TLItem{tag: 0xd4177d7f, annotations: 0x0, tlName: "tasks.cronTime", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("tasks.getAnyTask#4a9c7dbb", "#4a9c7dbb", &TLItem{tag: 0x4a9c7dbb, annotations: 0x1, tlName: "tasks.getAnyTask", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("tasks.getQueueSize#d8fcda03", "#d8fcda03", &TLItem{tag: 0xd8fcda03, annotations: 0x1, tlName: "tasks.getQueueSize", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("tasks.getQueueTypes#5434457a", "#5434457a", &TLItem{tag: 0x5434457a, annotations: 0x1, tlName: "tasks.getQueueTypes", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("tasks.getTaskFromQueue#6a52b698", "#6a52b698", &TLItem{tag: 0x6a52b698, annotations: 0x1, tlName: "tasks.getTaskFromQueue", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.queueTypeInfo#38d38d3e", "#38d38d3e", &TLItem{tag: 0x38d38d3e, annotations: 0x0, tlName: "tasks.queueTypeInfo", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.queueTypeSettings#561fbc09", "#561fbc09", &TLItem{tag: 0x561fbc09, annotations: 0x0, tlName: "tasks.queueTypeSettings", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.queueTypeStats#e1b785f2", "#e1b785f2", &TLItem{tag: 0xe1b785f2, annotations: 0x0, tlName: "tasks.queueTypeStats", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.task#7c23bc2c", "#7c23bc2c", &TLItem{tag: 0x7c23bc2c, annotations: 0x0, tlName: "tasks.task", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.taskInfo#06f0c6a6", "#06f0c6a6", &TLItem{tag: 0x06f0c6a6, annotations: 0x0, tlName: "tasks.taskInfo", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.taskStatusInProgress#06ef70e7", "#06ef70e7", &TLItem{tag: 0x06ef70e7, annotations: 0x0, tlName: "tasks.taskStatusInProgress", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.taskStatusNotCurrentlyInEngine#b207caaa", "#b207caaa", &TLItem{tag: 0xb207caaa, annotations: 0x0, tlName: "tasks.taskStatusNotCurrentlyInEngine", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.taskStatusScheduled#0aca80a9", "#0aca80a9", &TLItem{tag: 0x0aca80a9, annotations: 0x0, tlName: "tasks.taskStatusScheduled", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tasks.taskStatusWaiting#16739c2c", "#16739c2c", &TLItem{tag: 0x16739c2c, annotations: 0x0, tlName: "tasks.taskStatusWaiting", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tree_stats.objectLimitValueDouble#5dfb8816", "#5dfb8816", &TLItem{tag: 0x5dfb8816, annotations: 0x0, tlName: "tree_stats.objectLimitValueDouble", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("tree_stats.objectLimitValueLong#73111993", "#73111993", &TLItem{tag: 0x73111993, annotations: 0x0, tlName: "tree_stats.objectLimitValueLong", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("true#3fedd339", "#3fedd339", &TLItem{tag: 0x3fedd339, annotations: 0x0, tlName: "true", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("unique.get#ce89bbf2", "#ce89bbf2", &TLItem{tag: 0xce89bbf2, annotations: 0x1, tlName: "unique.get", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillFunction("unique.stringToInt#0f766c35", "#0f766c35", &TLItem{tag: 0x0f766c35, annotations: 0x1, tlName: "unique.stringToInt", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) + fillObject("withFloat#071b8685", "#071b8685", &TLItem{tag: 0x071b8685, annotations: 0x0, tlName: "withFloat", resultTypeContainsUnionTypes: false, argumentsTypesContainUnionTypes: false}) } diff --git a/internal/tlcodegen/test/tls/schema.tl b/internal/tlcodegen/test/tls/schema.tl index df832d0..0a54e73 100644 --- a/internal/tlcodegen/test/tls/schema.tl +++ b/internal/tlcodegen/test/tls/schema.tl @@ -308,7 +308,7 @@ fieldConflict4 X:%Int SetX:%Int = FieldConflict4; @any service5.query query:string params:%service5.Params = service5.Output; @any service5.insert table:string data:string = service5.Output; -@any withNatParam {n:#} = MyTuple n; +//@any withNatParam {n:#} = MyTuple n; @any tasks.addTask type_name:string queue_id:%(Vector int) task:%tasks.Task = Long; // id is returned From a02a3faab965b90fef485cf2d6b195fe65086781 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 22:06:59 +0300 Subject: [PATCH 35/37] staticcheck fix --- internal/tlcodegen/type_rw_maybe_php.go | 4 ++-- internal/tlcodegen/type_rw_struct_php.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/tlcodegen/type_rw_maybe_php.go b/internal/tlcodegen/type_rw_maybe_php.go index 2d7dabb..958b781 100644 --- a/internal/tlcodegen/type_rw_maybe_php.go +++ b/internal/tlcodegen/type_rw_maybe_php.go @@ -61,7 +61,7 @@ func (trw *TypeRWMaybe) PhpReadMethodCall(targetName string, bare bool, initIfDe initIfDefault = false } bodyReader := trw.element.t.trw.PhpReadMethodCall(targetName, trw.element.bare, initIfDefault, args) - for i, _ := range bodyReader { + for i := range bodyReader { bodyReader[i] = " " + bodyReader[i] } result = append(result, bodyReader...) @@ -91,7 +91,7 @@ func (trw *TypeRWMaybe) PhpWriteMethodCall(targetName string, bare bool, args *T } { bodyWriter := trw.element.t.trw.PhpWriteMethodCall(targetName, trw.element.bare, args) - for i, _ := range bodyWriter { + for i := range bodyWriter { bodyWriter[i] = " " + bodyWriter[i] } result = append(result, bodyWriter...) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index 666aa46..d6dd3ed 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -65,7 +65,7 @@ func (trw *TypeRWStruct) phpGetFieldArgsTree(currentType *TypeRWWrapper, current tree.CloneValuesFrom((*genericsToTrees)[generic]) return } - for i, _ := range currentType.origTL[0].TemplateArguments { + for i := range currentType.origTL[0].TemplateArguments { actualArg := currentType.arguments[i] actualArgRef := currentTypeRef.Args[i] if actualArg.isNat { @@ -93,7 +93,6 @@ func (trw *TypeRWStruct) phpGetFieldArgsTree(currentType *TypeRWWrapper, current } } } - return } func (trw *TypeRWStruct) PhpClassNameReplaced() bool { From 110627288890f211dfb6bb7cdba4419d45834661 Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Tue, 21 Jan 2025 22:10:41 +0300 Subject: [PATCH 36/37] add files --- .../internal/tl/tlBuiltinTuple2Int/int.go | 85 +++++++ .../pair.go | 90 +++++++ .../tl/tlBuiltinTupleTupleInt2/tuple.go | 100 ++++++++ .../tuple.go | 105 +++++++++ .../tl/tlPairTupleIntTupleInt/pair.go | 165 +++++++++++++ .../pair.go | 165 +++++++++++++ .../pair.go | 170 ++++++++++++++ .../gen/cases/internal/tl/tlTupleInt/tuple.go | 89 +++++++ .../cases/internal/tl/tlTupleInt2/tuple.go | 101 ++++++++ .../tl/tlTuplePairTupleIntTupleInt2/tuple.go | 90 +++++++ .../internal/tl/tlTupleTupleInt2/tuple.go | 89 +++++++ .../tuple.go | 90 +++++++ .../tlCasesInplace1Int/cases.inplace1.go | 125 ++++++++++ .../cases.inplace1.go | 125 ++++++++++ .../tlCasesInplace2Int/cases.inplace2.go | 125 ++++++++++ .../cases.inplace2.go | 125 ++++++++++ .../cases.inplace3.go | 125 ++++++++++ .../cases.inplace3.go | 125 ++++++++++ .../cases.testInplaceStructArgs.go | 219 ++++++++++++++++++ .../cases.testInplaceStructArgs2.go | 219 ++++++++++++++++++ 20 files changed, 2527 insertions(+) create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int/int.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt/pair.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt/pair.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2/pair.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2/pair.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlTuplePairTupleIntTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTuplePairTupleIntTupleInt2/tuple.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int/cases.inplace1.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt/cases.inplace1.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int/cases.inplace2.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt/cases.inplace2.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2/cases.inplace3.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2/cases.inplace3.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs/cases.testInplaceStructArgs.go create mode 100644 internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2/cases.testInplaceStructArgs2.go diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int/int.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int/int.go new file mode 100644 index 0000000..eb2ce0f --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int/int.go @@ -0,0 +1,85 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlBuiltinTuple2Int + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +func BuiltinTuple2IntReset(vec *[2]int32) { + for i := range *vec { + (*vec)[i] = 0 + } +} + +func BuiltinTuple2IntFillRandom(rg *basictl.RandGenerator, vec *[2]int32) { + rg.IncreaseDepth() + for i := range *vec { + (*vec)[i] = basictl.RandomInt(rg) + } + rg.DecreaseDepth() +} + +func BuiltinTuple2IntRead(w []byte, vec *[2]int32) (_ []byte, err error) { + for i := range *vec { + if w, err = basictl.IntRead(w, &(*vec)[i]); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTuple2IntWrite(w []byte, vec *[2]int32) []byte { + for _, elem := range *vec { + w = basictl.IntWrite(w, elem) + } + return w +} + +func BuiltinTuple2IntReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, vec *[2]int32) error { + index := 0 + if in != nil { + in.Delim('[') + if !in.Ok() { + return internal.ErrorInvalidJSON("[2]int32", "expected json array") + } + for ; !in.IsDelim(']'); index++ { + if index == 2 { + return internal.ErrorWrongSequenceLength("[2]int32", index+1, 2) + } + if err := internal.Json2ReadInt32(in, &(*vec)[index]); err != nil { + return err + } + in.WantComma() + } + in.Delim(']') + if !in.Ok() { + return internal.ErrorInvalidJSON("[2]int32", "expected json array's end") + } + } + if index != 2 { + return internal.ErrorWrongSequenceLength("[2]int32", index+1, 2) + } + return nil +} + +func BuiltinTuple2IntWriteJSON(w []byte, vec *[2]int32) []byte { + return BuiltinTuple2IntWriteJSONOpt(true, false, w, vec) +} +func BuiltinTuple2IntWriteJSONOpt(newTypeNames bool, short bool, w []byte, vec *[2]int32) []byte { + w = append(w, '[') + for _, elem := range *vec { + w = basictl.JSONAddCommaIfNeeded(w) + w = basictl.JSONWriteInt32(w, elem) + } + return append(w, ']') +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt/pair.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt/pair.go new file mode 100644 index 0000000..4eed611 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt/pair.go @@ -0,0 +1,90 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlBuiltinTuple2PairTupleIntTupleInt + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +func BuiltinTuple2PairTupleIntTupleIntReset(vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt) { + for i := range *vec { + (*vec)[i].Reset() + } +} + +func BuiltinTuple2PairTupleIntTupleIntFillRandom(rg *basictl.RandGenerator, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) { + rg.IncreaseDepth() + for i := range *vec { + (*vec)[i].FillRandom(rg, nat_tXn, nat_tYn) + } + rg.DecreaseDepth() +} + +func BuiltinTuple2PairTupleIntTupleIntRead(w []byte, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + for i := range *vec { + if w, err = (*vec)[i].Read(w, nat_tXn, nat_tYn); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTuple2PairTupleIntTupleIntWrite(w []byte, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + for _, elem := range *vec { + if w, err = elem.Write(w, nat_tXn, nat_tYn); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTuple2PairTupleIntTupleIntReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) error { + index := 0 + if in != nil { + in.Delim('[') + if !in.Ok() { + return internal.ErrorInvalidJSON("[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", "expected json array") + } + for ; !in.IsDelim(']'); index++ { + if index == 2 { + return internal.ErrorWrongSequenceLength("[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", index+1, 2) + } + if err := (*vec)[index].ReadJSON(legacyTypeNames, in, nat_tXn, nat_tYn); err != nil { + return err + } + in.WantComma() + } + in.Delim(']') + if !in.Ok() { + return internal.ErrorInvalidJSON("[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", "expected json array's end") + } + } + if index != 2 { + return internal.ErrorWrongSequenceLength("[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", index+1, 2) + } + return nil +} + +func BuiltinTuple2PairTupleIntTupleIntWriteJSON(w []byte, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + return BuiltinTuple2PairTupleIntTupleIntWriteJSONOpt(true, false, w, vec, nat_tXn, nat_tYn) +} +func BuiltinTuple2PairTupleIntTupleIntWriteJSONOpt(newTypeNames bool, short bool, w []byte, vec *[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + w = append(w, '[') + for _, elem := range *vec { + w = basictl.JSONAddCommaIfNeeded(w) + if w, err = elem.WriteJSONOpt(newTypeNames, short, w, nat_tXn, nat_tYn); err != nil { + return w, err + } + } + return append(w, ']'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2/tuple.go new file mode 100644 index 0000000..1d082d2 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2/tuple.go @@ -0,0 +1,100 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlBuiltinTupleTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +func BuiltinTupleTupleInt2FillRandom(rg *basictl.RandGenerator, vec *[][2]int32, nat_n uint32) { + rg.IncreaseDepth() + *vec = make([][2]int32, nat_n) + for i := range *vec { + tlBuiltinTuple2Int.BuiltinTuple2IntFillRandom(rg, &(*vec)[i]) + } + rg.DecreaseDepth() +} + +func BuiltinTupleTupleInt2Read(w []byte, vec *[][2]int32, nat_n uint32) (_ []byte, err error) { + if err = basictl.CheckLengthSanity(w, nat_n, 4); err != nil { + return w, err + } + if uint32(cap(*vec)) < nat_n { + *vec = make([][2]int32, nat_n) + } else { + *vec = (*vec)[:nat_n] + } + for i := range *vec { + if w, err = tlBuiltinTuple2Int.BuiltinTuple2IntRead(w, &(*vec)[i]); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTupleTupleInt2Write(w []byte, vec [][2]int32, nat_n uint32) (_ []byte, err error) { + if uint32(len(vec)) != nat_n { + return w, internal.ErrorWrongSequenceLength("[][2]int32", len(vec), nat_n) + } + for _, elem := range vec { + w = tlBuiltinTuple2Int.BuiltinTuple2IntWrite(w, &elem) + } + return w, nil +} + +func BuiltinTupleTupleInt2ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, vec *[][2]int32, nat_n uint32) error { + if uint32(cap(*vec)) < nat_n { + *vec = make([][2]int32, nat_n) + } else { + *vec = (*vec)[:nat_n] + } + index := 0 + if in != nil { + in.Delim('[') + if !in.Ok() { + return internal.ErrorInvalidJSON("[][2]int32", "expected json array") + } + for ; !in.IsDelim(']'); index++ { + if nat_n <= uint32(index) { + return internal.ErrorInvalidJSON("[][2]int32", "array is longer than expected") + } + if err := tlBuiltinTuple2Int.BuiltinTuple2IntReadJSON(legacyTypeNames, in, &(*vec)[index]); err != nil { + return err + } + in.WantComma() + } + in.Delim(']') + if !in.Ok() { + return internal.ErrorInvalidJSON("[][2]int32", "expected json array's end") + } + } + if uint32(index) != nat_n { + return internal.ErrorWrongSequenceLength("[][2]int32", index, nat_n) + } + return nil +} + +func BuiltinTupleTupleInt2WriteJSON(w []byte, vec [][2]int32, nat_n uint32) (_ []byte, err error) { + return BuiltinTupleTupleInt2WriteJSONOpt(true, false, w, vec, nat_n) +} +func BuiltinTupleTupleInt2WriteJSONOpt(newTypeNames bool, short bool, w []byte, vec [][2]int32, nat_n uint32) (_ []byte, err error) { + if uint32(len(vec)) != nat_n { + return w, internal.ErrorWrongSequenceLength("[][2]int32", len(vec), nat_n) + } + w = append(w, '[') + for _, elem := range vec { + w = basictl.JSONAddCommaIfNeeded(w) + w = tlBuiltinTuple2Int.BuiltinTuple2IntWriteJSONOpt(newTypeNames, short, w, &elem) + } + return append(w, ']'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2/tuple.go new file mode 100644 index 0000000..6994cd6 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2/tuple.go @@ -0,0 +1,105 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlBuiltinTupleTuplePairTupleIntTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +func BuiltinTupleTuplePairTupleIntTupleInt2FillRandom(rg *basictl.RandGenerator, vec *[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) { + rg.IncreaseDepth() + *vec = make([][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n) + for i := range *vec { + tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntFillRandom(rg, &(*vec)[i], nat_ttXn, nat_ttYn) + } + rg.DecreaseDepth() +} + +func BuiltinTupleTuplePairTupleIntTupleInt2Read(w []byte, vec *[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) (_ []byte, err error) { + if err = basictl.CheckLengthSanity(w, nat_n, 4); err != nil { + return w, err + } + if uint32(cap(*vec)) < nat_n { + *vec = make([][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n) + } else { + *vec = (*vec)[:nat_n] + } + for i := range *vec { + if w, err = tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntRead(w, &(*vec)[i], nat_ttXn, nat_ttYn); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTupleTuplePairTupleIntTupleInt2Write(w []byte, vec [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) (_ []byte, err error) { + if uint32(len(vec)) != nat_n { + return w, internal.ErrorWrongSequenceLength("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", len(vec), nat_n) + } + for _, elem := range vec { + if w, err = tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntWrite(w, &elem, nat_ttXn, nat_ttYn); err != nil { + return w, err + } + } + return w, nil +} + +func BuiltinTupleTuplePairTupleIntTupleInt2ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, vec *[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) error { + if uint32(cap(*vec)) < nat_n { + *vec = make([][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n) + } else { + *vec = (*vec)[:nat_n] + } + index := 0 + if in != nil { + in.Delim('[') + if !in.Ok() { + return internal.ErrorInvalidJSON("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", "expected json array") + } + for ; !in.IsDelim(']'); index++ { + if nat_n <= uint32(index) { + return internal.ErrorInvalidJSON("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", "array is longer than expected") + } + if err := tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntReadJSON(legacyTypeNames, in, &(*vec)[index], nat_ttXn, nat_ttYn); err != nil { + return err + } + in.WantComma() + } + in.Delim(']') + if !in.Ok() { + return internal.ErrorInvalidJSON("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", "expected json array's end") + } + } + if uint32(index) != nat_n { + return internal.ErrorWrongSequenceLength("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", index, nat_n) + } + return nil +} + +func BuiltinTupleTuplePairTupleIntTupleInt2WriteJSON(w []byte, vec [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) (_ []byte, err error) { + return BuiltinTupleTuplePairTupleIntTupleInt2WriteJSONOpt(true, false, w, vec, nat_n, nat_ttXn, nat_ttYn) +} +func BuiltinTupleTuplePairTupleIntTupleInt2WriteJSONOpt(newTypeNames bool, short bool, w []byte, vec [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt, nat_n uint32, nat_ttXn uint32, nat_ttYn uint32) (_ []byte, err error) { + if uint32(len(vec)) != nat_n { + return w, internal.ErrorWrongSequenceLength("[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt", len(vec), nat_n) + } + w = append(w, '[') + for _, elem := range vec { + w = basictl.JSONAddCommaIfNeeded(w) + if w, err = tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntWriteJSONOpt(newTypeNames, short, w, &elem, nat_ttXn, nat_ttYn); err != nil { + return w, err + } + } + return append(w, ']'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt/pair.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt/pair.go new file mode 100644 index 0000000..0db4199 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt/pair.go @@ -0,0 +1,165 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlPairTupleIntTupleInt + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type PairTupleIntTupleInt struct { + X []int32 + Y []int32 +} + +func (PairTupleIntTupleInt) TLName() string { return "pair" } +func (PairTupleIntTupleInt) TLTag() uint32 { return 0xf01604df } + +func (item *PairTupleIntTupleInt) Reset() { + item.X = item.X[:0] + item.Y = item.Y[:0] +} + +func (item *PairTupleIntTupleInt) FillRandom(rg *basictl.RandGenerator, nat_X uint32, nat_Y uint32) { + tlBuiltinTupleInt.BuiltinTupleIntFillRandom(rg, &item.X, nat_X) + tlBuiltinTupleInt.BuiltinTupleIntFillRandom(rg, &item.Y, nat_Y) +} + +func (item *PairTupleIntTupleInt) Read(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleInt.BuiltinTupleIntRead(w, &item.X, nat_X); err != nil { + return w, err + } + return tlBuiltinTupleInt.BuiltinTupleIntRead(w, &item.Y, nat_Y) +} + +// This method is general version of Write, use it instead! +func (item *PairTupleIntTupleInt) WriteGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.Write(w, nat_X, nat_Y) +} + +func (item *PairTupleIntTupleInt) Write(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleInt.BuiltinTupleIntWrite(w, item.X, nat_X); err != nil { + return w, err + } + if w, err = tlBuiltinTupleInt.BuiltinTupleIntWrite(w, item.Y, nat_Y); err != nil { + return w, err + } + return w, nil +} + +func (item *PairTupleIntTupleInt) ReadBoxed(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0xf01604df); err != nil { + return w, err + } + return item.Read(w, nat_X, nat_Y) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *PairTupleIntTupleInt) WriteBoxedGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_X, nat_Y) +} + +func (item *PairTupleIntTupleInt) WriteBoxed(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0xf01604df) + return item.Write(w, nat_X, nat_Y) +} + +func (item *PairTupleIntTupleInt) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_X uint32, nat_Y uint32) error { + var rawX []byte + var rawY []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "x": + if rawX != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "x") + } + rawX = in.Raw() + if !in.Ok() { + return in.Error() + } + case "y": + if rawY != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "y") + } + rawY = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("pair", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inXPointer *basictl.JsonLexer + inX := basictl.JsonLexer{Data: rawX} + if rawX != nil { + inXPointer = &inX + } + if err := tlBuiltinTupleInt.BuiltinTupleIntReadJSON(legacyTypeNames, inXPointer, &item.X, nat_X); err != nil { + return err + } + + var inYPointer *basictl.JsonLexer + inY := basictl.JsonLexer{Data: rawY} + if rawY != nil { + inYPointer = &inY + } + if err := tlBuiltinTupleInt.BuiltinTupleIntReadJSON(legacyTypeNames, inYPointer, &item.Y, nat_Y); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *PairTupleIntTupleInt) WriteJSONGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_X, nat_Y) +} + +func (item *PairTupleIntTupleInt) WriteJSON(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_X, nat_Y) +} +func (item *PairTupleIntTupleInt) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + w = append(w, '{') + backupIndexX := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"x":`...) + if w, err = tlBuiltinTupleInt.BuiltinTupleIntWriteJSONOpt(newTypeNames, short, w, item.X, nat_X); err != nil { + return w, err + } + if (len(item.X) != 0) == false { + w = w[:backupIndexX] + } + backupIndexY := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"y":`...) + if w, err = tlBuiltinTupleInt.BuiltinTupleIntWriteJSONOpt(newTypeNames, short, w, item.Y, nat_Y); err != nil { + return w, err + } + if (len(item.Y) != 0) == false { + w = w[:backupIndexY] + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2/pair.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2/pair.go new file mode 100644 index 0000000..998b913 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2/pair.go @@ -0,0 +1,165 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlPairTupleTupleInt2TupleTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type PairTupleTupleInt2TupleTupleInt2 struct { + X [][2]int32 + Y [][2]int32 +} + +func (PairTupleTupleInt2TupleTupleInt2) TLName() string { return "pair" } +func (PairTupleTupleInt2TupleTupleInt2) TLTag() uint32 { return 0xf01604df } + +func (item *PairTupleTupleInt2TupleTupleInt2) Reset() { + item.X = item.X[:0] + item.Y = item.Y[:0] +} + +func (item *PairTupleTupleInt2TupleTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_X uint32, nat_Y uint32) { + tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2FillRandom(rg, &item.X, nat_X) + tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2FillRandom(rg, &item.Y, nat_Y) +} + +func (item *PairTupleTupleInt2TupleTupleInt2) Read(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Read(w, &item.X, nat_X); err != nil { + return w, err + } + return tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Read(w, &item.Y, nat_Y) +} + +// This method is general version of Write, use it instead! +func (item *PairTupleTupleInt2TupleTupleInt2) WriteGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.Write(w, nat_X, nat_Y) +} + +func (item *PairTupleTupleInt2TupleTupleInt2) Write(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Write(w, item.X, nat_X); err != nil { + return w, err + } + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Write(w, item.Y, nat_Y); err != nil { + return w, err + } + return w, nil +} + +func (item *PairTupleTupleInt2TupleTupleInt2) ReadBoxed(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0xf01604df); err != nil { + return w, err + } + return item.Read(w, nat_X, nat_Y) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *PairTupleTupleInt2TupleTupleInt2) WriteBoxedGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_X, nat_Y) +} + +func (item *PairTupleTupleInt2TupleTupleInt2) WriteBoxed(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0xf01604df) + return item.Write(w, nat_X, nat_Y) +} + +func (item *PairTupleTupleInt2TupleTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_X uint32, nat_Y uint32) error { + var rawX []byte + var rawY []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "x": + if rawX != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "x") + } + rawX = in.Raw() + if !in.Ok() { + return in.Error() + } + case "y": + if rawY != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "y") + } + rawY = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("pair", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inXPointer *basictl.JsonLexer + inX := basictl.JsonLexer{Data: rawX} + if rawX != nil { + inXPointer = &inX + } + if err := tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2ReadJSON(legacyTypeNames, inXPointer, &item.X, nat_X); err != nil { + return err + } + + var inYPointer *basictl.JsonLexer + inY := basictl.JsonLexer{Data: rawY} + if rawY != nil { + inYPointer = &inY + } + if err := tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2ReadJSON(legacyTypeNames, inYPointer, &item.Y, nat_Y); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *PairTupleTupleInt2TupleTupleInt2) WriteJSONGeneral(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_X, nat_Y) +} + +func (item *PairTupleTupleInt2TupleTupleInt2) WriteJSON(w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_X, nat_Y) +} +func (item *PairTupleTupleInt2TupleTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_X uint32, nat_Y uint32) (_ []byte, err error) { + w = append(w, '{') + backupIndexX := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"x":`...) + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2WriteJSONOpt(newTypeNames, short, w, item.X, nat_X); err != nil { + return w, err + } + if (len(item.X) != 0) == false { + w = w[:backupIndexX] + } + backupIndexY := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"y":`...) + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2WriteJSONOpt(newTypeNames, short, w, item.Y, nat_Y); err != nil { + return w, err + } + if (len(item.Y) != 0) == false { + w = w[:backupIndexY] + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2/pair.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2/pair.go new file mode 100644 index 0000000..62458cd --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2/pair.go @@ -0,0 +1,170 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2 struct { + X [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt + Y [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt +} + +func (PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) TLName() string { + return "pair" +} +func (PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) TLTag() uint32 { + return 0xf01604df +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) Reset() { + item.X = item.X[:0] + item.Y = item.Y[:0] +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) { + tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2FillRandom(rg, &item.X, nat_Xn, nat_XttXn, nat_XttYn) + tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2FillRandom(rg, &item.Y, nat_Yn, nat_YttXn, nat_YttYn) +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) Read(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Read(w, &item.X, nat_Xn, nat_XttXn, nat_XttYn); err != nil { + return w, err + } + return tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Read(w, &item.Y, nat_Yn, nat_YttXn, nat_YttYn) +} + +// This method is general version of Write, use it instead! +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteGeneral(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + return item.Write(w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) Write(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Write(w, item.X, nat_Xn, nat_XttXn, nat_XttYn); err != nil { + return w, err + } + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Write(w, item.Y, nat_Yn, nat_YttXn, nat_YttYn); err != nil { + return w, err + } + return w, nil +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) ReadBoxed(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0xf01604df); err != nil { + return w, err + } + return item.Read(w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteBoxedGeneral(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteBoxed(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0xf01604df) + return item.Write(w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) error { + var rawX []byte + var rawY []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "x": + if rawX != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "x") + } + rawX = in.Raw() + if !in.Ok() { + return in.Error() + } + case "y": + if rawY != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("pair", "y") + } + rawY = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("pair", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inXPointer *basictl.JsonLexer + inX := basictl.JsonLexer{Data: rawX} + if rawX != nil { + inXPointer = &inX + } + if err := tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2ReadJSON(legacyTypeNames, inXPointer, &item.X, nat_Xn, nat_XttXn, nat_XttYn); err != nil { + return err + } + + var inYPointer *basictl.JsonLexer + inY := basictl.JsonLexer{Data: rawY} + if rawY != nil { + inYPointer = &inY + } + if err := tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2ReadJSON(legacyTypeNames, inYPointer, &item.Y, nat_Yn, nat_YttXn, nat_YttYn); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteJSONGeneral(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} + +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteJSON(w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_XttXn, nat_XttYn, nat_Xn, nat_YttXn, nat_YttYn, nat_Yn) +} +func (item *PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_XttXn uint32, nat_XttYn uint32, nat_Xn uint32, nat_YttXn uint32, nat_YttYn uint32, nat_Yn uint32) (_ []byte, err error) { + w = append(w, '{') + backupIndexX := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"x":`...) + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2WriteJSONOpt(newTypeNames, short, w, item.X, nat_Xn, nat_XttXn, nat_XttYn); err != nil { + return w, err + } + if (len(item.X) != 0) == false { + w = w[:backupIndexX] + } + backupIndexY := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"y":`...) + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2WriteJSONOpt(newTypeNames, short, w, item.Y, nat_Yn, nat_YttXn, nat_YttYn); err != nil { + return w, err + } + if (len(item.Y) != 0) == false { + w = w[:backupIndexY] + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt/tuple.go new file mode 100644 index 0000000..1e31674 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt/tuple.go @@ -0,0 +1,89 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlTupleInt + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type TupleInt []int32 + +func (TupleInt) TLName() string { return "tuple" } +func (TupleInt) TLTag() uint32 { return 0x9770768a } + +func (item *TupleInt) Reset() { + ptr := (*[]int32)(item) + *ptr = (*ptr)[:0] +} + +func (item *TupleInt) FillRandom(rg *basictl.RandGenerator, nat_n uint32) { + ptr := (*[]int32)(item) + tlBuiltinTupleInt.BuiltinTupleIntFillRandom(rg, ptr, nat_n) +} + +func (item *TupleInt) Read(w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[]int32)(item) + return tlBuiltinTupleInt.BuiltinTupleIntRead(w, ptr, nat_n) +} + +// This method is general version of Write, use it instead! +func (item *TupleInt) WriteGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.Write(w, nat_n) +} + +func (item *TupleInt) Write(w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[]int32)(item) + return tlBuiltinTupleInt.BuiltinTupleIntWrite(w, *ptr, nat_n) +} + +func (item *TupleInt) ReadBoxed(w []byte, nat_n uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x9770768a); err != nil { + return w, err + } + return item.Read(w, nat_n) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *TupleInt) WriteBoxedGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_n) +} + +func (item *TupleInt) WriteBoxed(w []byte, nat_n uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x9770768a) + return item.Write(w, nat_n) +} + +func (item *TupleInt) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_n uint32) error { + ptr := (*[]int32)(item) + if err := tlBuiltinTupleInt.BuiltinTupleIntReadJSON(legacyTypeNames, in, ptr, nat_n); err != nil { + return err + } + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *TupleInt) WriteJSONGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteJSON(w, nat_n) +} + +func (item *TupleInt) WriteJSON(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_n) +} + +func (item *TupleInt) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[]int32)(item) + if w, err = tlBuiltinTupleInt.BuiltinTupleIntWriteJSONOpt(newTypeNames, short, w, *ptr, nat_n); err != nil { + return w, err + } + return w, nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt2/tuple.go new file mode 100644 index 0000000..86d1099 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleInt2/tuple.go @@ -0,0 +1,101 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2Int" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type TupleInt2 [2]int32 + +func (TupleInt2) TLName() string { return "tuple" } +func (TupleInt2) TLTag() uint32 { return 0x9770768a } + +func (item *TupleInt2) Reset() { + ptr := (*[2]int32)(item) + tlBuiltinTuple2Int.BuiltinTuple2IntReset(ptr) +} + +func (item *TupleInt2) FillRandom(rg *basictl.RandGenerator) { + ptr := (*[2]int32)(item) + tlBuiltinTuple2Int.BuiltinTuple2IntFillRandom(rg, ptr) +} + +func (item *TupleInt2) Read(w []byte) (_ []byte, err error) { + ptr := (*[2]int32)(item) + return tlBuiltinTuple2Int.BuiltinTuple2IntRead(w, ptr) +} + +// This method is general version of Write, use it instead! +func (item *TupleInt2) WriteGeneral(w []byte) (_ []byte, err error) { + return item.Write(w), nil +} + +func (item *TupleInt2) Write(w []byte) []byte { + ptr := (*[2]int32)(item) + return tlBuiltinTuple2Int.BuiltinTuple2IntWrite(w, ptr) +} + +func (item *TupleInt2) ReadBoxed(w []byte) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x9770768a); err != nil { + return w, err + } + return item.Read(w) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *TupleInt2) WriteBoxedGeneral(w []byte) (_ []byte, err error) { + return item.WriteBoxed(w), nil +} + +func (item *TupleInt2) WriteBoxed(w []byte) []byte { + w = basictl.NatWrite(w, 0x9770768a) + return item.Write(w) +} + +func (item TupleInt2) String() string { + return string(item.WriteJSON(nil)) +} + +func (item *TupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer) error { + ptr := (*[2]int32)(item) + if err := tlBuiltinTuple2Int.BuiltinTuple2IntReadJSON(legacyTypeNames, in, ptr); err != nil { + return err + } + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *TupleInt2) WriteJSONGeneral(w []byte) (_ []byte, err error) { + return item.WriteJSON(w), nil +} + +func (item *TupleInt2) WriteJSON(w []byte) []byte { + return item.WriteJSONOpt(true, false, w) +} + +func (item *TupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte) []byte { + ptr := (*[2]int32)(item) + w = tlBuiltinTuple2Int.BuiltinTuple2IntWriteJSONOpt(newTypeNames, short, w, ptr) + return w +} +func (item *TupleInt2) MarshalJSON() ([]byte, error) { + return item.WriteJSON(nil), nil +} + +func (item *TupleInt2) UnmarshalJSON(b []byte) error { + if err := item.ReadJSON(true, &basictl.JsonLexer{Data: b}); err != nil { + return internal.ErrorInvalidJSON("tuple", err.Error()) + } + return nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlTuplePairTupleIntTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlTuplePairTupleIntTupleInt2/tuple.go new file mode 100644 index 0000000..b35bb89 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlTuplePairTupleIntTupleInt2/tuple.go @@ -0,0 +1,90 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlTuplePairTupleIntTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple2PairTupleIntTupleInt" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type TuplePairTupleIntTupleInt2 [2]tlPairTupleIntTupleInt.PairTupleIntTupleInt + +func (TuplePairTupleIntTupleInt2) TLName() string { return "tuple" } +func (TuplePairTupleIntTupleInt2) TLTag() uint32 { return 0x9770768a } + +func (item *TuplePairTupleIntTupleInt2) Reset() { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntReset(ptr) +} + +func (item *TuplePairTupleIntTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_tXn uint32, nat_tYn uint32) { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntFillRandom(rg, ptr, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) Read(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + return tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntRead(w, ptr, nat_tXn, nat_tYn) +} + +// This method is general version of Write, use it instead! +func (item *TuplePairTupleIntTupleInt2) WriteGeneral(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + return item.Write(w, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) Write(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + return tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntWrite(w, ptr, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) ReadBoxed(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x9770768a); err != nil { + return w, err + } + return item.Read(w, nat_tXn, nat_tYn) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *TuplePairTupleIntTupleInt2) WriteBoxedGeneral(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) WriteBoxed(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x9770768a) + return item.Write(w, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_tXn uint32, nat_tYn uint32) error { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + if err := tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntReadJSON(legacyTypeNames, in, ptr, nat_tXn, nat_tYn); err != nil { + return err + } + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *TuplePairTupleIntTupleInt2) WriteJSONGeneral(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + return item.WriteJSON(w, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) WriteJSON(w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_tXn, nat_tYn) +} + +func (item *TuplePairTupleIntTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_tXn uint32, nat_tYn uint32) (_ []byte, err error) { + ptr := (*[2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + if w, err = tlBuiltinTuple2PairTupleIntTupleInt.BuiltinTuple2PairTupleIntTupleIntWriteJSONOpt(newTypeNames, short, w, ptr, nat_tXn, nat_tYn); err != nil { + return w, err + } + return w, nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTupleInt2/tuple.go new file mode 100644 index 0000000..db2f7f4 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTupleInt2/tuple.go @@ -0,0 +1,89 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlTupleTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type TupleTupleInt2 [][2]int32 + +func (TupleTupleInt2) TLName() string { return "tuple" } +func (TupleTupleInt2) TLTag() uint32 { return 0x9770768a } + +func (item *TupleTupleInt2) Reset() { + ptr := (*[][2]int32)(item) + *ptr = (*ptr)[:0] +} + +func (item *TupleTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_n uint32) { + ptr := (*[][2]int32)(item) + tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2FillRandom(rg, ptr, nat_n) +} + +func (item *TupleTupleInt2) Read(w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]int32)(item) + return tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Read(w, ptr, nat_n) +} + +// This method is general version of Write, use it instead! +func (item *TupleTupleInt2) WriteGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.Write(w, nat_n) +} + +func (item *TupleTupleInt2) Write(w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]int32)(item) + return tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2Write(w, *ptr, nat_n) +} + +func (item *TupleTupleInt2) ReadBoxed(w []byte, nat_n uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x9770768a); err != nil { + return w, err + } + return item.Read(w, nat_n) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *TupleTupleInt2) WriteBoxedGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_n) +} + +func (item *TupleTupleInt2) WriteBoxed(w []byte, nat_n uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x9770768a) + return item.Write(w, nat_n) +} + +func (item *TupleTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_n uint32) error { + ptr := (*[][2]int32)(item) + if err := tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2ReadJSON(legacyTypeNames, in, ptr, nat_n); err != nil { + return err + } + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *TupleTupleInt2) WriteJSONGeneral(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteJSON(w, nat_n) +} + +func (item *TupleTupleInt2) WriteJSON(w []byte, nat_n uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_n) +} + +func (item *TupleTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]int32)(item) + if w, err = tlBuiltinTupleTupleInt2.BuiltinTupleTupleInt2WriteJSONOpt(newTypeNames, short, w, *ptr, nat_n); err != nil { + return w, err + } + return w, nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTuplePairTupleIntTupleInt2/tuple.go b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTuplePairTupleIntTupleInt2/tuple.go new file mode 100644 index 0000000..53e0c78 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tl/tlTupleTuplePairTupleIntTupleInt2/tuple.go @@ -0,0 +1,90 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlTupleTuplePairTupleIntTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleTuplePairTupleIntTupleInt2" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type TupleTuplePairTupleIntTupleInt2 [][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt + +func (TupleTuplePairTupleIntTupleInt2) TLName() string { return "tuple" } +func (TupleTuplePairTupleIntTupleInt2) TLTag() uint32 { return 0x9770768a } + +func (item *TupleTuplePairTupleIntTupleInt2) Reset() { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + *ptr = (*ptr)[:0] +} + +func (item *TupleTuplePairTupleIntTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2FillRandom(rg, ptr, nat_n, nat_ttXn, nat_ttYn) +} + +func (item *TupleTuplePairTupleIntTupleInt2) Read(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + return tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Read(w, ptr, nat_n, nat_ttXn, nat_ttYn) +} + +// This method is general version of Write, use it instead! +func (item *TupleTuplePairTupleIntTupleInt2) WriteGeneral(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + return item.Write(w, nat_ttXn, nat_ttYn, nat_n) +} + +func (item *TupleTuplePairTupleIntTupleInt2) Write(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + return tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2Write(w, *ptr, nat_n, nat_ttXn, nat_ttYn) +} + +func (item *TupleTuplePairTupleIntTupleInt2) ReadBoxed(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x9770768a); err != nil { + return w, err + } + return item.Read(w, nat_ttXn, nat_ttYn, nat_n) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *TupleTuplePairTupleIntTupleInt2) WriteBoxedGeneral(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_ttXn, nat_ttYn, nat_n) +} + +func (item *TupleTuplePairTupleIntTupleInt2) WriteBoxed(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x9770768a) + return item.Write(w, nat_ttXn, nat_ttYn, nat_n) +} + +func (item *TupleTuplePairTupleIntTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) error { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + if err := tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2ReadJSON(legacyTypeNames, in, ptr, nat_n, nat_ttXn, nat_ttYn); err != nil { + return err + } + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *TupleTuplePairTupleIntTupleInt2) WriteJSONGeneral(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + return item.WriteJSON(w, nat_ttXn, nat_ttYn, nat_n) +} + +func (item *TupleTuplePairTupleIntTupleInt2) WriteJSON(w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_ttXn, nat_ttYn, nat_n) +} + +func (item *TupleTuplePairTupleIntTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_ttXn uint32, nat_ttYn uint32, nat_n uint32) (_ []byte, err error) { + ptr := (*[][2]tlPairTupleIntTupleInt.PairTupleIntTupleInt)(item) + if w, err = tlBuiltinTupleTuplePairTupleIntTupleInt2.BuiltinTupleTuplePairTupleIntTupleInt2WriteJSONOpt(newTypeNames, short, w, *ptr, nat_n, nat_ttXn, nat_ttYn); err != nil { + return w, err + } + return w, nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int/cases.inplace1.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int/cases.inplace1.go new file mode 100644 index 0000000..f2dc746 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int/cases.inplace1.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace1Int + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace1Int struct { + Value tlCasesInplace2Int.CasesInplace2Int +} + +func (CasesInplace1Int) TLName() string { return "cases.inplace1" } +func (CasesInplace1Int) TLTag() uint32 { return 0x5533e8e9 } + +func (item *CasesInplace1Int) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace1Int) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) { + item.Value.FillRandom(rg, nat_a2, nat_a3, nat_a1) +} + +func (item *CasesInplace1Int) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_a2, nat_a3, nat_a1) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace1Int) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace1Int) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_a2, nat_a3, nat_a1); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace1Int) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x5533e8e9); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace1Int) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace1Int) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x5533e8e9) + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace1Int) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace1", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace1", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_a2, nat_a3, nat_a1); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace1Int) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace1Int) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} +func (item *CasesInplace1Int) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_a2, nat_a3, nat_a1); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt/cases.inplace1.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt/cases.inplace1.go new file mode 100644 index 0000000..9765874 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt/cases.inplace1.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace1PairTupleIntTupleInt + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace1PairTupleIntTupleInt struct { + Value tlCasesInplace2PairTupleIntTupleInt.CasesInplace2PairTupleIntTupleInt +} + +func (CasesInplace1PairTupleIntTupleInt) TLName() string { return "cases.inplace1" } +func (CasesInplace1PairTupleIntTupleInt) TLTag() uint32 { return 0x5533e8e9 } + +func (item *CasesInplace1PairTupleIntTupleInt) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace1PairTupleIntTupleInt) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) { + item.Value.FillRandom(rg, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn) +} + +func (item *CasesInplace1PairTupleIntTupleInt) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace1PairTupleIntTupleInt) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace1PairTupleIntTupleInt) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace1PairTupleIntTupleInt) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x5533e8e9); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace1PairTupleIntTupleInt) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace1PairTupleIntTupleInt) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x5533e8e9) + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace1PairTupleIntTupleInt) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace1", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace1", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace1PairTupleIntTupleInt) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace1PairTupleIntTupleInt) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} +func (item *CasesInplace1PairTupleIntTupleInt) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int/cases.inplace2.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int/cases.inplace2.go new file mode 100644 index 0000000..7ef9496 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2Int/cases.inplace2.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace2Int + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace2Int struct { + Value tlCasesInplace3TupleInt2.CasesInplace3TupleInt2 +} + +func (CasesInplace2Int) TLName() string { return "cases.inplace2" } +func (CasesInplace2Int) TLTag() uint32 { return 0x869fcff5 } + +func (item *CasesInplace2Int) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace2Int) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) { + item.Value.FillRandom(rg, nat_a2, nat_a3, nat_a1) +} + +func (item *CasesInplace2Int) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_a2, nat_a3, nat_a1) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace2Int) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace2Int) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_a2, nat_a3, nat_a1); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace2Int) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x869fcff5); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace2Int) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace2Int) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x869fcff5) + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace2Int) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace2", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace2", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_a2, nat_a3, nat_a1); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace2Int) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace2Int) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} +func (item *CasesInplace2Int) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_a2, nat_a3, nat_a1); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt/cases.inplace2.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt/cases.inplace2.go new file mode 100644 index 0000000..589a638 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace2PairTupleIntTupleInt/cases.inplace2.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace2PairTupleIntTupleInt + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace2PairTupleIntTupleInt struct { + Value tlCasesInplace3TuplePairTupleIntTupleInt2.CasesInplace3TuplePairTupleIntTupleInt2 +} + +func (CasesInplace2PairTupleIntTupleInt) TLName() string { return "cases.inplace2" } +func (CasesInplace2PairTupleIntTupleInt) TLTag() uint32 { return 0x869fcff5 } + +func (item *CasesInplace2PairTupleIntTupleInt) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace2PairTupleIntTupleInt) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) { + item.Value.FillRandom(rg, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn) +} + +func (item *CasesInplace2PairTupleIntTupleInt) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace2PairTupleIntTupleInt) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace2PairTupleIntTupleInt) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace2PairTupleIntTupleInt) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x869fcff5); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace2PairTupleIntTupleInt) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace2PairTupleIntTupleInt) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x869fcff5) + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace2PairTupleIntTupleInt) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace2", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace2", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace2PairTupleIntTupleInt) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} + +func (item *CasesInplace2PairTupleIntTupleInt) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XXn, nat_XYn) +} +func (item *CasesInplace2PairTupleIntTupleInt) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XXn uint32, nat_XYn uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_a2, nat_a3, nat_a1, nat_XXn, nat_XYn); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2/cases.inplace3.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2/cases.inplace3.go new file mode 100644 index 0000000..88c9889 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TupleInt2/cases.inplace3.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace3TupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTupleInt2TupleTupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace3TupleInt2 struct { + Value tlPairTupleTupleInt2TupleTupleInt2.PairTupleTupleInt2TupleTupleInt2 +} + +func (CasesInplace3TupleInt2) TLName() string { return "cases.inplace3" } +func (CasesInplace3TupleInt2) TLTag() uint32 { return 0x4ffb95cb } + +func (item *CasesInplace3TupleInt2) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace3TupleInt2) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) { + item.Value.FillRandom(rg, nat_a2, nat_a3) +} + +func (item *CasesInplace3TupleInt2) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_a2, nat_a3) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace3TupleInt2) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace3TupleInt2) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_a2, nat_a3); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace3TupleInt2) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x4ffb95cb); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace3TupleInt2) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace3TupleInt2) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x4ffb95cb) + return item.Write(w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace3TupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace3", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace3", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_a2, nat_a3); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace3TupleInt2) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} + +func (item *CasesInplace3TupleInt2) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3) +} +func (item *CasesInplace3TupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_a2, nat_a3); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2/cases.inplace3.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2/cases.inplace3.go new file mode 100644 index 0000000..b9d87b2 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace3TuplePairTupleIntTupleInt2/cases.inplace3.go @@ -0,0 +1,125 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesInplace3TuplePairTupleIntTupleInt2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tl/tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesInplace3TuplePairTupleIntTupleInt2 struct { + Value tlPairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2.PairTupleTuplePairTupleIntTupleInt2TupleTuplePairTupleIntTupleInt2 +} + +func (CasesInplace3TuplePairTupleIntTupleInt2) TLName() string { return "cases.inplace3" } +func (CasesInplace3TuplePairTupleIntTupleInt2) TLTag() uint32 { return 0x4ffb95cb } + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) Reset() { + item.Value.Reset() +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) FillRandom(rg *basictl.RandGenerator, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) { + item.Value.FillRandom(rg, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3) +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) Read(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + return item.Value.Read(w, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3) +} + +// This method is general version of Write, use it instead! +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) Write(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + if w, err = item.Value.Write(w, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) ReadBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0x4ffb95cb); err != nil { + return w, err + } + return item.Read(w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteBoxedGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + return item.WriteBoxed(w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteBoxed(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + w = basictl.NatWrite(w, 0x4ffb95cb) + return item.Write(w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) error { + var rawValue []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "value": + if rawValue != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.inplace3", "value") + } + rawValue = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.inplace3", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + var inValuePointer *basictl.JsonLexer + inValue := basictl.JsonLexer{Data: rawValue} + if rawValue != nil { + inValuePointer = &inValue + } + if err := item.Value.ReadJSON(legacyTypeNames, inValuePointer, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteJSONGeneral(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} + +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteJSON(w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w, nat_a1, nat_a2, nat_a3, nat_XtXn, nat_XtYn) +} +func (item *CasesInplace3TuplePairTupleIntTupleInt2) WriteJSONOpt(newTypeNames bool, short bool, w []byte, nat_a1 uint32, nat_a2 uint32, nat_a3 uint32, nat_XtXn uint32, nat_XtYn uint32) (_ []byte, err error) { + w = append(w, '{') + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"value":`...) + if w, err = item.Value.WriteJSONOpt(newTypeNames, short, w, nat_XtXn, nat_XtYn, nat_a2, nat_XtXn, nat_XtYn, nat_a3); err != nil { + return w, err + } + return append(w, '}'), nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs/cases.testInplaceStructArgs.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs/cases.testInplaceStructArgs.go new file mode 100644 index 0000000..5d4c745 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs/cases.testInplaceStructArgs.go @@ -0,0 +1,219 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesTestInplaceStructArgs + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1Int" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesTestInplaceStructArgs struct { + A1 uint32 + A2 uint32 + A3 uint32 + Arg tlCasesInplace1Int.CasesInplace1Int +} + +func (CasesTestInplaceStructArgs) TLName() string { return "cases.testInplaceStructArgs" } +func (CasesTestInplaceStructArgs) TLTag() uint32 { return 0xa9e4441e } + +func (item *CasesTestInplaceStructArgs) Reset() { + item.A1 = 0 + item.A2 = 0 + item.A3 = 0 + item.Arg.Reset() +} + +func (item *CasesTestInplaceStructArgs) FillRandom(rg *basictl.RandGenerator) { + item.Arg.FillRandom(rg, item.A1, item.A2, item.A3) +} + +func (item *CasesTestInplaceStructArgs) Read(w []byte) (_ []byte, err error) { + if w, err = basictl.NatRead(w, &item.A1); err != nil { + return w, err + } + if w, err = basictl.NatRead(w, &item.A2); err != nil { + return w, err + } + if w, err = basictl.NatRead(w, &item.A3); err != nil { + return w, err + } + return item.Arg.Read(w, item.A1, item.A2, item.A3) +} + +// This method is general version of Write, use it instead! +func (item *CasesTestInplaceStructArgs) WriteGeneral(w []byte) (_ []byte, err error) { + return item.Write(w) +} + +func (item *CasesTestInplaceStructArgs) Write(w []byte) (_ []byte, err error) { + w = basictl.NatWrite(w, item.A1) + w = basictl.NatWrite(w, item.A2) + w = basictl.NatWrite(w, item.A3) + if w, err = item.Arg.Write(w, item.A1, item.A2, item.A3); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesTestInplaceStructArgs) ReadBoxed(w []byte) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0xa9e4441e); err != nil { + return w, err + } + return item.Read(w) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesTestInplaceStructArgs) WriteBoxedGeneral(w []byte) (_ []byte, err error) { + return item.WriteBoxed(w) +} + +func (item *CasesTestInplaceStructArgs) WriteBoxed(w []byte) (_ []byte, err error) { + w = basictl.NatWrite(w, 0xa9e4441e) + return item.Write(w) +} + +func (item CasesTestInplaceStructArgs) String() string { + w, err := item.WriteJSON(nil) + if err != nil { + return err.Error() + } + return string(w) +} + +func (item *CasesTestInplaceStructArgs) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer) error { + var propA1Presented bool + var propA2Presented bool + var propA3Presented bool + var rawArg []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "a1": + if propA1Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs", "a1") + } + if err := internal.Json2ReadUint32(in, &item.A1); err != nil { + return err + } + propA1Presented = true + case "a2": + if propA2Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs", "a2") + } + if err := internal.Json2ReadUint32(in, &item.A2); err != nil { + return err + } + propA2Presented = true + case "a3": + if propA3Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs", "a3") + } + if err := internal.Json2ReadUint32(in, &item.A3); err != nil { + return err + } + propA3Presented = true + case "arg": + if rawArg != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs", "arg") + } + rawArg = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.testInplaceStructArgs", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + if !propA1Presented { + item.A1 = 0 + } + if !propA2Presented { + item.A2 = 0 + } + if !propA3Presented { + item.A3 = 0 + } + var inArgPointer *basictl.JsonLexer + inArg := basictl.JsonLexer{Data: rawArg} + if rawArg != nil { + inArgPointer = &inArg + } + if err := item.Arg.ReadJSON(legacyTypeNames, inArgPointer, item.A1, item.A2, item.A3); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesTestInplaceStructArgs) WriteJSONGeneral(w []byte) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w) +} + +func (item *CasesTestInplaceStructArgs) WriteJSON(w []byte) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w) +} +func (item *CasesTestInplaceStructArgs) WriteJSONOpt(newTypeNames bool, short bool, w []byte) (_ []byte, err error) { + w = append(w, '{') + backupIndexA1 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a1":`...) + w = basictl.JSONWriteUint32(w, item.A1) + if (item.A1 != 0) == false { + w = w[:backupIndexA1] + } + backupIndexA2 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a2":`...) + w = basictl.JSONWriteUint32(w, item.A2) + if (item.A2 != 0) == false { + w = w[:backupIndexA2] + } + backupIndexA3 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a3":`...) + w = basictl.JSONWriteUint32(w, item.A3) + if (item.A3 != 0) == false { + w = w[:backupIndexA3] + } + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"arg":`...) + if w, err = item.Arg.WriteJSONOpt(newTypeNames, short, w, item.A1, item.A2, item.A3); err != nil { + return w, err + } + return append(w, '}'), nil +} + +func (item *CasesTestInplaceStructArgs) MarshalJSON() ([]byte, error) { + return item.WriteJSON(nil) +} + +func (item *CasesTestInplaceStructArgs) UnmarshalJSON(b []byte) error { + if err := item.ReadJSON(true, &basictl.JsonLexer{Data: b}); err != nil { + return internal.ErrorInvalidJSON("cases.testInplaceStructArgs", err.Error()) + } + return nil +} diff --git a/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2/cases.testInplaceStructArgs2.go b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2/cases.testInplaceStructArgs2.go new file mode 100644 index 0000000..e66ec04 --- /dev/null +++ b/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesTestInplaceStructArgs2/cases.testInplaceStructArgs2.go @@ -0,0 +1,219 @@ +// Copyright 2022 V Kontakte LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// Code generated by vktl/cmd/tlgen2; DO NOT EDIT. +package tlCasesTestInplaceStructArgs2 + +import ( + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal" + "github.com/vkcom/tl/internal/tlcodegen/test/gen/cases/internal/tlcases/tlCasesInplace1PairTupleIntTupleInt" + "github.com/vkcom/tl/pkg/basictl" +) + +var _ = basictl.NatWrite +var _ = internal.ErrorInvalidEnumTag + +type CasesTestInplaceStructArgs2 struct { + A1 uint32 + A2 uint32 + A3 uint32 + Arg tlCasesInplace1PairTupleIntTupleInt.CasesInplace1PairTupleIntTupleInt +} + +func (CasesTestInplaceStructArgs2) TLName() string { return "cases.testInplaceStructArgs2" } +func (CasesTestInplaceStructArgs2) TLTag() uint32 { return 0xaa9f2480 } + +func (item *CasesTestInplaceStructArgs2) Reset() { + item.A1 = 0 + item.A2 = 0 + item.A3 = 0 + item.Arg.Reset() +} + +func (item *CasesTestInplaceStructArgs2) FillRandom(rg *basictl.RandGenerator) { + item.Arg.FillRandom(rg, item.A1, item.A2, item.A3, item.A3, item.A2) +} + +func (item *CasesTestInplaceStructArgs2) Read(w []byte) (_ []byte, err error) { + if w, err = basictl.NatRead(w, &item.A1); err != nil { + return w, err + } + if w, err = basictl.NatRead(w, &item.A2); err != nil { + return w, err + } + if w, err = basictl.NatRead(w, &item.A3); err != nil { + return w, err + } + return item.Arg.Read(w, item.A1, item.A2, item.A3, item.A3, item.A2) +} + +// This method is general version of Write, use it instead! +func (item *CasesTestInplaceStructArgs2) WriteGeneral(w []byte) (_ []byte, err error) { + return item.Write(w) +} + +func (item *CasesTestInplaceStructArgs2) Write(w []byte) (_ []byte, err error) { + w = basictl.NatWrite(w, item.A1) + w = basictl.NatWrite(w, item.A2) + w = basictl.NatWrite(w, item.A3) + if w, err = item.Arg.Write(w, item.A1, item.A2, item.A3, item.A3, item.A2); err != nil { + return w, err + } + return w, nil +} + +func (item *CasesTestInplaceStructArgs2) ReadBoxed(w []byte) (_ []byte, err error) { + if w, err = basictl.NatReadExactTag(w, 0xaa9f2480); err != nil { + return w, err + } + return item.Read(w) +} + +// This method is general version of WriteBoxed, use it instead! +func (item *CasesTestInplaceStructArgs2) WriteBoxedGeneral(w []byte) (_ []byte, err error) { + return item.WriteBoxed(w) +} + +func (item *CasesTestInplaceStructArgs2) WriteBoxed(w []byte) (_ []byte, err error) { + w = basictl.NatWrite(w, 0xaa9f2480) + return item.Write(w) +} + +func (item CasesTestInplaceStructArgs2) String() string { + w, err := item.WriteJSON(nil) + if err != nil { + return err.Error() + } + return string(w) +} + +func (item *CasesTestInplaceStructArgs2) ReadJSON(legacyTypeNames bool, in *basictl.JsonLexer) error { + var propA1Presented bool + var propA2Presented bool + var propA3Presented bool + var rawArg []byte + + if in != nil { + in.Delim('{') + if !in.Ok() { + return in.Error() + } + for !in.IsDelim('}') { + key := in.UnsafeFieldName(true) + in.WantColon() + switch key { + case "a1": + if propA1Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs2", "a1") + } + if err := internal.Json2ReadUint32(in, &item.A1); err != nil { + return err + } + propA1Presented = true + case "a2": + if propA2Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs2", "a2") + } + if err := internal.Json2ReadUint32(in, &item.A2); err != nil { + return err + } + propA2Presented = true + case "a3": + if propA3Presented { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs2", "a3") + } + if err := internal.Json2ReadUint32(in, &item.A3); err != nil { + return err + } + propA3Presented = true + case "arg": + if rawArg != nil { + return internal.ErrorInvalidJSONWithDuplicatingKeys("cases.testInplaceStructArgs2", "arg") + } + rawArg = in.Raw() + if !in.Ok() { + return in.Error() + } + default: + return internal.ErrorInvalidJSONExcessElement("cases.testInplaceStructArgs2", key) + } + in.WantComma() + } + in.Delim('}') + if !in.Ok() { + return in.Error() + } + } + if !propA1Presented { + item.A1 = 0 + } + if !propA2Presented { + item.A2 = 0 + } + if !propA3Presented { + item.A3 = 0 + } + var inArgPointer *basictl.JsonLexer + inArg := basictl.JsonLexer{Data: rawArg} + if rawArg != nil { + inArgPointer = &inArg + } + if err := item.Arg.ReadJSON(legacyTypeNames, inArgPointer, item.A1, item.A2, item.A3, item.A3, item.A2); err != nil { + return err + } + + return nil +} + +// This method is general version of WriteJSON, use it instead! +func (item *CasesTestInplaceStructArgs2) WriteJSONGeneral(w []byte) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w) +} + +func (item *CasesTestInplaceStructArgs2) WriteJSON(w []byte) (_ []byte, err error) { + return item.WriteJSONOpt(true, false, w) +} +func (item *CasesTestInplaceStructArgs2) WriteJSONOpt(newTypeNames bool, short bool, w []byte) (_ []byte, err error) { + w = append(w, '{') + backupIndexA1 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a1":`...) + w = basictl.JSONWriteUint32(w, item.A1) + if (item.A1 != 0) == false { + w = w[:backupIndexA1] + } + backupIndexA2 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a2":`...) + w = basictl.JSONWriteUint32(w, item.A2) + if (item.A2 != 0) == false { + w = w[:backupIndexA2] + } + backupIndexA3 := len(w) + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"a3":`...) + w = basictl.JSONWriteUint32(w, item.A3) + if (item.A3 != 0) == false { + w = w[:backupIndexA3] + } + w = basictl.JSONAddCommaIfNeeded(w) + w = append(w, `"arg":`...) + if w, err = item.Arg.WriteJSONOpt(newTypeNames, short, w, item.A1, item.A2, item.A3, item.A3, item.A2); err != nil { + return w, err + } + return append(w, '}'), nil +} + +func (item *CasesTestInplaceStructArgs2) MarshalJSON() ([]byte, error) { + return item.WriteJSON(nil) +} + +func (item *CasesTestInplaceStructArgs2) UnmarshalJSON(b []byte) error { + if err := item.ReadJSON(true, &basictl.JsonLexer{Data: b}); err != nil { + return internal.ErrorInvalidJSON("cases.testInplaceStructArgs2", err.Error()) + } + return nil +} From 1aa708435b73a46d7372a3c9d836e8fe626beaaa Mon Sep 17 00:00:00 2001 From: Fedor Vikhnin Date: Wed, 22 Jan 2025 17:51:21 +0300 Subject: [PATCH 37/37] return !== null to restore compatibility with og version --- internal/tlcodegen/type_rw_struct_php.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/tlcodegen/type_rw_struct_php.go b/internal/tlcodegen/type_rw_struct_php.go index d6dd3ed..a0ba755 100644 --- a/internal/tlcodegen/type_rw_struct_php.go +++ b/internal/tlcodegen/type_rw_struct_php.go @@ -577,7 +577,7 @@ func (trw *TypeRWStruct) PHPStructFieldMaskCalculators(code *strings.Builder, us condition = fmt.Sprintf("$has_%s", dependentField.originalName) } else { condition = fmt.Sprintf( - "!is_null($this->%[1]s)", + "$this->%[1]s !== null", dependentField.originalName, ) }