// Code generated by thriftgo (0.3.15) (fastgo). DO NOT EDIT.
package skip

import (
	"encoding/binary"
	"fmt"

	"github.com/cloudwego/gopkg/protocol/thrift"
)

func (p *TestListMap) BLength() int {
	if p == nil {
		return 1
	}
	off := 0

	// p.ListMap ID:1 thrift.LIST
	off += 3
	off += 5
	for _, v := range p.ListMap {
		off += 6
		for k0, v0 := range v {
			off += 4 + len(k0)
			off += 4 + len(v0)
		}
	}
	return off + 1
}

func (p *TestListMap) FastWrite(b []byte) int { return p.FastWriteNocopy(b, nil) }

func (p *TestListMap) FastWriteNocopy(b []byte, w thrift.NocopyWriter) int {
	if p == nil {
		b[0] = 0
		return 1
	}
	off := 0

	// p.ListMap ID:1 thrift.LIST
	b[off] = 15
	binary.BigEndian.PutUint16(b[off+1:], 1)
	off += 3
	b[off] = 13
	binary.BigEndian.PutUint32(b[off+1:], uint32(len(p.ListMap)))
	off += 5
	for _, v := range p.ListMap {
		b[off] = 11
		b[off+1] = 11
		binary.BigEndian.PutUint32(b[off+2:], uint32(len(v)))
		off += 6
		for k0, v0 := range v {
			off += thrift.Binary.WriteStringNocopy(b[off:], w, k0)
			off += thrift.Binary.WriteStringNocopy(b[off:], w, v0)
		}
	}

	b[off] = 0
	return off + 1
}

func (p *TestListMap) FastRead(b []byte) (off int, err error) {
	var ftyp thrift.TType
	var fid int16
	var l int
	x := thrift.BinaryProtocol{}
	for {
		ftyp, fid, l, err = x.ReadFieldBegin(b[off:])
		off += l
		if err != nil {
			goto ReadFieldBeginError
		}
		if ftyp == thrift.STOP {
			break
		}
		switch uint32(fid)<<8 | uint32(ftyp) {
		case 0x10f: // p.ListMap ID:1 thrift.LIST
			var sz int
			_, sz, l, err = x.ReadListBegin(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
			p.ListMap = make([]map[string]string, sz)
			for i := 0; i < sz; i++ {
				{
					var sz0 int
					_, _, sz0, l, err = x.ReadMapBegin(b[off:])
					off += l
					if err != nil {
						goto ReadFieldError
					}
					p.ListMap[i] = make(map[string]string, sz0)
					for i0 := 0; i0 < sz0; i0++ {
						var k0 string
						var v0 string
						k0, l, err = x.ReadString(b[off:])
						off += l
						if err != nil {
							goto ReadFieldError
						}
						v0, l, err = x.ReadString(b[off:])
						off += l
						if err != nil {
							goto ReadFieldError
						}
						p.ListMap[i][k0] = v0
					}
				}
			}
		default:
			l, err = x.Skip(b[off:], ftyp)
			off += l
			if err != nil {
				goto SkipFieldError
			}
		}
	}
	return
ReadFieldBeginError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field begin error: ", p), err)
ReadFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fid, fieldIDToName_TestListMap[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
}

func (p *SkipTestTestListMapArgs) BLength() int {
	if p == nil {
		return 1
	}
	off := 0

	// p.Req ID:1 thrift.STRUCT
	off += 3
	off += p.Req.BLength()
	return off + 1
}

func (p *SkipTestTestListMapArgs) FastWrite(b []byte) int { return p.FastWriteNocopy(b, nil) }

func (p *SkipTestTestListMapArgs) FastWriteNocopy(b []byte, w thrift.NocopyWriter) int {
	if p == nil {
		b[0] = 0
		return 1
	}
	off := 0

	// p.Req ID:1 thrift.STRUCT
	b[off] = 12
	binary.BigEndian.PutUint16(b[off+1:], 1)
	off += 3
	off += p.Req.FastWriteNocopy(b[off:], w)

	b[off] = 0
	return off + 1
}

func (p *SkipTestTestListMapArgs) FastRead(b []byte) (off int, err error) {
	var ftyp thrift.TType
	var fid int16
	var l int
	x := thrift.BinaryProtocol{}
	for {
		ftyp, fid, l, err = x.ReadFieldBegin(b[off:])
		off += l
		if err != nil {
			goto ReadFieldBeginError
		}
		if ftyp == thrift.STOP {
			break
		}
		switch uint32(fid)<<8 | uint32(ftyp) {
		case 0x10c: // p.Req ID:1 thrift.STRUCT
			p.Req = NewTestListMap()
			l, err = p.Req.FastRead(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
		default:
			l, err = x.Skip(b[off:], ftyp)
			off += l
			if err != nil {
				goto SkipFieldError
			}
		}
	}
	return
ReadFieldBeginError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field begin error: ", p), err)
ReadFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fid, fieldIDToName_SkipTestTestListMapArgs[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
}

func (p *SkipTestTestListMapResult) BLength() int {
	if p == nil {
		return 1
	}
	off := 0

	// p.Success ID:0 thrift.STRUCT
	if p.Success != nil {
		off += 3
		off += p.Success.BLength()
	}
	return off + 1
}

func (p *SkipTestTestListMapResult) FastWrite(b []byte) int { return p.FastWriteNocopy(b, nil) }

func (p *SkipTestTestListMapResult) FastWriteNocopy(b []byte, w thrift.NocopyWriter) int {
	if p == nil {
		b[0] = 0
		return 1
	}
	off := 0

	// p.Success ID:0 thrift.STRUCT
	if p.Success != nil {
		b[off] = 12
		binary.BigEndian.PutUint16(b[off+1:], 0)
		off += 3
		off += p.Success.FastWriteNocopy(b[off:], w)
	}

	b[off] = 0
	return off + 1
}

func (p *SkipTestTestListMapResult) FastRead(b []byte) (off int, err error) {
	var ftyp thrift.TType
	var fid int16
	var l int
	x := thrift.BinaryProtocol{}
	for {
		ftyp, fid, l, err = x.ReadFieldBegin(b[off:])
		off += l
		if err != nil {
			goto ReadFieldBeginError
		}
		if ftyp == thrift.STOP {
			break
		}
		switch uint32(fid)<<8 | uint32(ftyp) {
		case 0xc: // p.Success ID:0 thrift.STRUCT
			p.Success = NewTestListMap()
			l, err = p.Success.FastRead(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
		default:
			l, err = x.Skip(b[off:], ftyp)
			off += l
			if err != nil {
				goto SkipFieldError
			}
		}
	}
	return
ReadFieldBeginError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field begin error: ", p), err)
ReadFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fid, fieldIDToName_SkipTestTestListMapResult[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
}
