// Autogenerated by Thrift Compiler (1.0.0-dev)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

package keyvalue

import (
	"bytes"
	"fmt"
	"github.com/apache/thrift/lib/go/thrift"
)

// (needed to ensure safety because of naive import list construction.)
var _ = thrift.ZERO
var _ = fmt.Printf
var _ = bytes.Equal

type KeyValue interface {
	BaseService

	// Parameters:
	//  - Key
	Get(key string) (r string, err error)
	// Parameters:
	//  - Key
	//  - Value
	Set(key string, value string) (err error)
}

type KeyValueClient struct {
	*BaseServiceClient
}

func NewKeyValueClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *KeyValueClient {
	return &KeyValueClient{BaseServiceClient: NewBaseServiceClientFactory(t, f)}
}

func NewKeyValueClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *KeyValueClient {
	return &KeyValueClient{BaseServiceClient: NewBaseServiceClientProtocol(t, iprot, oprot)}
}

// Parameters:
//  - Key
func (p *KeyValueClient) Get(key string) (r string, err error) {
	if err = p.sendGet(key); err != nil {
		return
	}
	return p.recvGet()
}

func (p *KeyValueClient) sendGet(key string) (err error) {
	oprot := p.OutputProtocol
	if oprot == nil {
		oprot = p.ProtocolFactory.GetProtocol(p.Transport)
		p.OutputProtocol = oprot
	}
	p.SeqId++
	if err = oprot.WriteMessageBegin("Get", thrift.CALL, p.SeqId); err != nil {
		return
	}
	args := KeyValueGetArgs{
		Key: key,
	}
	if err = args.Write(oprot); err != nil {
		return
	}
	if err = oprot.WriteMessageEnd(); err != nil {
		return
	}
	return oprot.Flush()
}

func (p *KeyValueClient) recvGet() (value string, err error) {
	iprot := p.InputProtocol
	if iprot == nil {
		iprot = p.ProtocolFactory.GetProtocol(p.Transport)
		p.InputProtocol = iprot
	}
	method, mTypeId, seqId, err := iprot.ReadMessageBegin()
	if err != nil {
		return
	}
	if method != "Get" {
		err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "Get failed: wrong method name")
		return
	}
	if p.SeqId != seqId {
		err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Get failed: out of sequence response")
		return
	}
	if mTypeId == thrift.EXCEPTION {
		error4 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception")
		var error5 error
		error5, err = error4.Read(iprot)
		if err != nil {
			return
		}
		if err = iprot.ReadMessageEnd(); err != nil {
			return
		}
		err = error5
		return
	}
	if mTypeId != thrift.REPLY {
		err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "Get failed: invalid message type")
		return
	}
	result := KeyValueGetResult{}
	if err = result.Read(iprot); err != nil {
		return
	}
	if err = iprot.ReadMessageEnd(); err != nil {
		return
	}
	if result.NotFound != nil {
		err = result.NotFound
		return
	} else if result.InvalidKey != nil {
		err = result.InvalidKey
		return
	}
	value = result.GetSuccess()
	return
}

// Parameters:
//  - Key
//  - Value
func (p *KeyValueClient) Set(key string, value string) (err error) {
	if err = p.sendSet(key, value); err != nil {
		return
	}
	return p.recvSet()
}

func (p *KeyValueClient) sendSet(key string, value string) (err error) {
	oprot := p.OutputProtocol
	if oprot == nil {
		oprot = p.ProtocolFactory.GetProtocol(p.Transport)
		p.OutputProtocol = oprot
	}
	p.SeqId++
	if err = oprot.WriteMessageBegin("Set", thrift.CALL, p.SeqId); err != nil {
		return
	}
	args := KeyValueSetArgs{
		Key:   key,
		Value: value,
	}
	if err = args.Write(oprot); err != nil {
		return
	}
	if err = oprot.WriteMessageEnd(); err != nil {
		return
	}
	return oprot.Flush()
}

func (p *KeyValueClient) recvSet() (err error) {
	iprot := p.InputProtocol
	if iprot == nil {
		iprot = p.ProtocolFactory.GetProtocol(p.Transport)
		p.InputProtocol = iprot
	}
	method, mTypeId, seqId, err := iprot.ReadMessageBegin()
	if err != nil {
		return
	}
	if method != "Set" {
		err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "Set failed: wrong method name")
		return
	}
	if p.SeqId != seqId {
		err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Set failed: out of sequence response")
		return
	}
	if mTypeId == thrift.EXCEPTION {
		error6 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception")
		var error7 error
		error7, err = error6.Read(iprot)
		if err != nil {
			return
		}
		if err = iprot.ReadMessageEnd(); err != nil {
			return
		}
		err = error7
		return
	}
	if mTypeId != thrift.REPLY {
		err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "Set failed: invalid message type")
		return
	}
	result := KeyValueSetResult{}
	if err = result.Read(iprot); err != nil {
		return
	}
	if err = iprot.ReadMessageEnd(); err != nil {
		return
	}
	if result.InvalidKey != nil {
		err = result.InvalidKey
		return
	}
	return
}

type KeyValueProcessor struct {
	*BaseServiceProcessor
}

func NewKeyValueProcessor(handler KeyValue) *KeyValueProcessor {
	self8 := &KeyValueProcessor{NewBaseServiceProcessor(handler)}
	self8.AddToProcessorMap("Get", &keyValueProcessorGet{handler: handler})
	self8.AddToProcessorMap("Set", &keyValueProcessorSet{handler: handler})
	return self8
}

type keyValueProcessorGet struct {
	handler KeyValue
}

func (p *keyValueProcessorGet) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
	args := KeyValueGetArgs{}
	if err = args.Read(iprot); err != nil {
		iprot.ReadMessageEnd()
		x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
		oprot.WriteMessageBegin("Get", thrift.EXCEPTION, seqId)
		x.Write(oprot)
		oprot.WriteMessageEnd()
		oprot.Flush()
		return false, err
	}

	iprot.ReadMessageEnd()
	result := KeyValueGetResult{}
	var retval string
	var err2 error
	if retval, err2 = p.handler.Get(args.Key); err2 != nil {
		switch v := err2.(type) {
		case *KeyNotFound:
			result.NotFound = v
		case *InvalidKey:
			result.InvalidKey = v
		default:
			x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Get: "+err2.Error())
			oprot.WriteMessageBegin("Get", thrift.EXCEPTION, seqId)
			x.Write(oprot)
			oprot.WriteMessageEnd()
			oprot.Flush()
			return true, err2
		}
	} else {
		result.Success = &retval
	}
	if err2 = oprot.WriteMessageBegin("Get", thrift.REPLY, seqId); err2 != nil {
		err = err2
	}
	if err2 = result.Write(oprot); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.Flush(); err == nil && err2 != nil {
		err = err2
	}
	if err != nil {
		return
	}
	return true, err
}

type keyValueProcessorSet struct {
	handler KeyValue
}

func (p *keyValueProcessorSet) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
	args := KeyValueSetArgs{}
	if err = args.Read(iprot); err != nil {
		iprot.ReadMessageEnd()
		x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
		oprot.WriteMessageBegin("Set", thrift.EXCEPTION, seqId)
		x.Write(oprot)
		oprot.WriteMessageEnd()
		oprot.Flush()
		return false, err
	}

	iprot.ReadMessageEnd()
	result := KeyValueSetResult{}
	var err2 error
	if err2 = p.handler.Set(args.Key, args.Value); err2 != nil {
		switch v := err2.(type) {
		case *InvalidKey:
			result.InvalidKey = v
		default:
			x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Set: "+err2.Error())
			oprot.WriteMessageBegin("Set", thrift.EXCEPTION, seqId)
			x.Write(oprot)
			oprot.WriteMessageEnd()
			oprot.Flush()
			return true, err2
		}
	}
	if err2 = oprot.WriteMessageBegin("Set", thrift.REPLY, seqId); err2 != nil {
		err = err2
	}
	if err2 = result.Write(oprot); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.Flush(); err == nil && err2 != nil {
		err = err2
	}
	if err != nil {
		return
	}
	return true, err
}

// HELPER FUNCTIONS AND STRUCTURES

// Attributes:
//  - Key
type KeyValueGetArgs struct {
	Key string `thrift:"key,1" db:"key" json:"key"`
}

func NewKeyValueGetArgs() *KeyValueGetArgs {
	return &KeyValueGetArgs{}
}

func (p *KeyValueGetArgs) GetKey() string {
	return p.Key
}
func (p *KeyValueGetArgs) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.ReadField1(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	return nil
}

func (p *KeyValueGetArgs) ReadField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 1: ", err)
	} else {
		p.Key = v
	}
	return nil
}

func (p *KeyValueGetArgs) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Get_args"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *KeyValueGetArgs) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("key", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err)
	}
	if err := oprot.WriteString(string(p.Key)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err)
	}
	return err
}

func (p *KeyValueGetArgs) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("KeyValueGetArgs(%+v)", *p)
}

// Attributes:
//  - Success
//  - NotFound
//  - InvalidKey
type KeyValueGetResult struct {
	Success    *string      `thrift:"success,0" db:"success" json:"success,omitempty"`
	NotFound   *KeyNotFound `thrift:"notFound,1" db:"notFound" json:"notFound,omitempty"`
	InvalidKey *InvalidKey  `thrift:"invalidKey,2" db:"invalidKey" json:"invalidKey,omitempty"`
}

func NewKeyValueGetResult() *KeyValueGetResult {
	return &KeyValueGetResult{}
}

var KeyValueGetResult_Success_DEFAULT string

func (p *KeyValueGetResult) GetSuccess() string {
	if !p.IsSetSuccess() {
		return KeyValueGetResult_Success_DEFAULT
	}
	return *p.Success
}

var KeyValueGetResult_NotFound_DEFAULT *KeyNotFound

func (p *KeyValueGetResult) GetNotFound() *KeyNotFound {
	if !p.IsSetNotFound() {
		return KeyValueGetResult_NotFound_DEFAULT
	}
	return p.NotFound
}

var KeyValueGetResult_InvalidKey_DEFAULT *InvalidKey

func (p *KeyValueGetResult) GetInvalidKey() *InvalidKey {
	if !p.IsSetInvalidKey() {
		return KeyValueGetResult_InvalidKey_DEFAULT
	}
	return p.InvalidKey
}
func (p *KeyValueGetResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *KeyValueGetResult) IsSetNotFound() bool {
	return p.NotFound != nil
}

func (p *KeyValueGetResult) IsSetInvalidKey() bool {
	return p.InvalidKey != nil
}

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

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 0:
			if err := p.ReadField0(iprot); err != nil {
				return err
			}
		case 1:
			if err := p.ReadField1(iprot); err != nil {
				return err
			}
		case 2:
			if err := p.ReadField2(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	return nil
}

func (p *KeyValueGetResult) ReadField0(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 0: ", err)
	} else {
		p.Success = &v
	}
	return nil
}

func (p *KeyValueGetResult) ReadField1(iprot thrift.TProtocol) error {
	p.NotFound = &KeyNotFound{}
	if err := p.NotFound.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.NotFound), err)
	}
	return nil
}

func (p *KeyValueGetResult) ReadField2(iprot thrift.TProtocol) error {
	p.InvalidKey = &InvalidKey{}
	if err := p.InvalidKey.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.InvalidKey), err)
	}
	return nil
}

func (p *KeyValueGetResult) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Get_result"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField0(oprot); err != nil {
		return err
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *KeyValueGetResult) writeField0(oprot thrift.TProtocol) (err error) {
	if p.IsSetSuccess() {
		if err := oprot.WriteFieldBegin("success", thrift.STRING, 0); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
		}
		if err := oprot.WriteString(string(*p.Success)); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T.success (0) field write error: ", p), err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
		}
	}
	return err
}

func (p *KeyValueGetResult) writeField1(oprot thrift.TProtocol) (err error) {
	if p.IsSetNotFound() {
		if err := oprot.WriteFieldBegin("notFound", thrift.STRUCT, 1); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:notFound: ", p), err)
		}
		if err := p.NotFound.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.NotFound), err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 1:notFound: ", p), err)
		}
	}
	return err
}

func (p *KeyValueGetResult) writeField2(oprot thrift.TProtocol) (err error) {
	if p.IsSetInvalidKey() {
		if err := oprot.WriteFieldBegin("invalidKey", thrift.STRUCT, 2); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:invalidKey: ", p), err)
		}
		if err := p.InvalidKey.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.InvalidKey), err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 2:invalidKey: ", p), err)
		}
	}
	return err
}

func (p *KeyValueGetResult) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("KeyValueGetResult(%+v)", *p)
}

// Attributes:
//  - Key
//  - Value
type KeyValueSetArgs struct {
	Key   string `thrift:"key,1" db:"key" json:"key"`
	Value string `thrift:"value,2" db:"value" json:"value"`
}

func NewKeyValueSetArgs() *KeyValueSetArgs {
	return &KeyValueSetArgs{}
}

func (p *KeyValueSetArgs) GetKey() string {
	return p.Key
}

func (p *KeyValueSetArgs) GetValue() string {
	return p.Value
}
func (p *KeyValueSetArgs) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.ReadField1(iprot); err != nil {
				return err
			}
		case 2:
			if err := p.ReadField2(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	return nil
}

func (p *KeyValueSetArgs) ReadField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 1: ", err)
	} else {
		p.Key = v
	}
	return nil
}

func (p *KeyValueSetArgs) ReadField2(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 2: ", err)
	} else {
		p.Value = v
	}
	return nil
}

func (p *KeyValueSetArgs) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Set_args"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *KeyValueSetArgs) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("key", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err)
	}
	if err := oprot.WriteString(string(p.Key)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err)
	}
	return err
}

func (p *KeyValueSetArgs) writeField2(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err)
	}
	if err := oprot.WriteString(string(p.Value)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err)
	}
	return err
}

func (p *KeyValueSetArgs) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("KeyValueSetArgs(%+v)", *p)
}

// Attributes:
//  - InvalidKey
type KeyValueSetResult struct {
	InvalidKey *InvalidKey `thrift:"invalidKey,1" db:"invalidKey" json:"invalidKey,omitempty"`
}

func NewKeyValueSetResult() *KeyValueSetResult {
	return &KeyValueSetResult{}
}

var KeyValueSetResult_InvalidKey_DEFAULT *InvalidKey

func (p *KeyValueSetResult) GetInvalidKey() *InvalidKey {
	if !p.IsSetInvalidKey() {
		return KeyValueSetResult_InvalidKey_DEFAULT
	}
	return p.InvalidKey
}
func (p *KeyValueSetResult) IsSetInvalidKey() bool {
	return p.InvalidKey != nil
}

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

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.ReadField1(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	return nil
}

func (p *KeyValueSetResult) ReadField1(iprot thrift.TProtocol) error {
	p.InvalidKey = &InvalidKey{}
	if err := p.InvalidKey.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.InvalidKey), err)
	}
	return nil
}

func (p *KeyValueSetResult) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Set_result"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *KeyValueSetResult) writeField1(oprot thrift.TProtocol) (err error) {
	if p.IsSetInvalidKey() {
		if err := oprot.WriteFieldBegin("invalidKey", thrift.STRUCT, 1); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:invalidKey: ", p), err)
		}
		if err := p.InvalidKey.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.InvalidKey), err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 1:invalidKey: ", p), err)
		}
	}
	return err
}

func (p *KeyValueSetResult) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("KeyValueSetResult(%+v)", *p)
}
