1<?hh // strict
2/**
3 * Autogenerated by Thrift
4 *
5 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
6 *  @generated
7 */
8
9/**
10 * Original thrift struct:-
11 * Foo
12 */
13class Foo implements \IThriftStruct, \IThriftShapishStruct {
14  use \ThriftSerializationTrait;
15
16  const dict<int, this::TFieldSpec> SPEC = dict[
17    1 => shape(
18      'var' => 'intField',
19      'adapter' => \Adapter1::class,
20      'type' => \TType::I32,
21    ),
22    2 => shape(
23      'var' => 'optionalIntField',
24      'adapter' => \Adapter1::class,
25      'type' => \TType::I32,
26    ),
27    3 => shape(
28      'var' => 'intFieldWithDefault',
29      'adapter' => \Adapter1::class,
30      'type' => \TType::I32,
31    ),
32    4 => shape(
33      'var' => 'setField',
34      'adapter' => \Adapter2::class,
35      'type' => \TType::SET,
36      'etype' => \TType::STRING,
37      'elem' => shape(
38        'type' => \TType::STRING,
39      ),
40      'format' => 'collection',
41    ),
42    5 => shape(
43      'var' => 'optionalSetField',
44      'adapter' => \Adapter2::class,
45      'type' => \TType::SET,
46      'etype' => \TType::STRING,
47      'elem' => shape(
48        'type' => \TType::STRING,
49      ),
50      'format' => 'collection',
51    ),
52    6 => shape(
53      'var' => 'mapField',
54      'adapter' => \Adapter3::class,
55      'type' => \TType::MAP,
56      'ktype' => \TType::STRING,
57      'vtype' => \TType::LST,
58      'key' => shape(
59        'type' => \TType::STRING,
60      ),
61      'val' => shape(
62        'adapter' => \Adapter2::class,
63        'type' => \TType::LST,
64        'etype' => \TType::STRING,
65        'elem' => shape(
66          'adapter' => \Adapter1::class,
67          'type' => \TType::STRING,
68        ),
69        'format' => 'collection',
70      ),
71      'format' => 'collection',
72    ),
73    7 => shape(
74      'var' => 'optionalMapField',
75      'adapter' => \Adapter3::class,
76      'type' => \TType::MAP,
77      'ktype' => \TType::STRING,
78      'vtype' => \TType::LST,
79      'key' => shape(
80        'type' => \TType::STRING,
81      ),
82      'val' => shape(
83        'adapter' => \Adapter2::class,
84        'type' => \TType::LST,
85        'etype' => \TType::STRING,
86        'elem' => shape(
87          'adapter' => \Adapter1::class,
88          'type' => \TType::STRING,
89        ),
90        'format' => 'collection',
91      ),
92      'format' => 'collection',
93    ),
94    8 => shape(
95      'var' => 'binaryField',
96      'adapter' => \Adapter1::class,
97      'type' => \TType::STRING,
98    ),
99  ];
100  const dict<string, int> FIELDMAP = dict[
101    'intField' => 1,
102    'optionalIntField' => 2,
103    'intFieldWithDefault' => 3,
104    'setField' => 4,
105    'optionalSetField' => 5,
106    'mapField' => 6,
107    'optionalMapField' => 7,
108    'binaryField' => 8,
109  ];
110
111  const type TConstructorShape = shape(
112    ?'intField' => ?\Adapter1::THackType,
113    ?'optionalIntField' => ?\Adapter1::THackType,
114    ?'intFieldWithDefault' => ?\Adapter1::THackType,
115    ?'setField' => ?\Adapter2::THackType,
116    ?'optionalSetField' => ?\Adapter2::THackType,
117    ?'mapField' => ?\Adapter3::THackType,
118    ?'optionalMapField' => ?\Adapter3::THackType,
119    ?'binaryField' => ?\Adapter1::THackType,
120  );
121
122  const type TShape = shape(
123    'intField' => \Adapter1::THackType,
124    ?'optionalIntField' => ?\Adapter1::THackType,
125    'intFieldWithDefault' => \Adapter1::THackType,
126    'setField' => \Adapter2::THackType,
127    ?'optionalSetField' => ?\Adapter2::THackType,
128    'mapField' => \Adapter3::THackType,
129    ?'optionalMapField' => ?\Adapter3::THackType,
130    'binaryField' => \Adapter1::THackType,
131  );
132  const int STRUCTURAL_ID = 3693521661416523209;
133  /**
134   * Original thrift field:-
135   * 1: i32 intField
136   */
137  public \Adapter1::THackType $intField;
138  /**
139   * Original thrift field:-
140   * 2: i32 optionalIntField
141   */
142  public ?\Adapter1::THackType $optionalIntField;
143  /**
144   * Original thrift field:-
145   * 3: i32 intFieldWithDefault
146   */
147  public \Adapter1::THackType $intFieldWithDefault;
148  /**
149   * Original thrift field:-
150   * 4: set<string> setField
151   */
152  public \Adapter2::THackType $setField;
153  /**
154   * Original thrift field:-
155   * 5: set<string> optionalSetField
156   */
157  public ?\Adapter2::THackType $optionalSetField;
158  /**
159   * Original thrift field:-
160   * 6: map<string, list<string>> mapField
161   */
162  public \Adapter3::THackType $mapField;
163  /**
164   * Original thrift field:-
165   * 7: map<string, list<string>> optionalMapField
166   */
167  public ?\Adapter3::THackType $optionalMapField;
168  /**
169   * Original thrift field:-
170   * 8: binary binaryField
171   */
172  public \Adapter1::THackType $binaryField;
173
174  public function __construct(?\Adapter1::THackType $intField = null, ?\Adapter1::THackType $optionalIntField = null, ?\Adapter1::THackType $intFieldWithDefault = null, ?\Adapter2::THackType $setField = null, ?\Adapter2::THackType $optionalSetField = null, ?\Adapter3::THackType $mapField = null, ?\Adapter3::THackType $optionalMapField = null, ?\Adapter1::THackType $binaryField = null  )[] {
175    $this->intField = $intField ?? \Adapter1::fromThrift(0);
176    $this->optionalIntField = $optionalIntField;
177    $this->intFieldWithDefault = $intFieldWithDefault ?? \Adapter1::fromThrift(13);
178    $this->setField = $setField ?? \Adapter2::fromThrift(Set {});
179    $this->optionalSetField = $optionalSetField;
180    $this->mapField = $mapField ?? \Adapter3::fromThrift(Map {});
181    $this->optionalMapField = $optionalMapField;
182    $this->binaryField = $binaryField ?? \Adapter1::fromThrift('');
183  }
184
185  public static function withDefaultValues()[]: this {
186    return new static();
187  }
188
189  public static function fromShape(self::TConstructorShape $shape)[]: this {
190    return new static(
191      Shapes::idx($shape, 'intField'),
192      Shapes::idx($shape, 'optionalIntField'),
193      Shapes::idx($shape, 'intFieldWithDefault'),
194      Shapes::idx($shape, 'setField'),
195      Shapes::idx($shape, 'optionalSetField'),
196      Shapes::idx($shape, 'mapField'),
197      Shapes::idx($shape, 'optionalMapField'),
198      Shapes::idx($shape, 'binaryField'),
199    );
200  }
201
202  public function getName()[]: string {
203    return 'Foo';
204  }
205
206  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
207    return tmeta_ThriftStruct::fromShape(
208      shape(
209        "name" => "module.Foo",
210        "fields" => vec[
211          tmeta_ThriftField::fromShape(
212            shape(
213              "id" => 1,
214              "type" => tmeta_ThriftType::fromShape(
215                shape(
216                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
217                )
218              ),
219              "name" => "intField",
220            )
221          ),
222          tmeta_ThriftField::fromShape(
223            shape(
224              "id" => 2,
225              "type" => tmeta_ThriftType::fromShape(
226                shape(
227                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
228                )
229              ),
230              "name" => "optionalIntField",
231              "is_optional" => true,
232            )
233          ),
234          tmeta_ThriftField::fromShape(
235            shape(
236              "id" => 3,
237              "type" => tmeta_ThriftType::fromShape(
238                shape(
239                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
240                )
241              ),
242              "name" => "intFieldWithDefault",
243            )
244          ),
245          tmeta_ThriftField::fromShape(
246            shape(
247              "id" => 4,
248              "type" => tmeta_ThriftType::fromShape(
249                shape(
250                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
251                    shape(
252                      "name" => "module.SetWithAdapter",
253                      "underlyingType" => tmeta_ThriftType::fromShape(
254                        shape(
255                          "t_set" => tmeta_ThriftSetType::fromShape(
256                            shape(
257                              "valueType" => tmeta_ThriftType::fromShape(
258                                shape(
259                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
260                                )
261                              ),
262                            )
263                          ),
264                        )
265                      ),
266                    )
267                  ),
268                )
269              ),
270              "name" => "setField",
271            )
272          ),
273          tmeta_ThriftField::fromShape(
274            shape(
275              "id" => 5,
276              "type" => tmeta_ThriftType::fromShape(
277                shape(
278                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
279                    shape(
280                      "name" => "module.SetWithAdapter",
281                      "underlyingType" => tmeta_ThriftType::fromShape(
282                        shape(
283                          "t_set" => tmeta_ThriftSetType::fromShape(
284                            shape(
285                              "valueType" => tmeta_ThriftType::fromShape(
286                                shape(
287                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
288                                )
289                              ),
290                            )
291                          ),
292                        )
293                      ),
294                    )
295                  ),
296                )
297              ),
298              "name" => "optionalSetField",
299              "is_optional" => true,
300            )
301          ),
302          tmeta_ThriftField::fromShape(
303            shape(
304              "id" => 6,
305              "type" => tmeta_ThriftType::fromShape(
306                shape(
307                  "t_map" => tmeta_ThriftMapType::fromShape(
308                    shape(
309                      "keyType" => tmeta_ThriftType::fromShape(
310                        shape(
311                          "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
312                        )
313                      ),
314                      "valueType" => tmeta_ThriftType::fromShape(
315                        shape(
316                          "t_typedef" => tmeta_ThriftTypedefType::fromShape(
317                            shape(
318                              "name" => "module.ListWithElemAdapter",
319                              "underlyingType" => tmeta_ThriftType::fromShape(
320                                shape(
321                                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
322                                    shape(
323                                      "name" => "module.ListWithElemAdapter",
324                                      "underlyingType" => tmeta_ThriftType::fromShape(
325                                        shape(
326                                          "t_list" => tmeta_ThriftListType::fromShape(
327                                            shape(
328                                              "valueType" => tmeta_ThriftType::fromShape(
329                                                shape(
330                                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
331                                                )
332                                              ),
333                                            )
334                                          ),
335                                        )
336                                      ),
337                                    )
338                                  ),
339                                )
340                              ),
341                            )
342                          ),
343                        )
344                      ),
345                    )
346                  ),
347                )
348              ),
349              "name" => "mapField",
350            )
351          ),
352          tmeta_ThriftField::fromShape(
353            shape(
354              "id" => 7,
355              "type" => tmeta_ThriftType::fromShape(
356                shape(
357                  "t_map" => tmeta_ThriftMapType::fromShape(
358                    shape(
359                      "keyType" => tmeta_ThriftType::fromShape(
360                        shape(
361                          "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
362                        )
363                      ),
364                      "valueType" => tmeta_ThriftType::fromShape(
365                        shape(
366                          "t_typedef" => tmeta_ThriftTypedefType::fromShape(
367                            shape(
368                              "name" => "module.ListWithElemAdapter",
369                              "underlyingType" => tmeta_ThriftType::fromShape(
370                                shape(
371                                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
372                                    shape(
373                                      "name" => "module.ListWithElemAdapter",
374                                      "underlyingType" => tmeta_ThriftType::fromShape(
375                                        shape(
376                                          "t_list" => tmeta_ThriftListType::fromShape(
377                                            shape(
378                                              "valueType" => tmeta_ThriftType::fromShape(
379                                                shape(
380                                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
381                                                )
382                                              ),
383                                            )
384                                          ),
385                                        )
386                                      ),
387                                    )
388                                  ),
389                                )
390                              ),
391                            )
392                          ),
393                        )
394                      ),
395                    )
396                  ),
397                )
398              ),
399              "name" => "optionalMapField",
400              "is_optional" => true,
401            )
402          ),
403          tmeta_ThriftField::fromShape(
404            shape(
405              "id" => 8,
406              "type" => tmeta_ThriftType::fromShape(
407                shape(
408                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_BINARY_TYPE,
409                )
410              ),
411              "name" => "binaryField",
412            )
413          ),
414        ],
415        "is_union" => false,
416      )
417    );
418  }
419
420  public static function getAllStructuredAnnotations()[]: \TStructAnnotations {
421    return shape(
422      'struct' => dict[],
423      'fields' => dict[
424      ],
425    );
426  }
427
428  public static function __fromShape(self::TShape $shape)[]: this {
429    return new static(
430      $shape['intField'],
431      Shapes::idx($shape, 'optionalIntField'),
432      $shape['intFieldWithDefault'],
433      new Set(Keyset\keys($shape['setField'])),
434      Shapes::idx($shape, 'optionalSetField') === null ? null : (new Set(Keyset\keys($shape['optionalSetField']))),
435      (new Map($shape['mapField']))->map(
436        $val0 ==> (new Vector($val0)),
437      ),
438      Shapes::idx($shape, 'optionalMapField') === null ? null : ((new Map($shape['optionalMapField']))->map(
439        $val1 ==> (new Vector($val1)),
440      )),
441      $shape['binaryField'],
442    );
443  }
444
445  public function __toShape()[]: self::TShape {
446    return shape(
447      'intField' => $this->intField,
448      'optionalIntField' => $this->optionalIntField,
449      'intFieldWithDefault' => $this->intFieldWithDefault,
450      'setField' => ThriftUtil::toDArray(Dict\fill_keys($this->setField->toValuesArray(), true), static::class),
451      'optionalSetField' => $this->optionalSetField
452        |> $$ === null ? null : ThriftUtil::toDArray(Dict\fill_keys($$->toValuesArray(), true), static::class),
453      'mapField' => $this->mapField->map(
454        ($_val0) ==> vec($_val0),
455      )
456        |> dict($$),
457      'optionalMapField' => $this->optionalMapField?->map(
458        ($_val0) ==> vec($_val0),
459      )
460        |> $$ === null ? null : dict($$),
461      'binaryField' => $this->binaryField,
462    );
463  }
464  public function readFromJson(string $jsonText): void {
465    $parsed = json_decode($jsonText, true);
466
467    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
468      throw new \TProtocolException("Cannot parse the given json string.");
469    }
470
471    if (idx($parsed, 'intField') !== null) {
472      $_tmp0 = (int)/* HH_FIXME[4110] */ $parsed['intField'];
473      if ($_tmp0 > 0x7fffffff) {
474        throw new \TProtocolException("number exceeds limit in field");
475      } else {
476        $this->intField = (int)$_tmp0;
477      }
478    }
479    if (idx($parsed, 'optionalIntField') !== null) {
480      $_tmp1 = (int)/* HH_FIXME[4110] */ $parsed['optionalIntField'];
481      if ($_tmp1 > 0x7fffffff) {
482        throw new \TProtocolException("number exceeds limit in field");
483      } else {
484        $this->optionalIntField = (int)$_tmp1;
485      }
486    }
487    if (idx($parsed, 'intFieldWithDefault') !== null) {
488      $_tmp2 = (int)/* HH_FIXME[4110] */ $parsed['intFieldWithDefault'];
489      if ($_tmp2 > 0x7fffffff) {
490        throw new \TProtocolException("number exceeds limit in field");
491      } else {
492        $this->intFieldWithDefault = (int)$_tmp2;
493      }
494    }
495    if (idx($parsed, 'setField') !== null) {
496      $_json6 = /* HH_FIXME[4110] */ $parsed['setField'];
497      $_container7 = Set {};
498      foreach(/* HH_FIXME[4110] */ $_json6 as $_key4 => $_value5) {
499        $_elem8 = '';
500        $_elem8 = $_value5;
501        $_container7->add($_elem8);
502      }
503      $this->setField = $_container7;
504    }
505    if (idx($parsed, 'optionalSetField') !== null) {
506      $_json12 = /* HH_FIXME[4110] */ $parsed['optionalSetField'];
507      $_container13 = Set {};
508      foreach(/* HH_FIXME[4110] */ $_json12 as $_key10 => $_value11) {
509        $_elem14 = '';
510        $_elem14 = $_value11;
511        $_container13->add($_elem14);
512      }
513      $this->optionalSetField = $_container13;
514    }
515    if (idx($parsed, 'mapField') !== null) {
516      $_json18 = /* HH_FIXME[4110] */ $parsed['mapField'];
517      $_container19 = Map {};
518      foreach(/* HH_FIXME[4110] */ $_json18 as $_key16 => $_value17) {
519        $_value20 = Vector {};
520        $_json24 = $_value17;
521        $_container25 = Vector {};
522        foreach(/* HH_FIXME[4110] */ $_json24 as $_key22 => $_value23) {
523          $_elem26 = '';
524          $_elem26 = $_value23;
525          $_container25 []= $_elem26;
526        }
527        $_value20 = $_container25;
528        $_container19[$_key16] = $_value20;
529      }
530      $this->mapField = $_container19;
531    }
532    if (idx($parsed, 'optionalMapField') !== null) {
533      $_json30 = /* HH_FIXME[4110] */ $parsed['optionalMapField'];
534      $_container31 = Map {};
535      foreach(/* HH_FIXME[4110] */ $_json30 as $_key28 => $_value29) {
536        $_value32 = Vector {};
537        $_json36 = $_value29;
538        $_container37 = Vector {};
539        foreach(/* HH_FIXME[4110] */ $_json36 as $_key34 => $_value35) {
540          $_elem38 = '';
541          $_elem38 = $_value35;
542          $_container37 []= $_elem38;
543        }
544        $_value32 = $_container37;
545        $_container31[$_key28] = $_value32;
546      }
547      $this->optionalMapField = $_container31;
548    }
549    if (idx($parsed, 'binaryField') !== null) {
550      $this->binaryField = /* HH_FIXME[4110] */ $parsed['binaryField'];
551    }
552  }
553
554  private static function __hackAdapterTypeChecks()[]: void {
555    \ThriftUtil::requireSameType<\Adapter1::TThriftType, int>();
556    \ThriftUtil::requireSameType<\Adapter1::TThriftType, string>();
557    \ThriftUtil::requireSameType<\Adapter2::TThriftType, Set<string>>();
558    \ThriftUtil::requireSameType<\Adapter2::TThriftType, Vector<\Adapter1::THackType>>();
559    \ThriftUtil::requireSameType<\Adapter3::TThriftType, Map<string, \Adapter2::THackType>>();
560  }
561
562}
563
564enum BazEnum: int {
565  _EMPTY_ = 0;
566  intField = 1;
567  setField = 4;
568  mapField = 6;
569  binaryField = 8;
570}
571
572/**
573 * Original thrift struct:-
574 * Baz
575 */
576class Baz implements \IThriftStruct, \IThriftUnion<BazEnum>, \IThriftShapishStruct {
577  use \ThriftUnionSerializationTrait;
578
579  const dict<int, this::TFieldSpec> SPEC = dict[
580    1 => shape(
581      'var' => 'intField',
582      'union' => true,
583      'adapter' => \Adapter1::class,
584      'type' => \TType::I32,
585    ),
586    4 => shape(
587      'var' => 'setField',
588      'union' => true,
589      'adapter' => \Adapter2::class,
590      'type' => \TType::SET,
591      'etype' => \TType::STRING,
592      'elem' => shape(
593        'type' => \TType::STRING,
594      ),
595      'format' => 'collection',
596    ),
597    6 => shape(
598      'var' => 'mapField',
599      'union' => true,
600      'adapter' => \Adapter3::class,
601      'type' => \TType::MAP,
602      'ktype' => \TType::STRING,
603      'vtype' => \TType::LST,
604      'key' => shape(
605        'type' => \TType::STRING,
606      ),
607      'val' => shape(
608        'adapter' => \Adapter2::class,
609        'type' => \TType::LST,
610        'etype' => \TType::STRING,
611        'elem' => shape(
612          'adapter' => \Adapter1::class,
613          'type' => \TType::STRING,
614        ),
615        'format' => 'collection',
616      ),
617      'format' => 'collection',
618    ),
619    8 => shape(
620      'var' => 'binaryField',
621      'union' => true,
622      'adapter' => \Adapter1::class,
623      'type' => \TType::STRING,
624    ),
625  ];
626  const dict<string, int> FIELDMAP = dict[
627    'intField' => 1,
628    'setField' => 4,
629    'mapField' => 6,
630    'binaryField' => 8,
631  ];
632
633  const type TConstructorShape = shape(
634    ?'intField' => ?\Adapter1::THackType,
635    ?'setField' => ?\Adapter2::THackType,
636    ?'mapField' => ?\Adapter3::THackType,
637    ?'binaryField' => ?\Adapter1::THackType,
638  );
639
640  const type TShape = shape(
641    ?'intField' => ?\Adapter1::THackType,
642    ?'setField' => ?\Adapter2::THackType,
643    ?'mapField' => ?\Adapter3::THackType,
644    ?'binaryField' => ?\Adapter1::THackType,
645  );
646  const int STRUCTURAL_ID = 2036191889248458060;
647  /**
648   * Original thrift field:-
649   * 1: i32 intField
650   */
651  public ?\Adapter1::THackType $intField;
652  /**
653   * Original thrift field:-
654   * 4: set<string> setField
655   */
656  public ?\Adapter2::THackType $setField;
657  /**
658   * Original thrift field:-
659   * 6: map<string, list<string>> mapField
660   */
661  public ?\Adapter3::THackType $mapField;
662  /**
663   * Original thrift field:-
664   * 8: binary binaryField
665   */
666  public ?\Adapter1::THackType $binaryField;
667  protected BazEnum $_type = BazEnum::_EMPTY_;
668
669  public function __construct(?\Adapter1::THackType $intField = null, ?\Adapter2::THackType $setField = null, ?\Adapter3::THackType $mapField = null, ?\Adapter1::THackType $binaryField = null  )[] {
670    $this->_type = BazEnum::_EMPTY_;
671    if ($intField !== null) {
672      $this->intField = $intField;
673      $this->_type = BazEnum::intField;
674    }
675    if ($setField !== null) {
676      $this->setField = $setField;
677      $this->_type = BazEnum::setField;
678    }
679    if ($mapField !== null) {
680      $this->mapField = $mapField;
681      $this->_type = BazEnum::mapField;
682    }
683    if ($binaryField !== null) {
684      $this->binaryField = $binaryField;
685      $this->_type = BazEnum::binaryField;
686    }
687  }
688
689  public static function withDefaultValues()[]: this {
690    return new static();
691  }
692
693  public static function fromShape(self::TConstructorShape $shape)[]: this {
694    return new static(
695      Shapes::idx($shape, 'intField'),
696      Shapes::idx($shape, 'setField'),
697      Shapes::idx($shape, 'mapField'),
698      Shapes::idx($shape, 'binaryField'),
699    );
700  }
701
702  public function getName()[]: string {
703    return 'Baz';
704  }
705
706  public function getType()[]: BazEnum {
707    return $this->_type;
708  }
709
710  public function reset()[write_props]: void {
711    switch ($this->_type) {
712      case BazEnum::intField:
713        $this->intField = null;
714        break;
715      case BazEnum::setField:
716        $this->setField = null;
717        break;
718      case BazEnum::mapField:
719        $this->mapField = null;
720        break;
721      case BazEnum::binaryField:
722        $this->binaryField = null;
723        break;
724      case BazEnum::_EMPTY_:
725        break;
726    }
727    $this->_type = BazEnum::_EMPTY_;
728  }
729
730  public function set_intField(\Adapter1::THackType $intField)[write_props]: this {
731    $this->reset();
732    $this->_type = BazEnum::intField;
733    $this->intField = $intField;
734    return $this;
735  }
736
737  public function get_intField()[]: ?\Adapter1::THackType {
738    return $this->intField;
739  }
740
741  public function getx_intField()[]: \Adapter1::THackType {
742    invariant(
743      $this->_type === BazEnum::intField,
744      'get_intField called on an instance of Baz whose current type is %s',
745      (string)$this->_type,
746    );
747    return $this->intField as nonnull;
748  }
749
750  public function set_setField(\Adapter2::THackType $setField)[write_props]: this {
751    $this->reset();
752    $this->_type = BazEnum::setField;
753    $this->setField = $setField;
754    return $this;
755  }
756
757  public function get_setField()[]: ?\Adapter2::THackType {
758    return $this->setField;
759  }
760
761  public function getx_setField()[]: \Adapter2::THackType {
762    invariant(
763      $this->_type === BazEnum::setField,
764      'get_setField called on an instance of Baz whose current type is %s',
765      (string)$this->_type,
766    );
767    return $this->setField as nonnull;
768  }
769
770  public function set_mapField(\Adapter3::THackType $mapField)[write_props]: this {
771    $this->reset();
772    $this->_type = BazEnum::mapField;
773    $this->mapField = $mapField;
774    return $this;
775  }
776
777  public function get_mapField()[]: ?\Adapter3::THackType {
778    return $this->mapField;
779  }
780
781  public function getx_mapField()[]: \Adapter3::THackType {
782    invariant(
783      $this->_type === BazEnum::mapField,
784      'get_mapField called on an instance of Baz whose current type is %s',
785      (string)$this->_type,
786    );
787    return $this->mapField as nonnull;
788  }
789
790  public function set_binaryField(\Adapter1::THackType $binaryField)[write_props]: this {
791    $this->reset();
792    $this->_type = BazEnum::binaryField;
793    $this->binaryField = $binaryField;
794    return $this;
795  }
796
797  public function get_binaryField()[]: ?\Adapter1::THackType {
798    return $this->binaryField;
799  }
800
801  public function getx_binaryField()[]: \Adapter1::THackType {
802    invariant(
803      $this->_type === BazEnum::binaryField,
804      'get_binaryField called on an instance of Baz whose current type is %s',
805      (string)$this->_type,
806    );
807    return $this->binaryField as nonnull;
808  }
809
810  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
811    return tmeta_ThriftStruct::fromShape(
812      shape(
813        "name" => "module.Baz",
814        "fields" => vec[
815          tmeta_ThriftField::fromShape(
816            shape(
817              "id" => 1,
818              "type" => tmeta_ThriftType::fromShape(
819                shape(
820                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
821                )
822              ),
823              "name" => "intField",
824            )
825          ),
826          tmeta_ThriftField::fromShape(
827            shape(
828              "id" => 4,
829              "type" => tmeta_ThriftType::fromShape(
830                shape(
831                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
832                    shape(
833                      "name" => "module.SetWithAdapter",
834                      "underlyingType" => tmeta_ThriftType::fromShape(
835                        shape(
836                          "t_set" => tmeta_ThriftSetType::fromShape(
837                            shape(
838                              "valueType" => tmeta_ThriftType::fromShape(
839                                shape(
840                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
841                                )
842                              ),
843                            )
844                          ),
845                        )
846                      ),
847                    )
848                  ),
849                )
850              ),
851              "name" => "setField",
852            )
853          ),
854          tmeta_ThriftField::fromShape(
855            shape(
856              "id" => 6,
857              "type" => tmeta_ThriftType::fromShape(
858                shape(
859                  "t_map" => tmeta_ThriftMapType::fromShape(
860                    shape(
861                      "keyType" => tmeta_ThriftType::fromShape(
862                        shape(
863                          "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
864                        )
865                      ),
866                      "valueType" => tmeta_ThriftType::fromShape(
867                        shape(
868                          "t_typedef" => tmeta_ThriftTypedefType::fromShape(
869                            shape(
870                              "name" => "module.ListWithElemAdapter",
871                              "underlyingType" => tmeta_ThriftType::fromShape(
872                                shape(
873                                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
874                                    shape(
875                                      "name" => "module.ListWithElemAdapter",
876                                      "underlyingType" => tmeta_ThriftType::fromShape(
877                                        shape(
878                                          "t_list" => tmeta_ThriftListType::fromShape(
879                                            shape(
880                                              "valueType" => tmeta_ThriftType::fromShape(
881                                                shape(
882                                                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
883                                                )
884                                              ),
885                                            )
886                                          ),
887                                        )
888                                      ),
889                                    )
890                                  ),
891                                )
892                              ),
893                            )
894                          ),
895                        )
896                      ),
897                    )
898                  ),
899                )
900              ),
901              "name" => "mapField",
902            )
903          ),
904          tmeta_ThriftField::fromShape(
905            shape(
906              "id" => 8,
907              "type" => tmeta_ThriftType::fromShape(
908                shape(
909                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_BINARY_TYPE,
910                )
911              ),
912              "name" => "binaryField",
913            )
914          ),
915        ],
916        "is_union" => true,
917      )
918    );
919  }
920
921  public static function getAllStructuredAnnotations()[]: \TStructAnnotations {
922    return shape(
923      'struct' => dict[],
924      'fields' => dict[
925      ],
926    );
927  }
928
929  public static function __fromShape(self::TShape $shape)[]: this {
930    return new static(
931      Shapes::idx($shape, 'intField'),
932      Shapes::idx($shape, 'setField') === null ? null : (new Set(Keyset\keys($shape['setField']))),
933      Shapes::idx($shape, 'mapField') === null ? null : ((new Map($shape['mapField']))->map(
934        $val0 ==> (new Vector($val0)),
935      )),
936      Shapes::idx($shape, 'binaryField'),
937    );
938  }
939
940  public function __toShape()[]: self::TShape {
941    return shape(
942      'intField' => $this->intField,
943      'setField' => $this->setField
944        |> $$ === null ? null : ThriftUtil::toDArray(Dict\fill_keys($$->toValuesArray(), true), static::class),
945      'mapField' => $this->mapField?->map(
946        ($_val0) ==> vec($_val0),
947      )
948        |> $$ === null ? null : dict($$),
949      'binaryField' => $this->binaryField,
950    );
951  }
952  public function readFromJson(string $jsonText): void {
953    $this->_type = BazEnum::_EMPTY_;
954    $parsed = json_decode($jsonText, true);
955
956    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
957      throw new \TProtocolException("Cannot parse the given json string.");
958    }
959
960    if (idx($parsed, 'intField') !== null) {
961      $_tmp0 = (int)/* HH_FIXME[4110] */ $parsed['intField'];
962      if ($_tmp0 > 0x7fffffff) {
963        throw new \TProtocolException("number exceeds limit in field");
964      } else {
965        $this->intField = (int)$_tmp0;
966      }
967      $this->_type = BazEnum::intField;
968    }
969    if (idx($parsed, 'setField') !== null) {
970      $_json4 = /* HH_FIXME[4110] */ $parsed['setField'];
971      $_container5 = Set {};
972      foreach(/* HH_FIXME[4110] */ $_json4 as $_key2 => $_value3) {
973        $_elem6 = '';
974        $_elem6 = $_value3;
975        $_container5->add($_elem6);
976      }
977      $this->setField = $_container5;
978      $this->_type = BazEnum::setField;
979    }
980    if (idx($parsed, 'mapField') !== null) {
981      $_json10 = /* HH_FIXME[4110] */ $parsed['mapField'];
982      $_container11 = Map {};
983      foreach(/* HH_FIXME[4110] */ $_json10 as $_key8 => $_value9) {
984        $_value12 = Vector {};
985        $_json16 = $_value9;
986        $_container17 = Vector {};
987        foreach(/* HH_FIXME[4110] */ $_json16 as $_key14 => $_value15) {
988          $_elem18 = '';
989          $_elem18 = $_value15;
990          $_container17 []= $_elem18;
991        }
992        $_value12 = $_container17;
993        $_container11[$_key8] = $_value12;
994      }
995      $this->mapField = $_container11;
996      $this->_type = BazEnum::mapField;
997    }
998    if (idx($parsed, 'binaryField') !== null) {
999      $this->binaryField = /* HH_FIXME[4110] */ $parsed['binaryField'];
1000      $this->_type = BazEnum::binaryField;
1001    }
1002  }
1003
1004  private static function __hackAdapterTypeChecks()[]: void {
1005    \ThriftUtil::requireSameType<\Adapter1::TThriftType, int>();
1006    \ThriftUtil::requireSameType<\Adapter1::TThriftType, string>();
1007    \ThriftUtil::requireSameType<\Adapter2::TThriftType, Set<string>>();
1008    \ThriftUtil::requireSameType<\Adapter2::TThriftType, Vector<\Adapter1::THackType>>();
1009    \ThriftUtil::requireSameType<\Adapter3::TThriftType, Map<string, \Adapter2::THackType>>();
1010  }
1011
1012}
1013
1014/**
1015 * Original thrift struct:-
1016 * Bar
1017 */
1018class Bar implements \IThriftStruct, \IThriftShapishStruct {
1019  use \ThriftSerializationTrait;
1020
1021  const dict<int, this::TFieldSpec> SPEC = dict[
1022    1 => shape(
1023      'var' => 'structField',
1024      'adapter' => \Adapter1::class,
1025      'type' => \TType::STRUCT,
1026      'class' => Foo::class,
1027    ),
1028    2 => shape(
1029      'var' => 'optionalStructField',
1030      'adapter' => \Adapter1::class,
1031      'type' => \TType::STRUCT,
1032      'class' => Foo::class,
1033    ),
1034    3 => shape(
1035      'var' => 'structListField',
1036      'type' => \TType::LST,
1037      'etype' => \TType::STRUCT,
1038      'elem' => shape(
1039        'adapter' => \Adapter1::class,
1040        'type' => \TType::STRUCT,
1041        'class' => Foo::class,
1042      ),
1043      'format' => 'collection',
1044    ),
1045    4 => shape(
1046      'var' => 'optionalStructListField',
1047      'type' => \TType::LST,
1048      'etype' => \TType::STRUCT,
1049      'elem' => shape(
1050        'adapter' => \Adapter1::class,
1051        'type' => \TType::STRUCT,
1052        'class' => Foo::class,
1053      ),
1054      'format' => 'collection',
1055    ),
1056    5 => shape(
1057      'var' => 'unionField',
1058      'adapter' => \Adapter1::class,
1059      'type' => \TType::STRUCT,
1060      'class' => Baz::class,
1061    ),
1062    6 => shape(
1063      'var' => 'optionalUnionField',
1064      'adapter' => \Adapter1::class,
1065      'type' => \TType::STRUCT,
1066      'class' => Baz::class,
1067    ),
1068  ];
1069  const dict<string, int> FIELDMAP = dict[
1070    'structField' => 1,
1071    'optionalStructField' => 2,
1072    'structListField' => 3,
1073    'optionalStructListField' => 4,
1074    'unionField' => 5,
1075    'optionalUnionField' => 6,
1076  ];
1077
1078  const type TConstructorShape = shape(
1079    ?'structField' => ?\Adapter1::THackType,
1080    ?'optionalStructField' => ?\Adapter1::THackType,
1081    ?'structListField' => ?Vector<\Adapter1::THackType>,
1082    ?'optionalStructListField' => ?Vector<\Adapter1::THackType>,
1083    ?'unionField' => ?\Adapter1::THackType,
1084    ?'optionalUnionField' => ?\Adapter1::THackType,
1085  );
1086
1087  const type TShape = shape(
1088    ?'structField' => ?\Adapter1::THackType,
1089    ?'optionalStructField' => ?\Adapter1::THackType,
1090    'structListField' => vec<\Adapter1::THackType>,
1091    ?'optionalStructListField' => ?vec<\Adapter1::THackType>,
1092    ?'unionField' => ?\Adapter1::THackType,
1093    ?'optionalUnionField' => ?\Adapter1::THackType,
1094  );
1095  const int STRUCTURAL_ID = 7572690377543394081;
1096  /**
1097   * Original thrift field:-
1098   * 1: struct module.Foo structField
1099   */
1100  public ?\Adapter1::THackType $structField;
1101  /**
1102   * Original thrift field:-
1103   * 2: struct module.Foo optionalStructField
1104   */
1105  public ?\Adapter1::THackType $optionalStructField;
1106  /**
1107   * Original thrift field:-
1108   * 3: list<struct module.Foo> structListField
1109   */
1110  public Vector<\Adapter1::THackType> $structListField;
1111  /**
1112   * Original thrift field:-
1113   * 4: list<struct module.Foo> optionalStructListField
1114   */
1115  public ?Vector<\Adapter1::THackType> $optionalStructListField;
1116  /**
1117   * Original thrift field:-
1118   * 5: struct module.Baz unionField
1119   */
1120  public ?\Adapter1::THackType $unionField;
1121  /**
1122   * Original thrift field:-
1123   * 6: struct module.Baz optionalUnionField
1124   */
1125  public ?\Adapter1::THackType $optionalUnionField;
1126
1127  public function __construct(?\Adapter1::THackType $structField = null, ?\Adapter1::THackType $optionalStructField = null, ?Vector<\Adapter1::THackType> $structListField = null, ?Vector<\Adapter1::THackType> $optionalStructListField = null, ?\Adapter1::THackType $unionField = null, ?\Adapter1::THackType $optionalUnionField = null  )[] {
1128    $this->structField = $structField;
1129    $this->optionalStructField = $optionalStructField;
1130    $this->structListField = $structListField ?? Vector {};
1131    $this->optionalStructListField = $optionalStructListField;
1132    $this->unionField = $unionField;
1133    $this->optionalUnionField = $optionalUnionField;
1134  }
1135
1136  public static function withDefaultValues()[]: this {
1137    return new static();
1138  }
1139
1140  public static function fromShape(self::TConstructorShape $shape)[]: this {
1141    return new static(
1142      Shapes::idx($shape, 'structField'),
1143      Shapes::idx($shape, 'optionalStructField'),
1144      Shapes::idx($shape, 'structListField'),
1145      Shapes::idx($shape, 'optionalStructListField'),
1146      Shapes::idx($shape, 'unionField'),
1147      Shapes::idx($shape, 'optionalUnionField'),
1148    );
1149  }
1150
1151  public function getName()[]: string {
1152    return 'Bar';
1153  }
1154
1155  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
1156    return tmeta_ThriftStruct::fromShape(
1157      shape(
1158        "name" => "module.Bar",
1159        "fields" => vec[
1160          tmeta_ThriftField::fromShape(
1161            shape(
1162              "id" => 1,
1163              "type" => tmeta_ThriftType::fromShape(
1164                shape(
1165                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1166                    shape(
1167                      "name" => "module.Foo",
1168                      "underlyingType" => tmeta_ThriftType::fromShape(
1169                        shape(
1170                          "t_struct" => tmeta_ThriftStructType::fromShape(
1171                            shape(
1172                              "name" => "module.Foo",
1173                            )
1174                          ),
1175                        )
1176                      ),
1177                    )
1178                  ),
1179                )
1180              ),
1181              "name" => "structField",
1182            )
1183          ),
1184          tmeta_ThriftField::fromShape(
1185            shape(
1186              "id" => 2,
1187              "type" => tmeta_ThriftType::fromShape(
1188                shape(
1189                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1190                    shape(
1191                      "name" => "module.Foo",
1192                      "underlyingType" => tmeta_ThriftType::fromShape(
1193                        shape(
1194                          "t_struct" => tmeta_ThriftStructType::fromShape(
1195                            shape(
1196                              "name" => "module.Foo",
1197                            )
1198                          ),
1199                        )
1200                      ),
1201                    )
1202                  ),
1203                )
1204              ),
1205              "name" => "optionalStructField",
1206              "is_optional" => true,
1207            )
1208          ),
1209          tmeta_ThriftField::fromShape(
1210            shape(
1211              "id" => 3,
1212              "type" => tmeta_ThriftType::fromShape(
1213                shape(
1214                  "t_list" => tmeta_ThriftListType::fromShape(
1215                    shape(
1216                      "valueType" => tmeta_ThriftType::fromShape(
1217                        shape(
1218                          "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1219                            shape(
1220                              "name" => "module.Foo",
1221                              "underlyingType" => tmeta_ThriftType::fromShape(
1222                                shape(
1223                                  "t_struct" => tmeta_ThriftStructType::fromShape(
1224                                    shape(
1225                                      "name" => "module.Foo",
1226                                    )
1227                                  ),
1228                                )
1229                              ),
1230                            )
1231                          ),
1232                        )
1233                      ),
1234                    )
1235                  ),
1236                )
1237              ),
1238              "name" => "structListField",
1239            )
1240          ),
1241          tmeta_ThriftField::fromShape(
1242            shape(
1243              "id" => 4,
1244              "type" => tmeta_ThriftType::fromShape(
1245                shape(
1246                  "t_list" => tmeta_ThriftListType::fromShape(
1247                    shape(
1248                      "valueType" => tmeta_ThriftType::fromShape(
1249                        shape(
1250                          "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1251                            shape(
1252                              "name" => "module.Foo",
1253                              "underlyingType" => tmeta_ThriftType::fromShape(
1254                                shape(
1255                                  "t_struct" => tmeta_ThriftStructType::fromShape(
1256                                    shape(
1257                                      "name" => "module.Foo",
1258                                    )
1259                                  ),
1260                                )
1261                              ),
1262                            )
1263                          ),
1264                        )
1265                      ),
1266                    )
1267                  ),
1268                )
1269              ),
1270              "name" => "optionalStructListField",
1271              "is_optional" => true,
1272            )
1273          ),
1274          tmeta_ThriftField::fromShape(
1275            shape(
1276              "id" => 5,
1277              "type" => tmeta_ThriftType::fromShape(
1278                shape(
1279                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1280                    shape(
1281                      "name" => "module.Baz",
1282                      "underlyingType" => tmeta_ThriftType::fromShape(
1283                        shape(
1284                          "t_struct" => tmeta_ThriftStructType::fromShape(
1285                            shape(
1286                              "name" => "module.Baz",
1287                            )
1288                          ),
1289                        )
1290                      ),
1291                    )
1292                  ),
1293                )
1294              ),
1295              "name" => "unionField",
1296            )
1297          ),
1298          tmeta_ThriftField::fromShape(
1299            shape(
1300              "id" => 6,
1301              "type" => tmeta_ThriftType::fromShape(
1302                shape(
1303                  "t_typedef" => tmeta_ThriftTypedefType::fromShape(
1304                    shape(
1305                      "name" => "module.Baz",
1306                      "underlyingType" => tmeta_ThriftType::fromShape(
1307                        shape(
1308                          "t_struct" => tmeta_ThriftStructType::fromShape(
1309                            shape(
1310                              "name" => "module.Baz",
1311                            )
1312                          ),
1313                        )
1314                      ),
1315                    )
1316                  ),
1317                )
1318              ),
1319              "name" => "optionalUnionField",
1320              "is_optional" => true,
1321            )
1322          ),
1323        ],
1324        "is_union" => false,
1325      )
1326    );
1327  }
1328
1329  public static function getAllStructuredAnnotations()[]: \TStructAnnotations {
1330    return shape(
1331      'struct' => dict[],
1332      'fields' => dict[
1333      ],
1334    );
1335  }
1336
1337  public static function __fromShape(self::TShape $shape)[]: this {
1338    return new static(
1339      Shapes::idx($shape, 'structField') === null ? null : (Foo::__fromShape($shape['structField'])),
1340      Shapes::idx($shape, 'optionalStructField') === null ? null : (Foo::__fromShape($shape['optionalStructField'])),
1341      (new Vector($shape['structListField']))->map(
1342        $val0 ==> Foo::__fromShape($val0),
1343      ),
1344      Shapes::idx($shape, 'optionalStructListField') === null ? null : ((new Vector($shape['optionalStructListField']))->map(
1345        $val1 ==> Foo::__fromShape($val1),
1346      )),
1347      Shapes::idx($shape, 'unionField') === null ? null : (Baz::__fromShape($shape['unionField'])),
1348      Shapes::idx($shape, 'optionalUnionField') === null ? null : (Baz::__fromShape($shape['optionalUnionField'])),
1349    );
1350  }
1351
1352  public function __toShape()[]: self::TShape {
1353    return shape(
1354      'structField' => $this->structField?->__toShape(),
1355      'optionalStructField' => $this->optionalStructField?->__toShape(),
1356      'structListField' => $this->structListField->map(
1357        ($_val0) ==> $_val0->__toShape(),
1358      )
1359        |> vec($$),
1360      'optionalStructListField' => $this->optionalStructListField?->map(
1361        ($_val0) ==> $_val0->__toShape(),
1362      )
1363        |> $$ === null ? null : vec($$),
1364      'unionField' => $this->unionField?->__toShape(),
1365      'optionalUnionField' => $this->optionalUnionField?->__toShape(),
1366    );
1367  }
1368  public function readFromJson(string $jsonText): void {
1369    $parsed = json_decode($jsonText, true);
1370
1371    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
1372      throw new \TProtocolException("Cannot parse the given json string.");
1373    }
1374
1375    if (idx($parsed, 'structField') !== null) {
1376      $_tmp0 = json_encode(/* HH_FIXME[4110] */ $parsed['structField']);
1377      $_tmp1 = Foo::withDefaultValues();
1378      $_tmp1->readFromJson($_tmp0);
1379      $this->structField = $_tmp1;
1380    }
1381    if (idx($parsed, 'optionalStructField') !== null) {
1382      $_tmp2 = json_encode(/* HH_FIXME[4110] */ $parsed['optionalStructField']);
1383      $_tmp3 = Foo::withDefaultValues();
1384      $_tmp3->readFromJson($_tmp2);
1385      $this->optionalStructField = $_tmp3;
1386    }
1387    if (idx($parsed, 'structListField') !== null) {
1388      $_json7 = /* HH_FIXME[4110] */ $parsed['structListField'];
1389      $_container8 = Vector {};
1390      foreach(/* HH_FIXME[4110] */ $_json7 as $_key5 => $_value6) {
1391        $_elem9 = Foo::withDefaultValues();
1392        $_tmp10 = json_encode($_value6);
1393        $_tmp11 = Foo::withDefaultValues();
1394        $_tmp11->readFromJson($_tmp10);
1395        $_elem9 = $_tmp11;
1396        $_container8 []= $_elem9;
1397      }
1398      $this->structListField = $_container8;
1399    }
1400    if (idx($parsed, 'optionalStructListField') !== null) {
1401      $_json15 = /* HH_FIXME[4110] */ $parsed['optionalStructListField'];
1402      $_container16 = Vector {};
1403      foreach(/* HH_FIXME[4110] */ $_json15 as $_key13 => $_value14) {
1404        $_elem17 = Foo::withDefaultValues();
1405        $_tmp18 = json_encode($_value14);
1406        $_tmp19 = Foo::withDefaultValues();
1407        $_tmp19->readFromJson($_tmp18);
1408        $_elem17 = $_tmp19;
1409        $_container16 []= $_elem17;
1410      }
1411      $this->optionalStructListField = $_container16;
1412    }
1413    if (idx($parsed, 'unionField') !== null) {
1414      $_tmp20 = json_encode(/* HH_FIXME[4110] */ $parsed['unionField']);
1415      $_tmp21 = Baz::withDefaultValues();
1416      $_tmp21->readFromJson($_tmp20);
1417      $this->unionField = $_tmp21;
1418    }
1419    if (idx($parsed, 'optionalUnionField') !== null) {
1420      $_tmp22 = json_encode(/* HH_FIXME[4110] */ $parsed['optionalUnionField']);
1421      $_tmp23 = Baz::withDefaultValues();
1422      $_tmp23->readFromJson($_tmp22);
1423      $this->optionalUnionField = $_tmp23;
1424    }
1425  }
1426
1427  private static function __hackAdapterTypeChecks()[]: void {
1428    \ThriftUtil::requireSameType<\Adapter1::TThriftType, Baz>();
1429    \ThriftUtil::requireSameType<\Adapter1::TThriftType, Foo>();
1430  }
1431
1432}
1433
1434/**
1435 * Original thrift struct:-
1436 * StructWithFieldAdapter
1437 */
1438class StructWithFieldAdapter implements \IThriftStruct, \IThriftShapishStruct {
1439  use \ThriftSerializationTrait;
1440
1441  const dict<int, this::TFieldSpec> SPEC = dict[
1442    1 => shape(
1443      'var' => 'field',
1444      'type' => \TType::I32,
1445    ),
1446  ];
1447  const dict<string, int> FIELDMAP = dict[
1448    'field' => 1,
1449  ];
1450
1451  const type TConstructorShape = shape(
1452    ?'field' => ?int,
1453  );
1454
1455  const type TShape = shape(
1456    'field' => int,
1457  );
1458  const int STRUCTURAL_ID = 7035499037608086885;
1459  /**
1460   * Original thrift field:-
1461   * 1: i32 field
1462   */
1463  public int $field;
1464
1465  public function __construct(?int $field = null  )[] {
1466    $this->field = $field ?? 0;
1467  }
1468
1469  public static function withDefaultValues()[]: this {
1470    return new static();
1471  }
1472
1473  public static function fromShape(self::TConstructorShape $shape)[]: this {
1474    return new static(
1475      Shapes::idx($shape, 'field'),
1476    );
1477  }
1478
1479  public function getName()[]: string {
1480    return 'StructWithFieldAdapter';
1481  }
1482
1483  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
1484    return tmeta_ThriftStruct::fromShape(
1485      shape(
1486        "name" => "module.StructWithFieldAdapter",
1487        "fields" => vec[
1488          tmeta_ThriftField::fromShape(
1489            shape(
1490              "id" => 1,
1491              "type" => tmeta_ThriftType::fromShape(
1492                shape(
1493                  "t_primitive" => tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
1494                )
1495              ),
1496              "name" => "field",
1497            )
1498          ),
1499        ],
1500        "is_union" => false,
1501      )
1502    );
1503  }
1504
1505  public static function getAllStructuredAnnotations()[]: \TStructAnnotations {
1506    return shape(
1507      'struct' => dict[],
1508      'fields' => dict[
1509        'field' => shape(
1510          'field' => dict[
1511            'facebook_thrift_annotation_cpp_ExperimentalAdapter' => facebook_thrift_annotation_cpp_ExperimentalAdapter::fromShape(
1512              shape(
1513                "name" => "my::Adapter1",
1514              )
1515            ),
1516          ],
1517          'type' => dict[],
1518        ),
1519      ],
1520    );
1521  }
1522
1523  public static function __fromShape(self::TShape $shape)[]: this {
1524    return new static(
1525      $shape['field'],
1526    );
1527  }
1528
1529  public function __toShape()[]: self::TShape {
1530    return shape(
1531      'field' => $this->field,
1532    );
1533  }
1534  public function readFromJson(string $jsonText): void {
1535    $parsed = json_decode($jsonText, true);
1536
1537    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
1538      throw new \TProtocolException("Cannot parse the given json string.");
1539    }
1540
1541    if (idx($parsed, 'field') !== null) {
1542      $_tmp0 = (int)/* HH_FIXME[4110] */ $parsed['field'];
1543      if ($_tmp0 > 0x7fffffff) {
1544        throw new \TProtocolException("number exceeds limit in field");
1545      } else {
1546        $this->field = (int)$_tmp0;
1547      }
1548    }
1549  }
1550
1551}
1552
1553