@@ -911,7 +911,7 @@ func (trw *TypeRWStruct) PHPStructReadMethods(code *strings.Builder) {
911911 usedBytes := "$used_bytes"
912912 code .WriteString (fmt .Sprintf ("%[1]s%[2]s = 0;\n " , tab , usedBytes ))
913913
914- for _ , line := range trw .phpStructReadTL2Code ("$this" , usedBytes , nil , true ) {
914+ for _ , line := range trw .phpStructReadTL2Code ("$this" , usedBytes , nil , "" , 0 , true ) {
915915 code .WriteString (fmt .Sprintf ("%[1]s%[2]s\n " , tab , line ))
916916 }
917917
@@ -963,10 +963,15 @@ func (trw *TypeRWStruct) phpStructReadCode(targetName string, calculatedArgs *Ty
963963 return result
964964}
965965
966- func (trw * TypeRWStruct ) phpStructReadTL2Code (targetName string , usedBytesPointer string , calculatedArgs * TypeArgumentsTree , topLevel bool ) []string {
966+ func (trw * TypeRWStruct ) phpStructReadTL2Code (targetName string , usedBytesPointer string , calculatedArgs * TypeArgumentsTree , supportSuffix string , callLevel int , topLevel bool ) []string {
967967 currentSize := "$current_size"
968968 block := "$block"
969969
970+ if ! topLevel {
971+ currentSize = fmt .Sprintf ("$current_size_%s_%d" , supportSuffix , callLevel )
972+ block = fmt .Sprintf ("$block_%s_%d" , supportSuffix , callLevel )
973+ }
974+
970975 cc := codecreator .NewPhpCodeCreator ()
971976
972977 subtractSize := func (value string ) string {
@@ -1039,10 +1044,11 @@ func (trw *TypeRWStruct) phpStructReadTL2Code(targetName string, usedBytesPointe
10391044 }
10401045 cc .If (fmt .Sprintf ("($block & (1 << %d)) != 0" , inBlockIndex ), func (cc * codecreator.PhpCodeCreator ) {
10411046 tree := trw .PHPGetFieldNatDependenciesValuesAsTypeTree (fieldIndex , calculatedArgs )
1042- localUsedBytes := "$local_used_bytes"
1047+ localUsedBytes := fmt .Sprintf ("$local_used_bytes_%s_%d" , supportSuffix , callLevel )
1048+ cc .Comments ("local size for this field" )
10431049 cc .AddLines (fmt .Sprintf ("%[1]s = 0;" , localUsedBytes ))
10441050 cc .AddLines (
1045- field .t .trw .PhpReadTL2MethodCall (fieldName , field .bare , true , & tree , strconv .Itoa (fieldIndex ), 0 , localUsedBytes , field .fieldMask == nil )... ,
1051+ field .t .trw .PhpReadTL2MethodCall (fieldName , field .bare , true , & tree , strconv .Itoa (fieldIndex ), callLevel + 1 , localUsedBytes , field .fieldMask == nil )... ,
10461052 )
10471053 cc .AddLines (subtractSize (localUsedBytes ))
10481054 cc .If (fmt .Sprintf ("%[1]s < 0" , currentSize ), func (cc * codecreator.PhpCodeCreator ) {
@@ -2122,7 +2128,7 @@ func (trw *TypeRWStruct) PhpReadTL2MethodCall(targetName string, bare bool, init
21222128 )
21232129 }
21242130 if trw .wr .phpInfo .IsDuplicate {
2125- result = append (result , trw .phpStructReadTL2Code (targetName , usedBytesPointer , args , false )... )
2131+ result = append (result , trw .phpStructReadTL2Code (targetName , usedBytesPointer , args , supportSuffix , callLevel + 1 , false )... )
21262132 } else {
21272133 result = append (result ,
21282134 fmt .Sprintf ("%[3]s += %[1]s->read_tl2(%[2]s);" ,
0 commit comments