// Autogenerated by Thrift for thrift/compiler/test/fixtures/terse_write/src/terse_write.thrift
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//  @generated

package terse_write

import (
    "maps"
    "sync"

    thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
    metadata "github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

// (needed to ensure safety because of naive import list construction)
var _ = thrift.ZERO
var _ = maps.Copy[map[int]int, map[int]int]
var _ = metadata.GoUnusedProtection__

// Premade Thrift types
var (
    premadeThriftType_terse_write_MyEnum *metadata.ThriftType = nil
    premadeThriftType_terse_write_MyStruct *metadata.ThriftType = nil
    premadeThriftType_bool *metadata.ThriftType = nil
    premadeThriftType_byte *metadata.ThriftType = nil
    premadeThriftType_i16 *metadata.ThriftType = nil
    premadeThriftType_i32 *metadata.ThriftType = nil
    premadeThriftType_i64 *metadata.ThriftType = nil
    premadeThriftType_float *metadata.ThriftType = nil
    premadeThriftType_double *metadata.ThriftType = nil
    premadeThriftType_string *metadata.ThriftType = nil
    premadeThriftType_binary *metadata.ThriftType = nil
    premadeThriftType_list_i16 *metadata.ThriftType = nil
    premadeThriftType_set_i16 *metadata.ThriftType = nil
    premadeThriftType_map_i16_i16 *metadata.ThriftType = nil
    premadeThriftType_terse_write_MyUnion *metadata.ThriftType = nil
    premadeThriftType_terse_write_MyStructWithCustomDefault *metadata.ThriftType = nil
    premadeThriftType_terse_write_StructLevelTerseStruct *metadata.ThriftType = nil
    premadeThriftType_terse_write_FieldLevelTerseStruct *metadata.ThriftType = nil
    premadeThriftType_terse_write_TerseStructWithCustomDefault *metadata.ThriftType = nil
    premadeThriftType_terse_write_MyInteger *metadata.ThriftType = nil
    premadeThriftType_terse_write_AdaptedFields *metadata.ThriftType = nil
    premadeThriftType_terse_write_WrappedFields *metadata.ThriftType = nil
    premadeThriftType_terse_write_TerseException *metadata.ThriftType = nil
)

// Premade Thrift type initializer
var premadeThriftTypesInitOnce = sync.OnceFunc(func() {
    premadeThriftType_terse_write_MyEnum = metadata.NewThriftType().SetTEnum(
        metadata.NewThriftEnumType().
            SetName("terse_write.MyEnum"),
    )
    premadeThriftType_terse_write_MyStruct = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.MyStruct"),
    )
    premadeThriftType_bool = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_BOOL_TYPE.Ptr(),
    )
    premadeThriftType_byte = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_BYTE_TYPE.Ptr(),
    )
    premadeThriftType_i16 = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_I16_TYPE.Ptr(),
    )
    premadeThriftType_i32 = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_I32_TYPE.Ptr(),
    )
    premadeThriftType_i64 = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_I64_TYPE.Ptr(),
    )
    premadeThriftType_float = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_FLOAT_TYPE.Ptr(),
    )
    premadeThriftType_double = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_DOUBLE_TYPE.Ptr(),
    )
    premadeThriftType_string = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_STRING_TYPE.Ptr(),
    )
    premadeThriftType_binary = metadata.NewThriftType().SetTPrimitive(
        metadata.ThriftPrimitiveType_THRIFT_BINARY_TYPE.Ptr(),
    )
    premadeThriftType_list_i16 = metadata.NewThriftType().SetTList(
        metadata.NewThriftListType().
            SetValueType(premadeThriftType_i16),
    )
    premadeThriftType_set_i16 = metadata.NewThriftType().SetTSet(
        metadata.NewThriftSetType().
            SetValueType(premadeThriftType_i16),
    )
    premadeThriftType_map_i16_i16 = metadata.NewThriftType().SetTMap(
        metadata.NewThriftMapType().
            SetKeyType(premadeThriftType_i16).
            SetValueType(premadeThriftType_i16),
    )
    premadeThriftType_terse_write_MyUnion = metadata.NewThriftType().SetTUnion(
        metadata.NewThriftUnionType().
            SetName("terse_write.MyUnion"),
    )
    premadeThriftType_terse_write_MyStructWithCustomDefault = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.MyStructWithCustomDefault"),
    )
    premadeThriftType_terse_write_StructLevelTerseStruct = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.StructLevelTerseStruct"),
    )
    premadeThriftType_terse_write_FieldLevelTerseStruct = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.FieldLevelTerseStruct"),
    )
    premadeThriftType_terse_write_TerseStructWithCustomDefault = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.TerseStructWithCustomDefault"),
    )
    premadeThriftType_terse_write_MyInteger = metadata.NewThriftType().SetTTypedef(
        metadata.NewThriftTypedefType().
            SetName("terse_write.MyInteger").
            SetUnderlyingType(premadeThriftType_i32),
    )
    premadeThriftType_terse_write_AdaptedFields = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.AdaptedFields"),
    )
    premadeThriftType_terse_write_WrappedFields = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.WrappedFields"),
    )
    premadeThriftType_terse_write_TerseException = metadata.NewThriftType().SetTStruct(
        metadata.NewThriftStructType().
            SetName("terse_write.TerseException"),
    )
})

// Helper type to allow us to store Thrift types in a slice at compile time,
// and put them in a map at runtime. See comment at the top of template
// about a compilation limitation that affects map literals.
type thriftTypeWithFullName struct {
    fullName   string
    thriftType *metadata.ThriftType
}

var premadeThriftTypesMapOnce = sync.OnceValue(
    func() map[string]*metadata.ThriftType {
        // Relies on premade Thrift types initialization
        premadeThriftTypesInitOnce()

        thriftTypesWithFullName := make([]thriftTypeWithFullName, 0)
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.MyEnum", premadeThriftType_terse_write_MyEnum })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.MyStruct", premadeThriftType_terse_write_MyStruct })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "bool", premadeThriftType_bool })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "byte", premadeThriftType_byte })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "i16", premadeThriftType_i16 })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "i32", premadeThriftType_i32 })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "i64", premadeThriftType_i64 })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "float", premadeThriftType_float })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "double", premadeThriftType_double })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "string", premadeThriftType_string })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "binary", premadeThriftType_binary })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.MyUnion", premadeThriftType_terse_write_MyUnion })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.MyStructWithCustomDefault", premadeThriftType_terse_write_MyStructWithCustomDefault })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.StructLevelTerseStruct", premadeThriftType_terse_write_StructLevelTerseStruct })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.FieldLevelTerseStruct", premadeThriftType_terse_write_FieldLevelTerseStruct })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.TerseStructWithCustomDefault", premadeThriftType_terse_write_TerseStructWithCustomDefault })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.MyInteger", premadeThriftType_terse_write_MyInteger })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.AdaptedFields", premadeThriftType_terse_write_AdaptedFields })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.WrappedFields", premadeThriftType_terse_write_WrappedFields })
        thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "terse_write.TerseException", premadeThriftType_terse_write_TerseException })

        fbthriftThriftTypesMap := make(map[string]*metadata.ThriftType, len(thriftTypesWithFullName))
        for _, value := range thriftTypesWithFullName {
            fbthriftThriftTypesMap[value.fullName] = value.thriftType
        }
        return fbthriftThriftTypesMap
    },
)

var structMetadatasOnce = sync.OnceValue(
    func() []*metadata.ThriftStruct {
        // Relies on premade Thrift types initialization
        premadeThriftTypesInitOnce()
        fbthriftThriftStructs := make([]*metadata.ThriftStruct, 0)
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.MyStruct").
    SetIsUnion(false))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.MyUnion").
    SetIsUnion(true).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("bool_field").
    SetIsOptional(false).
    SetType(premadeThriftType_bool),
            metadata.NewThriftField().
    SetId(2).
    SetName("byte_field").
    SetIsOptional(false).
    SetType(premadeThriftType_byte),
            metadata.NewThriftField().
    SetId(3).
    SetName("short_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i16),
            metadata.NewThriftField().
    SetId(4).
    SetName("int_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(5).
    SetName("long_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
            metadata.NewThriftField().
    SetId(6).
    SetName("float_field").
    SetIsOptional(false).
    SetType(premadeThriftType_float),
            metadata.NewThriftField().
    SetId(7).
    SetName("double_field").
    SetIsOptional(false).
    SetType(premadeThriftType_double),
            metadata.NewThriftField().
    SetId(8).
    SetName("string_field").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
            metadata.NewThriftField().
    SetId(9).
    SetName("binary_field").
    SetIsOptional(false).
    SetType(premadeThriftType_binary),
            metadata.NewThriftField().
    SetId(10).
    SetName("enum_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyEnum),
            metadata.NewThriftField().
    SetId(11).
    SetName("list_field").
    SetIsOptional(false).
    SetType(premadeThriftType_list_i16),
            metadata.NewThriftField().
    SetId(12).
    SetName("set_field").
    SetIsOptional(false).
    SetType(premadeThriftType_set_i16),
            metadata.NewThriftField().
    SetId(13).
    SetName("map_field").
    SetIsOptional(false).
    SetType(premadeThriftType_map_i16_i16),
            metadata.NewThriftField().
    SetId(14).
    SetName("struct_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyStruct),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.MyStructWithCustomDefault").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("field1").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.StructLevelTerseStruct").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("bool_field").
    SetIsOptional(false).
    SetType(premadeThriftType_bool),
            metadata.NewThriftField().
    SetId(2).
    SetName("byte_field").
    SetIsOptional(false).
    SetType(premadeThriftType_byte),
            metadata.NewThriftField().
    SetId(3).
    SetName("short_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i16),
            metadata.NewThriftField().
    SetId(4).
    SetName("int_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(5).
    SetName("long_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
            metadata.NewThriftField().
    SetId(6).
    SetName("float_field").
    SetIsOptional(false).
    SetType(premadeThriftType_float),
            metadata.NewThriftField().
    SetId(7).
    SetName("double_field").
    SetIsOptional(false).
    SetType(premadeThriftType_double),
            metadata.NewThriftField().
    SetId(8).
    SetName("string_field").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
            metadata.NewThriftField().
    SetId(9).
    SetName("binary_field").
    SetIsOptional(false).
    SetType(premadeThriftType_binary),
            metadata.NewThriftField().
    SetId(10).
    SetName("enum_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyEnum),
            metadata.NewThriftField().
    SetId(11).
    SetName("list_field").
    SetIsOptional(false).
    SetType(premadeThriftType_list_i16),
            metadata.NewThriftField().
    SetId(12).
    SetName("set_field").
    SetIsOptional(false).
    SetType(premadeThriftType_set_i16),
            metadata.NewThriftField().
    SetId(13).
    SetName("map_field").
    SetIsOptional(false).
    SetType(premadeThriftType_map_i16_i16),
            metadata.NewThriftField().
    SetId(14).
    SetName("struct_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyStruct),
            metadata.NewThriftField().
    SetId(15).
    SetName("union_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyUnion),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.FieldLevelTerseStruct").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("terse_bool_field").
    SetIsOptional(false).
    SetType(premadeThriftType_bool),
            metadata.NewThriftField().
    SetId(2).
    SetName("terse_byte_field").
    SetIsOptional(false).
    SetType(premadeThriftType_byte),
            metadata.NewThriftField().
    SetId(3).
    SetName("terse_short_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i16),
            metadata.NewThriftField().
    SetId(4).
    SetName("terse_int_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(5).
    SetName("terse_long_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
            metadata.NewThriftField().
    SetId(6).
    SetName("terse_float_field").
    SetIsOptional(false).
    SetType(premadeThriftType_float),
            metadata.NewThriftField().
    SetId(7).
    SetName("terse_double_field").
    SetIsOptional(false).
    SetType(premadeThriftType_double),
            metadata.NewThriftField().
    SetId(8).
    SetName("terse_string_field").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
            metadata.NewThriftField().
    SetId(9).
    SetName("terse_binary_field").
    SetIsOptional(false).
    SetType(premadeThriftType_binary),
            metadata.NewThriftField().
    SetId(10).
    SetName("terse_enum_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyEnum),
            metadata.NewThriftField().
    SetId(11).
    SetName("terse_list_field").
    SetIsOptional(false).
    SetType(premadeThriftType_list_i16),
            metadata.NewThriftField().
    SetId(12).
    SetName("terse_set_field").
    SetIsOptional(false).
    SetType(premadeThriftType_set_i16),
            metadata.NewThriftField().
    SetId(13).
    SetName("terse_map_field").
    SetIsOptional(false).
    SetType(premadeThriftType_map_i16_i16),
            metadata.NewThriftField().
    SetId(14).
    SetName("terse_struct_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyStruct),
            metadata.NewThriftField().
    SetId(15).
    SetName("bool_field").
    SetIsOptional(false).
    SetType(premadeThriftType_bool),
            metadata.NewThriftField().
    SetId(16).
    SetName("byte_field").
    SetIsOptional(false).
    SetType(premadeThriftType_byte),
            metadata.NewThriftField().
    SetId(17).
    SetName("short_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i16),
            metadata.NewThriftField().
    SetId(18).
    SetName("int_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(19).
    SetName("long_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
            metadata.NewThriftField().
    SetId(20).
    SetName("float_field").
    SetIsOptional(false).
    SetType(premadeThriftType_float),
            metadata.NewThriftField().
    SetId(21).
    SetName("double_field").
    SetIsOptional(false).
    SetType(premadeThriftType_double),
            metadata.NewThriftField().
    SetId(22).
    SetName("string_field").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
            metadata.NewThriftField().
    SetId(23).
    SetName("binary_field").
    SetIsOptional(false).
    SetType(premadeThriftType_binary),
            metadata.NewThriftField().
    SetId(24).
    SetName("enum_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyEnum),
            metadata.NewThriftField().
    SetId(25).
    SetName("list_field").
    SetIsOptional(false).
    SetType(premadeThriftType_list_i16),
            metadata.NewThriftField().
    SetId(26).
    SetName("set_field").
    SetIsOptional(false).
    SetType(premadeThriftType_set_i16),
            metadata.NewThriftField().
    SetId(27).
    SetName("map_field").
    SetIsOptional(false).
    SetType(premadeThriftType_map_i16_i16),
            metadata.NewThriftField().
    SetId(28).
    SetName("struct_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyStruct),
            metadata.NewThriftField().
    SetId(29).
    SetName("terse_union_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyUnion),
            metadata.NewThriftField().
    SetId(30).
    SetName("union_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyUnion),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.TerseStructWithCustomDefault").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("bool_field").
    SetIsOptional(false).
    SetType(premadeThriftType_bool),
            metadata.NewThriftField().
    SetId(2).
    SetName("byte_field").
    SetIsOptional(false).
    SetType(premadeThriftType_byte),
            metadata.NewThriftField().
    SetId(3).
    SetName("short_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i16),
            metadata.NewThriftField().
    SetId(4).
    SetName("int_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(5).
    SetName("long_field").
    SetIsOptional(false).
    SetType(premadeThriftType_i64),
            metadata.NewThriftField().
    SetId(6).
    SetName("float_field").
    SetIsOptional(false).
    SetType(premadeThriftType_float),
            metadata.NewThriftField().
    SetId(7).
    SetName("double_field").
    SetIsOptional(false).
    SetType(premadeThriftType_double),
            metadata.NewThriftField().
    SetId(8).
    SetName("string_field").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
            metadata.NewThriftField().
    SetId(9).
    SetName("binary_field").
    SetIsOptional(false).
    SetType(premadeThriftType_binary),
            metadata.NewThriftField().
    SetId(10).
    SetName("enum_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyEnum),
            metadata.NewThriftField().
    SetId(11).
    SetName("list_field").
    SetIsOptional(false).
    SetType(premadeThriftType_list_i16),
            metadata.NewThriftField().
    SetId(12).
    SetName("set_field").
    SetIsOptional(false).
    SetType(premadeThriftType_set_i16),
            metadata.NewThriftField().
    SetId(13).
    SetName("map_field").
    SetIsOptional(false).
    SetType(premadeThriftType_map_i16_i16),
            metadata.NewThriftField().
    SetId(14).
    SetName("struct_field").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyStructWithCustomDefault),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.AdaptedFields").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("field1").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyInteger),
            metadata.NewThriftField().
    SetId(2).
    SetName("field2").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
            metadata.NewThriftField().
    SetId(3).
    SetName("field3").
    SetIsOptional(false).
    SetType(premadeThriftType_terse_write_MyInteger),
        },
    ))
        fbthriftThriftStructs = append(fbthriftThriftStructs, metadata.NewThriftStruct().
    SetName("terse_write.WrappedFields").
    SetIsUnion(false).
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("field1").
    SetIsOptional(false).
    SetType(premadeThriftType_i32),
        },
    ))
        return fbthriftThriftStructs
    },
)

var exceptionMetadatasOnce = sync.OnceValue(
    func() []*metadata.ThriftException {
        // Relies on premade Thrift types initialization
        premadeThriftTypesInitOnce()
        return []*metadata.ThriftException{
            metadata.NewThriftException().
    SetName("terse_write.TerseException").
    SetFields(
        []*metadata.ThriftField{
            metadata.NewThriftField().
    SetId(1).
    SetName("msg").
    SetIsOptional(false).
    SetType(premadeThriftType_string),
        },
    ),
        }
    },
)

var enumMetadatasOnce = sync.OnceValue(
    func() []*metadata.ThriftEnum {
        // Relies on premade Thrift types initialization
        premadeThriftTypesInitOnce()
        return []*metadata.ThriftEnum{
            metadata.NewThriftEnum().
    SetName("terse_write.MyEnum").
    SetElements(
        map[int32]string{
            0: "ME0",
            1: "ME1",
        },
    ),
        }
    },
)

var serviceMetadatasOnce = sync.OnceValue(
    func() []*metadata.ThriftService {
        // Relies on premade Thrift types initialization
        premadeThriftTypesInitOnce()
        return []*metadata.ThriftService{
        }
    },
)

// GetMetadataThriftType (INTERNAL USE ONLY).
// Returns metadata ThriftType for a given full type name.
func GetMetadataThriftType(fullName string) *metadata.ThriftType {
    return premadeThriftTypesMapOnce()[fullName]
}

// GetThriftMetadata returns complete Thrift metadata for current and imported packages.
func GetThriftMetadata() *metadata.ThriftMetadata {
    allEnumsMap := make(map[string]*metadata.ThriftEnum)
    allStructsMap := make(map[string]*metadata.ThriftStruct)
    allExceptionsMap := make(map[string]*metadata.ThriftException)
    allServicesMap := make(map[string]*metadata.ThriftService)

    // Add enum metadatas from the current program...
    for _, enumMetadata := range enumMetadatasOnce() {
        allEnumsMap[enumMetadata.GetName()] = enumMetadata
    }
    // Add struct metadatas from the current program...
    for _, structMetadata := range structMetadatasOnce() {
        allStructsMap[structMetadata.GetName()] = structMetadata
    }
    // Add exception metadatas from the current program...
    for _, exceptionMetadata := range exceptionMetadatasOnce() {
        allExceptionsMap[exceptionMetadata.GetName()] = exceptionMetadata
    }
    // Add service metadatas from the current program...
    for _, serviceMetadata := range serviceMetadatasOnce() {
        allServicesMap[serviceMetadata.GetName()] = serviceMetadata
    }

    // Obtain Thrift metadatas from recursively included programs...
    var recursiveThriftMetadatas []*metadata.ThriftMetadata

    // ...now merge metadatas from recursively included programs.
    for _, thriftMetadata := range recursiveThriftMetadatas {
        maps.Copy(allEnumsMap, thriftMetadata.GetEnums())
        maps.Copy(allStructsMap, thriftMetadata.GetStructs())
        maps.Copy(allExceptionsMap, thriftMetadata.GetExceptions())
        maps.Copy(allServicesMap, thriftMetadata.GetServices())
    }

    return metadata.NewThriftMetadata().
        SetEnums(allEnumsMap).
        SetStructs(allStructsMap).
        SetExceptions(allExceptionsMap).
        SetServices(allServicesMap)
}

// GetThriftMetadataForService returns Thrift metadata for the given service.
func GetThriftMetadataForService(scopedServiceName string) *metadata.ThriftMetadata {
    thriftMetadata := GetThriftMetadata()

    allServicesMap := thriftMetadata.GetServices()
    relevantServicesMap := make(map[string]*metadata.ThriftService)

    serviceMetadata := allServicesMap[scopedServiceName]
    // Visit and record all recursive parents of the target service.
    for serviceMetadata != nil {
        relevantServicesMap[serviceMetadata.GetName()] = serviceMetadata
        if serviceMetadata.IsSetParent() {
            serviceMetadata = allServicesMap[serviceMetadata.GetParent()]
        } else {
            serviceMetadata = nil
        }
    }

    thriftMetadata.SetServices(relevantServicesMap)

    return thriftMetadata
}
