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

package dependency

import (
	"bytes"
	"context"
	"fmt"
	"reflect"

	"git.apache.org/thrift.git/lib/go/thrift"
)

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

// Attributes:
//  - Parent
//  - Child
//  - CallCount
type DependencyLink struct {
	Parent string `thrift:"parent,1,required" db:"parent" json:"parent"`
	Child  string `thrift:"child,2,required" db:"child" json:"child"`
	// unused field # 3
	CallCount int64 `thrift:"callCount,4,required" db:"callCount" json:"callCount"`
}

func NewDependencyLink() *DependencyLink {
	return &DependencyLink{}
}

func (p *DependencyLink) GetParent() string {
	return p.Parent
}

func (p *DependencyLink) GetChild() string {
	return p.Child
}

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

	var issetParent bool = false
	var issetChild bool = false
	var issetCallCount bool = false

	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 fieldTypeId == thrift.STRING {
				if err := p.ReadField1(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); err != nil {
					return err
				}
			}
			issetParent = true
		case 2:
			if fieldTypeId == thrift.STRING {
				if err := p.ReadField2(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); err != nil {
					return err
				}
			}
			issetChild = true
		case 4:
			if fieldTypeId == thrift.I64 {
				if err := p.ReadField4(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); err != nil {
					return err
				}
			}
			issetCallCount = true
		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)
	}
	if !issetParent {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Parent is not set"))
	}
	if !issetChild {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Child is not set"))
	}
	if !issetCallCount {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field CallCount is not set"))
	}
	return nil
}

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

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

func (p *DependencyLink) ReadField4(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI64(); err != nil {
		return thrift.PrependError("error reading field 4: ", err)
	} else {
		p.CallCount = v
	}
	return nil
}

func (p *DependencyLink) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("DependencyLink"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if p != nil {
		if err := p.writeField1(oprot); err != nil {
			return err
		}
		if err := p.writeField2(oprot); err != nil {
			return err
		}
		if err := p.writeField4(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 *DependencyLink) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("parent", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:parent: ", p), err)
	}
	if err := oprot.WriteString(string(p.Parent)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.parent (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:parent: ", p), err)
	}
	return err
}

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

func (p *DependencyLink) writeField4(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("callCount", thrift.I64, 4); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:callCount: ", p), err)
	}
	if err := oprot.WriteI64(int64(p.CallCount)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.callCount (4) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 4:callCount: ", p), err)
	}
	return err
}

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

// Attributes:
//  - Links
type Dependencies struct {
	Links []*DependencyLink `thrift:"links,1,required" db:"links" json:"links"`
}

func NewDependencies() *Dependencies {
	return &Dependencies{}
}

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

	var issetLinks bool = false

	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 fieldTypeId == thrift.LIST {
				if err := p.ReadField1(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); err != nil {
					return err
				}
			}
			issetLinks = true
		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)
	}
	if !issetLinks {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Links is not set"))
	}
	return nil
}

func (p *Dependencies) ReadField1(iprot thrift.TProtocol) error {
	_, size, err := iprot.ReadListBegin()
	if err != nil {
		return thrift.PrependError("error reading list begin: ", err)
	}
	tSlice := make([]*DependencyLink, 0, size)
	p.Links = tSlice
	for i := 0; i < size; i++ {
		_elem0 := &DependencyLink{}
		if err := _elem0.Read(iprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem0), err)
		}
		p.Links = append(p.Links, _elem0)
	}
	if err := iprot.ReadListEnd(); err != nil {
		return thrift.PrependError("error reading list end: ", err)
	}
	return nil
}

func (p *Dependencies) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Dependencies"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if p != nil {
		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 *Dependencies) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("links", thrift.LIST, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:links: ", p), err)
	}
	if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Links)); err != nil {
		return thrift.PrependError("error writing list begin: ", err)
	}
	for _, v := range p.Links {
		if err := v.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
		}
	}
	if err := oprot.WriteListEnd(); err != nil {
		return thrift.PrependError("error writing list end: ", err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:links: ", p), err)
	}
	return err
}

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

type Dependency interface {
	// Parameters:
	//  - TraceId
	GetDependenciesForTrace(ctx context.Context, traceId string) (r *Dependencies, err error)
	// Parameters:
	//  - Dependencies
	SaveDependencies(ctx context.Context, dependencies *Dependencies) (err error)
}

type DependencyClient struct {
	c thrift.TClient
}

// Deprecated: Use NewDependency instead
func NewDependencyClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *DependencyClient {
	return &DependencyClient{
		c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
	}
}

// Deprecated: Use NewDependency instead
func NewDependencyClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *DependencyClient {
	return &DependencyClient{
		c: thrift.NewTStandardClient(iprot, oprot),
	}
}

func NewDependencyClient(c thrift.TClient) *DependencyClient {
	return &DependencyClient{
		c: c,
	}
}

// Parameters:
//  - TraceId
func (p *DependencyClient) GetDependenciesForTrace(ctx context.Context, traceId string) (r *Dependencies, err error) {
	var _args1 DependencyGetDependenciesForTraceArgs
	_args1.TraceId = traceId
	var _result2 DependencyGetDependenciesForTraceResult
	if err = p.c.Call(ctx, "getDependenciesForTrace", &_args1, &_result2); err != nil {
		return
	}
	return _result2.GetSuccess(), nil
}

// Parameters:
//  - Dependencies
func (p *DependencyClient) SaveDependencies(ctx context.Context, dependencies *Dependencies) (err error) {
	var _args3 DependencySaveDependenciesArgs
	_args3.Dependencies = dependencies
	if err := p.c.Call(ctx, "saveDependencies", &_args3, nil); err != nil {
		return err
	}
	return nil
}

type DependencyProcessor struct {
	processorMap map[string]thrift.TProcessorFunction
	handler      Dependency
}

func (p *DependencyProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
	p.processorMap[key] = processor
}

func (p *DependencyProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
	processor, ok = p.processorMap[key]
	return processor, ok
}

func (p *DependencyProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
	return p.processorMap
}

func NewDependencyProcessor(handler Dependency) *DependencyProcessor {

	self4 := &DependencyProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
	self4.processorMap["getDependenciesForTrace"] = &dependencyProcessorGetDependenciesForTrace{handler: handler}
	self4.processorMap["saveDependencies"] = &dependencyProcessorSaveDependencies{handler: handler}
	return self4
}

func (p *DependencyProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
	name, _, seqId, err := iprot.ReadMessageBegin()
	if err != nil {
		return false, err
	}
	if processor, ok := p.GetProcessorFunction(name); ok {
		return processor.Process(ctx, seqId, iprot, oprot)
	}
	iprot.Skip(thrift.STRUCT)
	iprot.ReadMessageEnd()
	x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
	oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
	x5.Write(oprot)
	oprot.WriteMessageEnd()
	oprot.Flush()
	return false, x5

}

type dependencyProcessorGetDependenciesForTrace struct {
	handler Dependency
}

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

	iprot.ReadMessageEnd()
	result := DependencyGetDependenciesForTraceResult{}
	var retval *Dependencies
	var err2 error
	if retval, err2 = p.handler.GetDependenciesForTrace(ctx, args.TraceId); err2 != nil {
		x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getDependenciesForTrace: "+err2.Error())
		oprot.WriteMessageBegin("getDependenciesForTrace", thrift.EXCEPTION, seqId)
		x.Write(oprot)
		oprot.WriteMessageEnd()
		oprot.Flush()
		return true, err2
	} else {
		result.Success = retval
	}
	if err2 = oprot.WriteMessageBegin("getDependenciesForTrace", 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 dependencyProcessorSaveDependencies struct {
	handler Dependency
}

func (p *dependencyProcessorSaveDependencies) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
	args := DependencySaveDependenciesArgs{}
	if err = args.Read(iprot); err != nil {
		iprot.ReadMessageEnd()
		return false, err
	}

	iprot.ReadMessageEnd()
	var err2 error
	if err2 = p.handler.SaveDependencies(ctx, args.Dependencies); err2 != nil {
		return true, err2
	}
	return true, nil
}

// HELPER FUNCTIONS AND STRUCTURES

// Attributes:
//  - TraceId
type DependencyGetDependenciesForTraceArgs struct {
	TraceId string `thrift:"traceId,1,required" db:"traceId" json:"traceId"`
}

func NewDependencyGetDependenciesForTraceArgs() *DependencyGetDependenciesForTraceArgs {
	return &DependencyGetDependenciesForTraceArgs{}
}

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

	var issetTraceId bool = false

	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 fieldTypeId == thrift.STRING {
				if err := p.ReadField1(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); err != nil {
					return err
				}
			}
			issetTraceId = true
		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)
	}
	if !issetTraceId {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field TraceId is not set"))
	}
	return nil
}

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

func (p *DependencyGetDependenciesForTraceArgs) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("getDependenciesForTrace_args"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if p != nil {
		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 *DependencyGetDependenciesForTraceArgs) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("traceId", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:traceId: ", p), err)
	}
	if err := oprot.WriteString(string(p.TraceId)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.traceId (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:traceId: ", p), err)
	}
	return err
}

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

// Attributes:
//  - Success
type DependencyGetDependenciesForTraceResult struct {
	Success *Dependencies `thrift:"success,0" db:"success" json:"success,omitempty"`
}

func NewDependencyGetDependenciesForTraceResult() *DependencyGetDependenciesForTraceResult {
	return &DependencyGetDependenciesForTraceResult{}
}

var DependencyGetDependenciesForTraceResult_Success_DEFAULT *Dependencies

func (p *DependencyGetDependenciesForTraceResult) GetSuccess() *Dependencies {
	if !p.IsSetSuccess() {
		return DependencyGetDependenciesForTraceResult_Success_DEFAULT
	}
	return p.Success
}
func (p *DependencyGetDependenciesForTraceResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *DependencyGetDependenciesForTraceResult) 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 fieldTypeId == thrift.STRUCT {
				if err := p.ReadField0(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); 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 *DependencyGetDependenciesForTraceResult) ReadField0(iprot thrift.TProtocol) error {
	p.Success = &Dependencies{}
	if err := p.Success.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err)
	}
	return nil
}

func (p *DependencyGetDependenciesForTraceResult) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("getDependenciesForTrace_result"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if p != nil {
		if err := p.writeField0(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 *DependencyGetDependenciesForTraceResult) writeField0(oprot thrift.TProtocol) (err error) {
	if p.IsSetSuccess() {
		if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
		}
		if err := p.Success.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), 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 *DependencyGetDependenciesForTraceResult) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("DependencyGetDependenciesForTraceResult(%+v)", *p)
}

// Attributes:
//  - Dependencies
type DependencySaveDependenciesArgs struct {
	Dependencies *Dependencies `thrift:"dependencies,1" db:"dependencies" json:"dependencies"`
}

func NewDependencySaveDependenciesArgs() *DependencySaveDependenciesArgs {
	return &DependencySaveDependenciesArgs{}
}

var DependencySaveDependenciesArgs_Dependencies_DEFAULT *Dependencies

func (p *DependencySaveDependenciesArgs) GetDependencies() *Dependencies {
	if !p.IsSetDependencies() {
		return DependencySaveDependenciesArgs_Dependencies_DEFAULT
	}
	return p.Dependencies
}
func (p *DependencySaveDependenciesArgs) IsSetDependencies() bool {
	return p.Dependencies != nil
}

func (p *DependencySaveDependenciesArgs) 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 fieldTypeId == thrift.STRUCT {
				if err := p.ReadField1(iprot); err != nil {
					return err
				}
			} else {
				if err := iprot.Skip(fieldTypeId); 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 *DependencySaveDependenciesArgs) ReadField1(iprot thrift.TProtocol) error {
	p.Dependencies = &Dependencies{}
	if err := p.Dependencies.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Dependencies), err)
	}
	return nil
}

func (p *DependencySaveDependenciesArgs) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("saveDependencies_args"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if p != nil {
		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 *DependencySaveDependenciesArgs) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("dependencies", thrift.STRUCT, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:dependencies: ", p), err)
	}
	if err := p.Dependencies.Write(oprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Dependencies), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:dependencies: ", p), err)
	}
	return err
}

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