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

package module1

import (
    "fmt"
    "reflect"

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

var _ = module0.GoUnusedProtection__
var _ = module2.GoUnusedProtection__
// (needed to ensure safety because of naive import list construction)
var _ = fmt.Printf
var _ = reflect.Ptr
var _ = thrift.ZERO


type Plate = string

func NewPlate() Plate {
    return ""
}

func WritePlate(item Plate, p thrift.Encoder) error {
    if err := p.WriteString(item); err != nil {
        return err
    }
    return nil
}

func ReadPlate(p thrift.Decoder) (Plate, error) {
    var decodeResult Plate
    decodeErr := func() error {
        result, err := p.ReadString()
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type State = string

func NewState() State {
    return ""
}

func WriteState(item State, p thrift.Encoder) error {
    if err := p.WriteString(item); err != nil {
        return err
    }
    return nil
}

func ReadState(p thrift.Decoder) (State, error) {
    var decodeResult State
    decodeErr := func() error {
        result, err := p.ReadString()
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type Year = int32

func NewYear() Year {
    return 0
}

func WriteYear(item Year, p thrift.Encoder) error {
    if err := p.WriteI32(item); err != nil {
        return err
    }
    return nil
}

func ReadYear(p thrift.Decoder) (Year, error) {
    var decodeResult Year
    decodeErr := func() error {
        result, err := p.ReadI32()
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type Drivers = []string

func NewDrivers() Drivers {
    return make([]string, 0)
}

func WriteDrivers(item Drivers, p thrift.Encoder) error {
    if err := p.WriteListBegin(thrift.STRING, len(item)); err != nil {
        return thrift.PrependError("error writing list begin: ", err)
    }
    for _, v := range item {
        {
            item := v
            if err := p.WriteString(item); err != nil {
                return err
            }
        }
    }
    if err := p.WriteListEnd(); err != nil {
        return thrift.PrependError("error writing list end: ", err)
    }
    return nil
}

func ReadDrivers(p thrift.Decoder) (Drivers, error) {
    var decodeResult Drivers
    decodeErr := func() error {
        _ /* elemType */, size, err := p.ReadListBegin()
        if err != nil {
            return thrift.PrependError("error reading list begin: ", err)
        }
        
        listResult := make([]string, 0, size)
        for i := 0; i < size; i++ {
            var elem string
            {
                result, err := p.ReadString()
                if err != nil {
                    return err
                }
                elem = result
            }
            listResult = append(listResult, elem)
        }
        
        if err := p.ReadListEnd(); err != nil {
            return thrift.PrependError("error reading list end: ", err)
        }
        result := listResult
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type Accessory = module0.Accessory

func NewAccessory() *Accessory {
    return module0.NewAccessory()
}

func WriteAccessory(item *Accessory, p thrift.Encoder) error {
    if err := item.Write(p); err != nil {
        return err
    }
    return nil
}

func ReadAccessory(p thrift.Decoder) (*Accessory, error) {
    var decodeResult *Accessory
    decodeErr := func() error {
        result := module0.NewAccessory()
        err := result.Read(p)
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type CarPartName = module0.PartName

func NewCarPartName() *CarPartName {
    return module0.NewPartName()
}

func WriteCarPartName(item *CarPartName, p thrift.Encoder) error {
    if err := item.Write(p); err != nil {
        return err
    }
    return nil
}

func ReadCarPartName(p thrift.Decoder) (*CarPartName, error) {
    var decodeResult *CarPartName
    decodeErr := func() error {
        result := module0.NewPartName()
        err := result.Read(p)
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type Enum = module2.Enum

const (
    Enum_A Enum = module2.Enum_A
    Enum_B Enum = module2.Enum_B
    Enum_C Enum = module2.Enum_C
)

// Enum value maps for Enum
var (
    EnumToName  = module2.EnumToName
    EnumToValue = module2.EnumToValue
)

// Deprecated: Use EnumToValue instead (e.g. `x, ok := EnumToValue["name"]`).
func EnumFromString(s string) (Enum, error) {
    return module2.EnumFromString(s)
}

func NewEnum() Enum {
    return 0
}

func WriteEnum(item Enum, p thrift.Encoder) error {
    if err := p.WriteI32(int32(item)); err != nil {
        return err
    }
    return nil
}

func ReadEnum(p thrift.Decoder) (Enum, error) {
    var decodeResult Enum
    decodeErr := func() error {
        enumResult, err := p.ReadI32()
        if err != nil {
            return err
        }
        result := module2.Enum(enumResult)
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}

type Car = Automobile

func NewCar() *Car {
    return NewAutomobile()
}

func WriteCar(item *Car, p thrift.Encoder) error {
    if err := item.Write(p); err != nil {
        return err
    }
    return nil
}

func ReadCar(p thrift.Decoder) (*Car, error) {
    var decodeResult *Car
    decodeErr := func() error {
        result := NewAutomobile()
        err := result.Read(p)
        if err != nil {
            return err
        }
        decodeResult = result
        return nil
    }()
    return decodeResult, decodeErr
}
type Automobile struct {
    Plate Plate `thrift:"plate,1" json:"plate" db:"plate"`
    PreviousPlate *Plate `thrift:"previous_plate,2,optional" json:"previous_plate,omitempty" db:"previous_plate"`
    FirstPlate *Plate `thrift:"first_plate,3,optional" json:"first_plate,omitempty" db:"first_plate"`
    Year Year `thrift:"year,4" json:"year" db:"year"`
    Drivers Drivers `thrift:"drivers,5" json:"drivers" db:"drivers"`
    Accessories []*Accessory `thrift:"Accessories,6" json:"Accessories" db:"Accessories"`
    PartNames map[int32]*CarPartName `thrift:"PartNames,7" json:"PartNames" db:"PartNames"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*Automobile)(nil)

func NewAutomobile() *Automobile {
    return (&Automobile{}).setDefaults()
}

func (x *Automobile) GetPlate() Plate {
    return x.Plate
}

func (x *Automobile) GetPreviousPlate() Plate {
    if !x.IsSetPreviousPlate() {
        return NewPlate()
    }
    return *x.PreviousPlate
}

func (x *Automobile) GetFirstPlate() Plate {
    if !x.IsSetFirstPlate() {
        return "0000"
    }
    return *x.FirstPlate
}

func (x *Automobile) GetYear() Year {
    return x.Year
}

func (x *Automobile) GetDrivers() Drivers {
    if !x.IsSetDrivers() {
        return NewDrivers()
    }
    return x.Drivers
}

func (x *Automobile) GetAccessories() []*Accessory {
    if !x.IsSetAccessories() {
        return make([]*Accessory, 0)
    }
    return x.Accessories
}

func (x *Automobile) GetPartNames() map[int32]*CarPartName {
    if !x.IsSetPartNames() {
        return make(map[int32]*CarPartName)
    }
    return x.PartNames
}

func (x *Automobile) SetPlateNonCompat(value Plate) *Automobile {
    x.Plate = value
    return x
}

func (x *Automobile) SetPlate(value Plate) *Automobile {
    x.Plate = value
    return x
}

func (x *Automobile) SetPreviousPlateNonCompat(value Plate) *Automobile {
    x.PreviousPlate = &value
    return x
}

func (x *Automobile) SetPreviousPlate(value *Plate) *Automobile {
    x.PreviousPlate = value
    return x
}

func (x *Automobile) SetFirstPlateNonCompat(value Plate) *Automobile {
    x.FirstPlate = &value
    return x
}

func (x *Automobile) SetFirstPlate(value Plate) *Automobile {
    x.FirstPlate = &value
    return x
}

func (x *Automobile) SetYearNonCompat(value Year) *Automobile {
    x.Year = value
    return x
}

func (x *Automobile) SetYear(value Year) *Automobile {
    x.Year = value
    return x
}

func (x *Automobile) SetDriversNonCompat(value Drivers) *Automobile {
    x.Drivers = value
    return x
}

func (x *Automobile) SetDrivers(value Drivers) *Automobile {
    x.Drivers = value
    return x
}

func (x *Automobile) SetAccessoriesNonCompat(value []*Accessory) *Automobile {
    x.Accessories = value
    return x
}

func (x *Automobile) SetAccessories(value []*Accessory) *Automobile {
    x.Accessories = value
    return x
}

func (x *Automobile) SetPartNamesNonCompat(value map[int32]*CarPartName) *Automobile {
    x.PartNames = value
    return x
}

func (x *Automobile) SetPartNames(value map[int32]*CarPartName) *Automobile {
    x.PartNames = value
    return x
}

func (x *Automobile) IsSetPreviousPlate() bool {
    return x != nil && x.PreviousPlate != nil
}

func (x *Automobile) IsSetFirstPlate() bool {
    return x != nil && x.FirstPlate != nil
}

func (x *Automobile) IsSetDrivers() bool {
    return x != nil && x.Drivers != nil
}

func (x *Automobile) IsSetAccessories() bool {
    return x != nil && x.Accessories != nil
}

func (x *Automobile) IsSetPartNames() bool {
    return x != nil && x.PartNames != nil
}

func (x *Automobile) writeField1(p thrift.Encoder) error {  // Plate
    if err := p.WriteFieldBegin("plate", thrift.STRING, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Plate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField2(p thrift.Encoder) error {  // PreviousPlate
    if !x.IsSetPreviousPlate() {
        return nil
    }

    if err := p.WriteFieldBegin("previous_plate", thrift.STRING, 2); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := *x.PreviousPlate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField3(p thrift.Encoder) error {  // FirstPlate
    if !x.IsSetFirstPlate() {
        return nil
    }

    if err := p.WriteFieldBegin("first_plate", thrift.STRING, 3); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := *x.FirstPlate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField4(p thrift.Encoder) error {  // Year
    if err := p.WriteFieldBegin("year", thrift.I32, 4); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Year
    err := WriteYear(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField5(p thrift.Encoder) error {  // Drivers
    if err := p.WriteFieldBegin("drivers", thrift.LIST, 5); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Drivers
    err := WriteDrivers(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField6(p thrift.Encoder) error {  // Accessories
    if err := p.WriteFieldBegin("Accessories", thrift.LIST, 6); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Accessories
    if err := p.WriteListBegin(thrift.STRUCT, len(item)); err != nil {
        return thrift.PrependError("error writing list begin: ", err)
    }
    for _, v := range item {
        {
            item := v
            err := WriteAccessory(item, p)
            if err != nil {
                return err
            }
        }
    }
    if err := p.WriteListEnd(); err != nil {
        return thrift.PrependError("error writing list end: ", err)
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) writeField7(p thrift.Encoder) error {  // PartNames
    if err := p.WriteFieldBegin("PartNames", thrift.MAP, 7); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.PartNames
    if err := p.WriteMapBegin(thrift.I32, thrift.STRUCT, len(item)); err != nil {
        return thrift.PrependError("error writing map begin: ", err)
    }
    for k, v := range item {
        {
            item := k
            if err := p.WriteI32(item); err != nil {
                return err
            }
        }
    
        {
            item := v
            err := WriteCarPartName(item, p)
            if err != nil {
                return err
            }
        }
    }
    if err := p.WriteMapEnd(); err != nil {
        return thrift.PrependError("error writing map end: ", err)
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Automobile) readField1(p thrift.Decoder) error {  // Plate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.Plate = result
    return nil
}

func (x *Automobile) readField2(p thrift.Decoder) error {  // PreviousPlate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.PreviousPlate = &result
    return nil
}

func (x *Automobile) readField3(p thrift.Decoder) error {  // FirstPlate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.FirstPlate = &result
    return nil
}

func (x *Automobile) readField4(p thrift.Decoder) error {  // Year
    result, err := ReadYear(p)
    if err != nil {
        return err
    }

    x.Year = result
    return nil
}

func (x *Automobile) readField5(p thrift.Decoder) error {  // Drivers
    result, err := ReadDrivers(p)
    if err != nil {
        return err
    }

    x.Drivers = result
    return nil
}

func (x *Automobile) readField6(p thrift.Decoder) error {  // Accessories
    _ /* elemType */, size, err := p.ReadListBegin()
    if err != nil {
        return thrift.PrependError("error reading list begin: ", err)
    }
    
    listResult := make([]*Accessory, 0, size)
    for i := 0; i < size; i++ {
        var elem *Accessory
        {
            result, err := ReadAccessory(p)
            if err != nil {
                return err
            }
            elem = result
        }
        listResult = append(listResult, elem)
    }
    
    if err := p.ReadListEnd(); err != nil {
        return thrift.PrependError("error reading list end: ", err)
    }
    result := listResult

    x.Accessories = result
    return nil
}

func (x *Automobile) readField7(p thrift.Decoder) error {  // PartNames
    _ /* keyType */, _ /* valueType */, size, err := p.ReadMapBegin()
    if err != nil {
        return thrift.PrependError("error reading map begin: ", err)
    }
    
    mapResult := make(map[int32]*CarPartName, size)
    for i := 0; i < size; i++ {
        var key int32
        {
            result, err := p.ReadI32()
            if err != nil {
                return err
            }
            key = result
        }
    
        var value *CarPartName
        {
            result, err := ReadCarPartName(p)
            if err != nil {
                return err
            }
            value = result
        }
    
        mapResult[key] = value
    }
    
    if err := p.ReadMapEnd(); err != nil {
        return thrift.PrependError("error reading map end: ", err)
    }
    result := mapResult

    x.PartNames = result
    return nil
}





func (x *Automobile) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("Automobile"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }
    if err := x.writeField2(p); err != nil {
        return err
    }
    if err := x.writeField3(p); err != nil {
        return err
    }
    if err := x.writeField4(p); err != nil {
        return err
    }
    if err := x.writeField5(p); err != nil {
        return err
    }
    if err := x.writeField6(p); err != nil {
        return err
    }
    if err := x.writeField7(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *Automobile) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRING)):  // plate
            fieldReadErr = x.readField1(p)
        case (id == 2 && wireType == thrift.Type(thrift.STRING)):  // previous_plate
            fieldReadErr = x.readField2(p)
        case (id == 3 && wireType == thrift.Type(thrift.STRING)):  // first_plate
            fieldReadErr = x.readField3(p)
        case (id == 4 && wireType == thrift.Type(thrift.I32)):  // year
            fieldReadErr = x.readField4(p)
        case (id == 5 && wireType == thrift.Type(thrift.LIST)):  // drivers
            fieldReadErr = x.readField5(p)
        case (id == 6 && wireType == thrift.Type(thrift.LIST)):  // Accessories
            fieldReadErr = x.readField6(p)
        case (id == 7 && wireType == thrift.Type(thrift.MAP)):  // PartNames
            fieldReadErr = x.readField7(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *Automobile) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *Automobile) setDefaults() *Automobile {
    return x.
        SetPlateNonCompat(NewPlate()).
        SetFirstPlateNonCompat("0000").
        SetYearNonCompat(NewYear()).
        SetDriversNonCompat(NewDrivers()).
        SetAccessoriesNonCompat(make([]*Accessory, 0)).
        SetPartNamesNonCompat(make(map[int32]*CarPartName))
}

type MapKey struct {
    Num int64 `thrift:"num,1" json:"num" db:"num"`
    Strval string `thrift:"strval,2" json:"strval" db:"strval"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*MapKey)(nil)

func NewMapKey() *MapKey {
    return (&MapKey{}).setDefaults()
}

func (x *MapKey) GetNum() int64 {
    return x.Num
}

func (x *MapKey) GetStrval() string {
    return x.Strval
}

func (x *MapKey) SetNumNonCompat(value int64) *MapKey {
    x.Num = value
    return x
}

func (x *MapKey) SetNum(value int64) *MapKey {
    x.Num = value
    return x
}

func (x *MapKey) SetStrvalNonCompat(value string) *MapKey {
    x.Strval = value
    return x
}

func (x *MapKey) SetStrval(value string) *MapKey {
    x.Strval = value
    return x
}

func (x *MapKey) writeField1(p thrift.Encoder) error {  // Num
    if err := p.WriteFieldBegin("num", thrift.I64, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Num
    if err := p.WriteI64(item); err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *MapKey) writeField2(p thrift.Encoder) error {  // Strval
    if err := p.WriteFieldBegin("strval", thrift.STRING, 2); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Strval
    if err := p.WriteString(item); err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *MapKey) readField1(p thrift.Decoder) error {  // Num
    result, err := p.ReadI64()
    if err != nil {
        return err
    }

    x.Num = result
    return nil
}

func (x *MapKey) readField2(p thrift.Decoder) error {  // Strval
    result, err := p.ReadString()
    if err != nil {
        return err
    }

    x.Strval = result
    return nil
}



func (x *MapKey) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("MapKey"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }
    if err := x.writeField2(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *MapKey) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.I64)):  // num
            fieldReadErr = x.readField1(p)
        case (id == 2 && wireType == thrift.Type(thrift.STRING)):  // strval
            fieldReadErr = x.readField2(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *MapKey) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *MapKey) setDefaults() *MapKey {
    return x.
        SetNumNonCompat(0).
        SetStrvalNonCompat("")
}

type MapContainer struct {
    Mapval map[MapKey]string `thrift:"mapval,1" json:"mapval" db:"mapval"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*MapContainer)(nil)

func NewMapContainer() *MapContainer {
    return (&MapContainer{}).setDefaults()
}

func (x *MapContainer) GetMapval() map[MapKey]string {
    if !x.IsSetMapval() {
        return make(map[MapKey]string)
    }
    return x.Mapval
}

func (x *MapContainer) SetMapvalNonCompat(value map[MapKey]string) *MapContainer {
    x.Mapval = value
    return x
}

func (x *MapContainer) SetMapval(value map[MapKey]string) *MapContainer {
    x.Mapval = value
    return x
}

func (x *MapContainer) IsSetMapval() bool {
    return x != nil && x.Mapval != nil
}

func (x *MapContainer) writeField1(p thrift.Encoder) error {  // Mapval
    if err := p.WriteFieldBegin("mapval", thrift.MAP, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Mapval
    if err := p.WriteMapBegin(thrift.STRUCT, thrift.STRING, len(item)); err != nil {
        return thrift.PrependError("error writing map begin: ", err)
    }
    for k, v := range item {
        {
            item := k
            if err := item.Write(p); err != nil {
                return err
            }
        }
    
        {
            item := v
            if err := p.WriteString(item); err != nil {
                return err
            }
        }
    }
    if err := p.WriteMapEnd(); err != nil {
        return thrift.PrependError("error writing map end: ", err)
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *MapContainer) readField1(p thrift.Decoder) error {  // Mapval
    _ /* keyType */, _ /* valueType */, size, err := p.ReadMapBegin()
    if err != nil {
        return thrift.PrependError("error reading map begin: ", err)
    }
    
    mapResult := make(map[MapKey]string, size)
    for i := 0; i < size; i++ {
        var key MapKey
        {
            result := NewMapKey()
            err := result.Read(p)
            if err != nil {
                return err
            }
            key = *result
        }
    
        var value string
        {
            result, err := p.ReadString()
            if err != nil {
                return err
            }
            value = result
        }
    
        mapResult[key] = value
    }
    
    if err := p.ReadMapEnd(); err != nil {
        return thrift.PrependError("error reading map end: ", err)
    }
    result := mapResult

    x.Mapval = result
    return nil
}



func (x *MapContainer) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("MapContainer"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *MapContainer) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.MAP)):  // mapval
            fieldReadErr = x.readField1(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *MapContainer) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *MapContainer) setDefaults() *MapContainer {
    return x.
        SetMapvalNonCompat(make(map[MapKey]string))
}

type Pair struct {
    Automobile *Automobile `thrift:"automobile,1" json:"automobile" db:"automobile"`
    Car *Car `thrift:"car,2" json:"car" db:"car"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*Pair)(nil)

func NewPair() *Pair {
    return (&Pair{}).setDefaults()
}

func (x *Pair) GetAutomobile() *Automobile {
    if !x.IsSetAutomobile() {
        return nil
    }
    return x.Automobile
}

func (x *Pair) GetCar() *Car {
    if !x.IsSetCar() {
        return nil
    }
    return x.Car
}

func (x *Pair) SetAutomobileNonCompat(value *Automobile) *Pair {
    x.Automobile = value
    return x
}

func (x *Pair) SetAutomobile(value *Automobile) *Pair {
    x.Automobile = value
    return x
}

func (x *Pair) SetCarNonCompat(value *Car) *Pair {
    x.Car = value
    return x
}

func (x *Pair) SetCar(value *Car) *Pair {
    x.Car = value
    return x
}

func (x *Pair) IsSetAutomobile() bool {
    return x != nil && x.Automobile != nil
}

func (x *Pair) IsSetCar() bool {
    return x != nil && x.Car != nil
}

func (x *Pair) writeField1(p thrift.Encoder) error {  // Automobile
    if !x.IsSetAutomobile() {
        return nil
    }

    if err := p.WriteFieldBegin("automobile", thrift.STRUCT, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Automobile
    if err := item.Write(p); err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Pair) writeField2(p thrift.Encoder) error {  // Car
    if !x.IsSetCar() {
        return nil
    }

    if err := p.WriteFieldBegin("car", thrift.STRUCT, 2); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Car
    err := WriteCar(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Pair) readField1(p thrift.Decoder) error {  // Automobile
    result := NewAutomobile()
    err := result.Read(p)
    if err != nil {
        return err
    }

    x.Automobile = result
    return nil
}

func (x *Pair) readField2(p thrift.Decoder) error {  // Car
    result, err := ReadCar(p)
    if err != nil {
        return err
    }

    x.Car = result
    return nil
}

// Deprecated: Use NewPair().GetAutomobile() instead.
func (x *Pair) DefaultGetAutomobile() *Automobile {
    if !x.IsSetAutomobile() {
        return NewAutomobile()
    }
    return x.Automobile
}

// Deprecated: Use NewPair().GetCar() instead.
func (x *Pair) DefaultGetCar() *Car {
    if !x.IsSetCar() {
        return NewCar()
    }
    return x.Car
}



func (x *Pair) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("Pair"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }
    if err := x.writeField2(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *Pair) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRUCT)):  // automobile
            fieldReadErr = x.readField1(p)
        case (id == 2 && wireType == thrift.Type(thrift.STRUCT)):  // car
            fieldReadErr = x.readField2(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *Pair) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *Pair) setDefaults() *Pair {
    return x.
        SetAutomobileNonCompat(NewAutomobile()).
        SetCarNonCompat(NewCar())
}

type Collection struct {
    Automobiles []*Automobile `thrift:"automobiles,1" json:"automobiles" db:"automobiles"`
    Cars []*Car `thrift:"cars,2" json:"cars" db:"cars"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*Collection)(nil)

func NewCollection() *Collection {
    return (&Collection{}).setDefaults()
}

func (x *Collection) GetAutomobiles() []*Automobile {
    if !x.IsSetAutomobiles() {
        return make([]*Automobile, 0)
    }
    return x.Automobiles
}

func (x *Collection) GetCars() []*Car {
    if !x.IsSetCars() {
        return make([]*Car, 0)
    }
    return x.Cars
}

func (x *Collection) SetAutomobilesNonCompat(value []*Automobile) *Collection {
    x.Automobiles = value
    return x
}

func (x *Collection) SetAutomobiles(value []*Automobile) *Collection {
    x.Automobiles = value
    return x
}

func (x *Collection) SetCarsNonCompat(value []*Car) *Collection {
    x.Cars = value
    return x
}

func (x *Collection) SetCars(value []*Car) *Collection {
    x.Cars = value
    return x
}

func (x *Collection) IsSetAutomobiles() bool {
    return x != nil && x.Automobiles != nil
}

func (x *Collection) IsSetCars() bool {
    return x != nil && x.Cars != nil
}

func (x *Collection) writeField1(p thrift.Encoder) error {  // Automobiles
    if err := p.WriteFieldBegin("automobiles", thrift.LIST, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Automobiles
    if err := p.WriteListBegin(thrift.STRUCT, len(item)); err != nil {
        return thrift.PrependError("error writing list begin: ", err)
    }
    for _, v := range item {
        {
            item := v
            if err := item.Write(p); err != nil {
                return err
            }
        }
    }
    if err := p.WriteListEnd(); err != nil {
        return thrift.PrependError("error writing list end: ", err)
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Collection) writeField2(p thrift.Encoder) error {  // Cars
    if err := p.WriteFieldBegin("cars", thrift.LIST, 2); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Cars
    if err := p.WriteListBegin(thrift.STRUCT, len(item)); err != nil {
        return thrift.PrependError("error writing list begin: ", err)
    }
    for _, v := range item {
        {
            item := v
            err := WriteCar(item, p)
            if err != nil {
                return err
            }
        }
    }
    if err := p.WriteListEnd(); err != nil {
        return thrift.PrependError("error writing list end: ", err)
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *Collection) readField1(p thrift.Decoder) error {  // Automobiles
    _ /* elemType */, size, err := p.ReadListBegin()
    if err != nil {
        return thrift.PrependError("error reading list begin: ", err)
    }
    
    listResult := make([]*Automobile, 0, size)
    for i := 0; i < size; i++ {
        var elem *Automobile
        {
            result := NewAutomobile()
            err := result.Read(p)
            if err != nil {
                return err
            }
            elem = result
        }
        listResult = append(listResult, elem)
    }
    
    if err := p.ReadListEnd(); err != nil {
        return thrift.PrependError("error reading list end: ", err)
    }
    result := listResult

    x.Automobiles = result
    return nil
}

func (x *Collection) readField2(p thrift.Decoder) error {  // Cars
    _ /* elemType */, size, err := p.ReadListBegin()
    if err != nil {
        return thrift.PrependError("error reading list begin: ", err)
    }
    
    listResult := make([]*Car, 0, size)
    for i := 0; i < size; i++ {
        var elem *Car
        {
            result, err := ReadCar(p)
            if err != nil {
                return err
            }
            elem = result
        }
        listResult = append(listResult, elem)
    }
    
    if err := p.ReadListEnd(); err != nil {
        return thrift.PrependError("error reading list end: ", err)
    }
    result := listResult

    x.Cars = result
    return nil
}



func (x *Collection) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("Collection"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }
    if err := x.writeField2(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *Collection) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.LIST)):  // automobiles
            fieldReadErr = x.readField1(p)
        case (id == 2 && wireType == thrift.Type(thrift.LIST)):  // cars
            fieldReadErr = x.readField2(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *Collection) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *Collection) setDefaults() *Collection {
    return x.
        SetAutomobilesNonCompat(make([]*Automobile, 0)).
        SetCarsNonCompat(make([]*Car, 0))
}


// Service req/resp structs (below)
type reqFinderByPlate struct {
    Plate Plate `thrift:"plate,1" json:"plate" db:"plate"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*reqFinderByPlate)(nil)

// Deprecated: FinderByPlateArgsDeprecated is deprecated, since it is supposed to be internal.
type FinderByPlateArgsDeprecated = reqFinderByPlate

func newReqFinderByPlate() *reqFinderByPlate {
    return (&reqFinderByPlate{}).setDefaults()
}

func (x *reqFinderByPlate) GetPlate() Plate {
    return x.Plate
}

func (x *reqFinderByPlate) SetPlateNonCompat(value Plate) *reqFinderByPlate {
    x.Plate = value
    return x
}

func (x *reqFinderByPlate) SetPlate(value Plate) *reqFinderByPlate {
    x.Plate = value
    return x
}

func (x *reqFinderByPlate) writeField1(p thrift.Encoder) error {  // Plate
    if err := p.WriteFieldBegin("plate", thrift.STRING, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Plate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *reqFinderByPlate) readField1(p thrift.Decoder) error {  // Plate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.Plate = result
    return nil
}



func (x *reqFinderByPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("reqFinderByPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *reqFinderByPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRING)):  // plate
            fieldReadErr = x.readField1(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *reqFinderByPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *reqFinderByPlate) setDefaults() *reqFinderByPlate {
    return x.
        SetPlateNonCompat(NewPlate())
}

type respFinderByPlate struct {
    Success *Automobile `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*respFinderByPlate)(nil)
var _ thrift.WritableResult = (*respFinderByPlate)(nil)

// Deprecated: FinderByPlateResultDeprecated is deprecated, since it is supposed to be internal.
type FinderByPlateResultDeprecated = respFinderByPlate

func newRespFinderByPlate() *respFinderByPlate {
    return (&respFinderByPlate{}).setDefaults()
}

func (x *respFinderByPlate) GetSuccess() *Automobile {
    if !x.IsSetSuccess() {
        return nil
    }
    return x.Success
}

func (x *respFinderByPlate) SetSuccessNonCompat(value *Automobile) *respFinderByPlate {
    x.Success = value
    return x
}

func (x *respFinderByPlate) SetSuccess(value *Automobile) *respFinderByPlate {
    x.Success = value
    return x
}

func (x *respFinderByPlate) IsSetSuccess() bool {
    return x != nil && x.Success != nil
}

func (x *respFinderByPlate) writeField0(p thrift.Encoder) error {  // Success
    if !x.IsSetSuccess() {
        return nil
    }

    if err := p.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Success
    if err := item.Write(p); err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *respFinderByPlate) readField0(p thrift.Decoder) error {  // Success
    result := NewAutomobile()
    err := result.Read(p)
    if err != nil {
        return err
    }

    x.Success = result
    return nil
}

// Deprecated: Use newRespFinderByPlate().GetSuccess() instead.
func (x *respFinderByPlate) DefaultGetSuccess() *Automobile {
    if !x.IsSetSuccess() {
        return NewAutomobile()
    }
    return x.Success
}



func (x *respFinderByPlate) Exception() thrift.WritableException {
    return nil
}

func (x *respFinderByPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("respFinderByPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField0(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *respFinderByPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 0 && wireType == thrift.Type(thrift.STRUCT)):  // success
            fieldReadErr = x.readField0(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *respFinderByPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *respFinderByPlate) setDefaults() *respFinderByPlate {
    return x
}

type reqFinderAliasByPlate struct {
    Plate Plate `thrift:"plate,1" json:"plate" db:"plate"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*reqFinderAliasByPlate)(nil)

// Deprecated: FinderAliasByPlateArgsDeprecated is deprecated, since it is supposed to be internal.
type FinderAliasByPlateArgsDeprecated = reqFinderAliasByPlate

func newReqFinderAliasByPlate() *reqFinderAliasByPlate {
    return (&reqFinderAliasByPlate{}).setDefaults()
}

func (x *reqFinderAliasByPlate) GetPlate() Plate {
    return x.Plate
}

func (x *reqFinderAliasByPlate) SetPlateNonCompat(value Plate) *reqFinderAliasByPlate {
    x.Plate = value
    return x
}

func (x *reqFinderAliasByPlate) SetPlate(value Plate) *reqFinderAliasByPlate {
    x.Plate = value
    return x
}

func (x *reqFinderAliasByPlate) writeField1(p thrift.Encoder) error {  // Plate
    if err := p.WriteFieldBegin("plate", thrift.STRING, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Plate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *reqFinderAliasByPlate) readField1(p thrift.Decoder) error {  // Plate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.Plate = result
    return nil
}



func (x *reqFinderAliasByPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("reqFinderAliasByPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *reqFinderAliasByPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRING)):  // plate
            fieldReadErr = x.readField1(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *reqFinderAliasByPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *reqFinderAliasByPlate) setDefaults() *reqFinderAliasByPlate {
    return x.
        SetPlateNonCompat(NewPlate())
}

type respFinderAliasByPlate struct {
    Success *Car `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*respFinderAliasByPlate)(nil)
var _ thrift.WritableResult = (*respFinderAliasByPlate)(nil)

// Deprecated: FinderAliasByPlateResultDeprecated is deprecated, since it is supposed to be internal.
type FinderAliasByPlateResultDeprecated = respFinderAliasByPlate

func newRespFinderAliasByPlate() *respFinderAliasByPlate {
    return (&respFinderAliasByPlate{}).setDefaults()
}

func (x *respFinderAliasByPlate) GetSuccess() *Car {
    if !x.IsSetSuccess() {
        return nil
    }
    return x.Success
}

func (x *respFinderAliasByPlate) SetSuccessNonCompat(value *Car) *respFinderAliasByPlate {
    x.Success = value
    return x
}

func (x *respFinderAliasByPlate) SetSuccess(value *Car) *respFinderAliasByPlate {
    x.Success = value
    return x
}

func (x *respFinderAliasByPlate) IsSetSuccess() bool {
    return x != nil && x.Success != nil
}

func (x *respFinderAliasByPlate) writeField0(p thrift.Encoder) error {  // Success
    if !x.IsSetSuccess() {
        return nil
    }

    if err := p.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Success
    err := WriteCar(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *respFinderAliasByPlate) readField0(p thrift.Decoder) error {  // Success
    result, err := ReadCar(p)
    if err != nil {
        return err
    }

    x.Success = result
    return nil
}

// Deprecated: Use newRespFinderAliasByPlate().GetSuccess() instead.
func (x *respFinderAliasByPlate) DefaultGetSuccess() *Car {
    if !x.IsSetSuccess() {
        return NewCar()
    }
    return x.Success
}



func (x *respFinderAliasByPlate) Exception() thrift.WritableException {
    return nil
}

func (x *respFinderAliasByPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("respFinderAliasByPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField0(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *respFinderAliasByPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 0 && wireType == thrift.Type(thrift.STRUCT)):  // success
            fieldReadErr = x.readField0(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *respFinderAliasByPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *respFinderAliasByPlate) setDefaults() *respFinderAliasByPlate {
    return x
}

type reqFinderPreviousPlate struct {
    Plate Plate `thrift:"plate,1" json:"plate" db:"plate"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*reqFinderPreviousPlate)(nil)

// Deprecated: FinderPreviousPlateArgsDeprecated is deprecated, since it is supposed to be internal.
type FinderPreviousPlateArgsDeprecated = reqFinderPreviousPlate

func newReqFinderPreviousPlate() *reqFinderPreviousPlate {
    return (&reqFinderPreviousPlate{}).setDefaults()
}

func (x *reqFinderPreviousPlate) GetPlate() Plate {
    return x.Plate
}

func (x *reqFinderPreviousPlate) SetPlateNonCompat(value Plate) *reqFinderPreviousPlate {
    x.Plate = value
    return x
}

func (x *reqFinderPreviousPlate) SetPlate(value Plate) *reqFinderPreviousPlate {
    x.Plate = value
    return x
}

func (x *reqFinderPreviousPlate) writeField1(p thrift.Encoder) error {  // Plate
    if err := p.WriteFieldBegin("plate", thrift.STRING, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Plate
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *reqFinderPreviousPlate) readField1(p thrift.Decoder) error {  // Plate
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.Plate = result
    return nil
}



func (x *reqFinderPreviousPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("reqFinderPreviousPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *reqFinderPreviousPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRING)):  // plate
            fieldReadErr = x.readField1(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *reqFinderPreviousPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *reqFinderPreviousPlate) setDefaults() *reqFinderPreviousPlate {
    return x.
        SetPlateNonCompat(NewPlate())
}

type respFinderPreviousPlate struct {
    Success *Plate `thrift:"success,0,optional" json:"success,omitempty" db:"success"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*respFinderPreviousPlate)(nil)
var _ thrift.WritableResult = (*respFinderPreviousPlate)(nil)

// Deprecated: FinderPreviousPlateResultDeprecated is deprecated, since it is supposed to be internal.
type FinderPreviousPlateResultDeprecated = respFinderPreviousPlate

func newRespFinderPreviousPlate() *respFinderPreviousPlate {
    return (&respFinderPreviousPlate{}).setDefaults()
}

func (x *respFinderPreviousPlate) GetSuccess() Plate {
    if !x.IsSetSuccess() {
        return NewPlate()
    }
    return *x.Success
}

func (x *respFinderPreviousPlate) SetSuccessNonCompat(value Plate) *respFinderPreviousPlate {
    x.Success = &value
    return x
}

func (x *respFinderPreviousPlate) SetSuccess(value *Plate) *respFinderPreviousPlate {
    x.Success = value
    return x
}

func (x *respFinderPreviousPlate) IsSetSuccess() bool {
    return x != nil && x.Success != nil
}

func (x *respFinderPreviousPlate) writeField0(p thrift.Encoder) error {  // Success
    if !x.IsSetSuccess() {
        return nil
    }

    if err := p.WriteFieldBegin("success", thrift.STRING, 0); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := *x.Success
    err := WritePlate(item, p)
    if err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *respFinderPreviousPlate) readField0(p thrift.Decoder) error {  // Success
    result, err := ReadPlate(p)
    if err != nil {
        return err
    }

    x.Success = &result
    return nil
}




func (x *respFinderPreviousPlate) Exception() thrift.WritableException {
    return nil
}

func (x *respFinderPreviousPlate) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("respFinderPreviousPlate"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField0(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *respFinderPreviousPlate) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 0 && wireType == thrift.Type(thrift.STRING)):  // success
            fieldReadErr = x.readField0(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *respFinderPreviousPlate) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *respFinderPreviousPlate) setDefaults() *respFinderPreviousPlate {
    return x
}


// RegisterTypes registers types found in this file that have a thrift_uri with the passed in registry.
func RegisterTypes(registry interface {
  RegisterType(name string, initializer func() any)
}) {

}
