@@ -357,6 +357,10 @@ class %[1]s_result implements TL\RpcFunctionReturnResult {
357357 cc .AddLines (readCallLines ... )
358358 }, func () {
359359 // tl2 case
360+ cc .AddLines (cc .TLFetchUint32To ("$marker" ))
361+ cc .If (cc .NotEqual ("$marker" , "TL\\ tl2_support::Marker" ), func () {
362+ cc .AddLines ("throw new \\ Exception('can\\ 't fetch tl2 marker');" )
363+ })
360364 cc .AddLines ("$used_bytes = 0;" )
361365 cc .AddLines ("$obj_size = TL\\ tl2_support::fetch_size();" )
362366 cc .If ("$obj_size != 0" , func () {
@@ -393,18 +397,17 @@ class %[1]s_result implements TL\RpcFunctionReturnResult {
393397 cc .AddLines (writeCallLines ... )
394398 }, func () {
395399 cc .AddLines (
396- "$used_bytes = 0;" ,
397- ` $context_sizes = new TL\tl2_context();` ,
398- ` $context_blocks = new TL\tl2_context();` ,
400+ cc . Assign ( "$used_bytes" , "0" ) ,
401+ cc . Assign ( " $context_sizes" , ` new TL\tl2_context()` ) ,
402+ cc . Assign ( " $context_blocks" , ` new TL\tl2_context()` ) ,
399403 )
400404 cc .Comments ("calculate sizes" )
401- // TODO!
402405 cc .AddLines (trw .ResultType .trw .PhpCalculateSizesTL2MethodCall ("$result->value" , false , innerArgs , "" , 0 , "$used_bytes" , true )... )
403406 cc .Comments ("write result" )
407+ cc .AddLines (cc .TLStoreUint32 ("TL\\ tl2_support::Marker" ))
404408 cc .IfElse ("$used_bytes != 0" , func () {
405409 cc .AddLines ("TL\\ tl2_support::store_size(1 + $used_bytes);" )
406410 cc .AddLines ("store_byte(2);" )
407- // TODO!
408411 cc .AddLines (trw .ResultType .trw .PhpWriteTL2MethodCall ("$result->value" , false , innerArgs , "" , 0 , "$used_bytes" , false )... )
409412 }, func () {
410413 cc .AddLines ("TL\\ tl2_support::store_size(0);" )
@@ -574,26 +577,6 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder)
574577 trw .wr .TLTag (),
575578 ))
576579
577- //args := make([]string, 0)
578- //for _, arg := range trw.PHPFetcherArguments() {
579- // args = append(args, arg.FieldValue)
580- //}
581- //argsArray := strings.Join(args, ", ")
582-
583- var fetchArgNames []string
584- var fetchArgTypes []string
585-
586- var storeArgNames []string
587- var storeArgTypes []string
588-
589- if ! trw .wr .gen .options .PHP .UseBuiltinDataProviders {
590- fetchArgNames = append (fetchArgNames , "stream" )
591- fetchArgTypes = append (fetchArgTypes , `TL\tl_input_stream` )
592-
593- storeArgNames = append (storeArgNames , "stream" )
594- storeArgTypes = append (storeArgTypes , `TL\tl_output_stream` )
595- }
596-
597580 if trw .pureType .KernelType ().CanonicalName ().String () == "memcache.touch" {
598581 Debugf ("" )
599582 }
@@ -613,6 +596,7 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder)
613596
614597 tlMode := "$tl_mode"
615598 innerFetcher := "$fetcher"
599+ marker := "$marker"
616600
617601 hasTL2 := trw .wr .pureType .Common ().HasTL2 ()
618602 hasFetcher := trw .wr .pureType .Common ().KernelType ().IsExclamationWrapper ()
@@ -658,6 +642,7 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder)
658642 })
659643 if hasTL2 && ! hasFetcher {
660644 cc .If (cc .Equal (tlMode , "2" ), func () {
645+ cc .AddLines (fmt .Sprintf ("store_int(TL\\ tl2_support::Marker);" ))
661646 cc .AddLines (fmt .Sprintf ("store_int(0x%08[1]x);" , trw .wr .TLTag ()))
662647 cc .AddLines ("$this->write_tl2();" )
663648 if hasTL2 {
@@ -694,7 +679,11 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder)
694679 cc .AddLines (cc .Assign (tlMode , "1" ))
695680 })
696681 }
682+ cc .AddLines (cc .Assign (marker , "fetch_int() & 0xFFFFFFFF" ))
697683 cc .If (cc .Equal (tlMode , "1" ), func () {
684+ cc .If (cc .NotEqual (marker , fmt .Sprintf ("0x%08[1]x" , trw .wr .TLTag ())), func () {
685+ cc .AddLines (fmt .Sprintf (`throw new \Exception("expected tl tag:" + 0x%08[1]x);` , trw .wr .TLTag ()))
686+ })
698687 cc .AddLines ("$this->read();" )
699688 if hasFetcher {
700689 cc .AddLines (cc .Assign (innerFetcher , "$this->query->typedFetch()" ))
@@ -709,6 +698,13 @@ func (trw *TypeRWStruct) PHPStructFunctionSpecificMethods(code *strings.Builder)
709698 cc .AddLines (fmt .Sprintf ("return new %[1]s(%[2]s);" , fetcherClass , fetcherArgsCombined ))
710699 })
711700 if hasTL2 && ! hasFetcher {
701+ cc .If (cc .NotEqual (marker , "TL\\ tl2_support::Marker" ), func () {
702+ cc .AddLines (`throw new \Exception("expected tl2 marker");` )
703+ })
704+ cc .AddLines (cc .Assign (marker , "fetch_int() & 0xFFFFFFFF" ))
705+ cc .If (cc .NotEqual (marker , fmt .Sprintf ("0x%08[1]x" , trw .wr .TLTag ())), func () {
706+ cc .AddLines (fmt .Sprintf (`throw new \Exception("expected tl tag: " . 0x%08[1]x);` , trw .wr .TLTag ()))
707+ })
712708 cc .If (cc .Equal (tlMode , "2" ), func () {
713709 cc .AddLines ("$this->read_tl2();" )
714710 if hasTL2 {
0 commit comments