// Code generated by smithy-go-codegen DO NOT EDIT.

package types

import (
	"github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/schemas"
	smithy "github.com/aws/smithy-go"
)

func serializeMyUnion(s smithy.ShapeSerializer, schema *smithy.Schema, v MyUnion) {
	switch vv := v.(type) {
	case *MyUnionMemberBlobValue:
		s.WriteUnion(schema, schemas.MyUnion_blobValue)
		s.WriteBlob(schemas.MyUnion_blobValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberBooleanValue:
		s.WriteUnion(schema, schemas.MyUnion_booleanValue)
		s.WriteBool(schemas.MyUnion_booleanValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberEnumValue:
		s.WriteUnion(schema, schemas.MyUnion_enumValue)
		s.WriteString(schemas.MyUnion_enumValue, string(vv.Value))
		s.CloseUnion()
	case *MyUnionMemberListValue:
		s.WriteUnion(schema, schemas.MyUnion_listValue)
		serializeStringList(s, schemas.MyUnion_listValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberMapValue:
		s.WriteUnion(schema, schemas.MyUnion_mapValue)
		serializeStringMap(s, schemas.MyUnion_mapValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberNumberValue:
		s.WriteUnion(schema, schemas.MyUnion_numberValue)
		s.WriteInt32(schemas.MyUnion_numberValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberStringValue:
		s.WriteUnion(schema, schemas.MyUnion_stringValue)
		s.WriteString(schemas.MyUnion_stringValue, vv.Value)
		s.CloseUnion()
	case *MyUnionMemberStructureValue:
		s.WriteUnion(schema, schemas.MyUnion_structureValue)
		s.WriteStruct(schemas.MyUnion_structureValue)
		vv.Value.SerializeMembers(s)
		s.CloseStruct()
		s.CloseUnion()
	case *MyUnionMemberTimestampValue:
		s.WriteUnion(schema, schemas.MyUnion_timestampValue)
		s.WriteTime(schemas.MyUnion_timestampValue, vv.Value)
		s.CloseUnion()
	}
}

func deserializeMyUnion(d smithy.ShapeDeserializer, s *smithy.Schema, v *MyUnion) error {
	return smithy.ReadUnion(d, s, func(ms *smithy.Schema) error {
		switch ms {
		case schemas.MyUnion_blobValue:
			vv := &MyUnionMemberBlobValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_booleanValue:
			vv := &MyUnionMemberBooleanValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_enumValue:
			vv := &MyUnionMemberEnumValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_listValue:
			vv := &MyUnionMemberListValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_mapValue:
			vv := &MyUnionMemberMapValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_numberValue:
			vv := &MyUnionMemberNumberValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_stringValue:
			vv := &MyUnionMemberStringValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_structureValue:
			vv := &MyUnionMemberStructureValue{}
			*v = vv
			return vv.Deserialize(d)
		case schemas.MyUnion_timestampValue:
			vv := &MyUnionMemberTimestampValue{}
			*v = vv
			return vv.Deserialize(d)
		}
		return nil
	})
}

func serializeListOfKitchenSinks(s smithy.ShapeSerializer, schema *smithy.Schema, v []KitchenSink) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteStruct(schema.ListMember())
		vv.SerializeMembers(s)
		s.CloseStruct()
	}
	s.CloseList()
}

func serializeListOfListOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v [][]string) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		serializeListOfStrings(s, schema.ListMember(), vv)
	}
	s.CloseList()
}

func serializeListOfMapsOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v []map[string]string) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		serializeMapOfStrings(s, schema.ListMember(), vv)
	}
	s.CloseList()
}

func serializeListOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v []string) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteString(schema.ListMember(), string(vv))
	}
	s.CloseList()
}

func serializeListOfStructs(s smithy.ShapeSerializer, schema *smithy.Schema, v []SimpleStruct) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteStruct(schema.ListMember())
		vv.SerializeMembers(s)
		s.CloseStruct()
	}
	s.CloseList()
}

func serializeFooEnumList(s smithy.ShapeSerializer, schema *smithy.Schema, v []FooEnum) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteString(schema.ListMember(), string(vv))
	}
	s.CloseList()
}

func serializeFooEnumSet(s smithy.ShapeSerializer, schema *smithy.Schema, v []FooEnum) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteString(schema.ListMember(), string(vv))
	}
	s.CloseList()
}

func serializeIntegerEnumList(s smithy.ShapeSerializer, schema *smithy.Schema, v []IntegerEnum) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteInt32(schema.ListMember(), int32(vv))
	}
	s.CloseList()
}

func serializeIntegerEnumSet(s smithy.ShapeSerializer, schema *smithy.Schema, v []IntegerEnum) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteInt32(schema.ListMember(), int32(vv))
	}
	s.CloseList()
}

func serializeSparseStringList(s smithy.ShapeSerializer, schema *smithy.Schema, v []*string) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		if vv != nil {
			s.WriteString(schema.ListMember(), *vv)
		} else {
			s.WriteNil(schema.ListMember())
		}
	}
	s.CloseList()
}

func serializeStringList(s smithy.ShapeSerializer, schema *smithy.Schema, v []string) {
	if v == nil {
		return
	}
	s.WriteList(schema)
	for _, vv := range v {
		s.WriteString(schema.ListMember(), string(vv))
	}
	s.CloseList()
}

func deserializeListOfKitchenSinks(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]KitchenSink) error {
	var vv KitchenSink
	return smithy.ReadList(d, s, func() error {
		vv = KitchenSink{}
		if err := vv.Deserialize(d); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeListOfListOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *[][]string) error {
	var vv []string
	return smithy.ReadList(d, s, func() error {
		vv = nil
		if err := deserializeListOfStrings(d, s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeListOfMapsOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]map[string]string) error {
	var vv map[string]string
	return smithy.ReadList(d, s, func() error {
		vv = nil
		if err := deserializeMapOfStrings(d, s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeListOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]string) error {
	var vv string
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadString(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeListOfStructs(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]SimpleStruct) error {
	var vv SimpleStruct
	return smithy.ReadList(d, s, func() error {
		vv = SimpleStruct{}
		if err := vv.Deserialize(d); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeFooEnumList(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]FooEnum) error {
	var vv string
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadString(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, FooEnum(vv))
		return nil
	})
}

func deserializeFooEnumSet(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]FooEnum) error {
	var vv string
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadString(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, FooEnum(vv))
		return nil
	})
}

func deserializeIntegerEnumList(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]IntegerEnum) error {
	var vv int32
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadInt32(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeIntegerEnumSet(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]IntegerEnum) error {
	var vv int32
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadInt32(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func deserializeSparseStringList(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]*string) error {
	var vv string
	return smithy.ReadList(d, s, func() error {
		if isNil, err := d.ReadNil(s.ListMember()); err != nil {
			return err
		} else if isNil {
			*v = append(*v, nil)
			return nil
		}

		if err := d.ReadString(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, &vv)
		return nil
	})
}

func deserializeStringList(d smithy.ShapeDeserializer, s *smithy.Schema, v *[]string) error {
	var vv string
	return smithy.ReadList(d, s, func() error {

		if err := d.ReadString(s.ListMember(), &vv); err != nil {
			return err
		}

		*v = append(*v, vv)
		return nil
	})
}

func serializeMapOfKitchenSinks(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]KitchenSink) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteStruct(schema.MapValue())
		vv.SerializeMembers(s)
		s.CloseStruct()
	}
	s.CloseMap()
}

func serializeMapOfListsOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string][]string) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		serializeListOfStrings(s, schema.MapValue(), vv)
	}
	s.CloseMap()
}

func serializeMapOfMapOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]map[string]string) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		serializeMapOfStrings(s, schema.MapValue(), vv)
	}
	s.CloseMap()
}

func serializeMapOfStrings(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]string) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteString(schema.MapValue(), string(vv))
	}
	s.CloseMap()
}

func serializeMapOfStructs(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]SimpleStruct) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteStruct(schema.MapValue())
		vv.SerializeMembers(s)
		s.CloseStruct()
	}
	s.CloseMap()
}

func serializeFooEnumMap(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]FooEnum) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteString(schema.MapValue(), string(vv))
	}
	s.CloseMap()
}

func serializeIntegerEnumMap(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]IntegerEnum) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteInt32(schema.MapValue(), int32(vv))
	}
	s.CloseMap()
}

func serializeSparseStringMap(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]*string) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		if vv != nil {
			s.WriteString(schema.MapValue(), *vv)
		} else {
			s.WriteNil(schema.MapValue())
		}
	}
	s.CloseMap()
}

func serializeStringMap(s smithy.ShapeSerializer, schema *smithy.Schema, v map[string]string) {
	if v == nil {
		return
	}
	s.WriteMap(schema)
	for k, vv := range v {
		s.WriteKey(schema.MapKey(), k)
		s.WriteString(schema.MapValue(), string(vv))
	}
	s.CloseMap()
}

func deserializeMapOfKitchenSinks(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]KitchenSink) error {
	*v = make(map[string]KitchenSink)
	var vv KitchenSink
	return smithy.ReadMap(d, s, func(k string) error {
		vv = KitchenSink{}
		if err := vv.Deserialize(d); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeMapOfListsOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string][]string) error {
	*v = make(map[string][]string)
	var vv []string
	return smithy.ReadMap(d, s, func(k string) error {
		vv = nil
		if err := deserializeListOfStrings(d, s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeMapOfMapOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]map[string]string) error {
	*v = make(map[string]map[string]string)
	var vv map[string]string
	return smithy.ReadMap(d, s, func(k string) error {
		vv = nil
		if err := deserializeMapOfStrings(d, s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeMapOfStrings(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]string) error {
	*v = make(map[string]string)
	var vv string
	return smithy.ReadMap(d, s, func(k string) error {

		if err := d.ReadString(s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeMapOfStructs(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]SimpleStruct) error {
	*v = make(map[string]SimpleStruct)
	var vv SimpleStruct
	return smithy.ReadMap(d, s, func(k string) error {
		vv = SimpleStruct{}
		if err := vv.Deserialize(d); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeFooEnumMap(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]FooEnum) error {
	*v = make(map[string]FooEnum)
	var vv string
	return smithy.ReadMap(d, s, func(k string) error {

		if err := d.ReadString(s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = FooEnum(vv)
		return nil
	})
}

func deserializeIntegerEnumMap(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]IntegerEnum) error {
	*v = make(map[string]IntegerEnum)
	var vv int32
	return smithy.ReadMap(d, s, func(k string) error {

		if err := d.ReadInt32(s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}

func deserializeSparseStringMap(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]*string) error {
	*v = make(map[string]*string)
	var vv string
	return smithy.ReadMap(d, s, func(k string) error {
		if isNil, err := d.ReadNil(s.MapValue()); err != nil {
			return err
		} else if isNil {
			(*v)[k] = nil
			return nil
		}

		if err := d.ReadString(s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = &vv
		return nil
	})
}

func deserializeStringMap(d smithy.ShapeDeserializer, s *smithy.Schema, v *map[string]string) error {
	*v = make(map[string]string)
	var vv string
	return smithy.ReadMap(d, s, func(k string) error {

		if err := d.ReadString(s.MapValue(), &vv); err != nil {
			return err
		}

		(*v)[k] = vv
		return nil
	})
}
