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

import (
	"encoding/binary"
	"fmt"

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

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

	// p.Null1 ID:1 thrift.I64
	off += 3
	off += 8

	// p.Null2 ID:2 thrift.I64
	if p.Null2 != nil {
		off += 3
		off += 8
	}

	// p.Null3 ID:3 thrift.I64
	off += 3
	off += 8

	// p.Null4 ID:4 thrift.LIST
	off += 3
	off += 5
	off += len(p.Null4) * 8

	// p.Null5 ID:5 thrift.MAP
	off += 3
	off += 6
	off += len(p.Null5) * 8
	for k, _ := range p.Null5 {
		off += 4 + len(k)
	}

	// p.Null6 ID:6 thrift.MAP
	off += 3
	off += 6
	off += len(p.Null6) * (8 + 8)
	return off + 1
}

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

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

	// p.Null1 ID:1 thrift.I64
	b[off] = 10
	binary.BigEndian.PutUint16(b[off+1:], 1)
	off += 3
	binary.BigEndian.PutUint64(b[off:], uint64(p.Null1))
	off += 8

	// p.Null2 ID:2 thrift.I64
	if p.Null2 != nil {
		b[off] = 10
		binary.BigEndian.PutUint16(b[off+1:], 2)
		off += 3
		binary.BigEndian.PutUint64(b[off:], uint64(*p.Null2))
		off += 8
	}

	// p.Null3 ID:3 thrift.I64
	b[off] = 10
	binary.BigEndian.PutUint16(b[off+1:], 3)
	off += 3
	binary.BigEndian.PutUint64(b[off:], uint64(p.Null3))
	off += 8

	// p.Null4 ID:4 thrift.LIST
	b[off] = 15
	binary.BigEndian.PutUint16(b[off+1:], 4)
	off += 3
	b[off] = 10
	binary.BigEndian.PutUint32(b[off+1:], uint32(len(p.Null4)))
	off += 5
	for _, v := range p.Null4 {
		binary.BigEndian.PutUint64(b[off:], uint64(v))
		off += 8
	}

	// p.Null5 ID:5 thrift.MAP
	b[off] = 13
	binary.BigEndian.PutUint16(b[off+1:], 5)
	off += 3
	b[off] = 11
	b[off+1] = 10
	binary.BigEndian.PutUint32(b[off+2:], uint32(len(p.Null5)))
	off += 6
	for k, v := range p.Null5 {
		off += thrift.Binary.WriteStringNocopy(b[off:], w, k)
		binary.BigEndian.PutUint64(b[off:], uint64(v))
		off += 8
	}

	// p.Null6 ID:6 thrift.MAP
	b[off] = 13
	binary.BigEndian.PutUint16(b[off+1:], 6)
	off += 3
	b[off] = 10
	b[off+1] = 10
	binary.BigEndian.PutUint32(b[off+2:], uint32(len(p.Null6)))
	off += 6
	for k, v := range p.Null6 {
		binary.BigEndian.PutUint64(b[off:], uint64(k))
		off += 8
		binary.BigEndian.PutUint64(b[off:], uint64(v))
		off += 8
	}

	b[off] = 0
	return off + 1
}

func (p *NullStruct) FastRead(b []byte) (off int, err error) {
	var ftyp thrift.TType
	var fid int16
	var l int
	var isset uint8
	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 0x10a: // p.Null1 ID:1 thrift.I64
			p.Null1, l, err = x.ReadI64(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
		case 0x20a: // p.Null2 ID:2 thrift.I64
			if p.Null2 == nil {
				p.Null2 = new(int64)
			}
			*p.Null2, l, err = x.ReadI64(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
		case 0x30a: // p.Null3 ID:3 thrift.I64
			p.Null3, l, err = x.ReadI64(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
			isset |= 0x1
		case 0x40f: // p.Null4 ID:4 thrift.LIST
			var sz int
			_, sz, l, err = x.ReadListBegin(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
			p.Null4 = make([]int64, sz)
			for i := 0; i < sz; i++ {
				p.Null4[i], l, err = x.ReadI64(b[off:])
				off += l
				if err != nil {
					goto ReadFieldError
				}
			}
		case 0x50d: // p.Null5 ID:5 thrift.MAP
			var sz int
			_, _, sz, l, err = x.ReadMapBegin(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
			p.Null5 = make(map[string]int64, sz)
			for i := 0; i < sz; i++ {
				var k string
				var v int64
				k, l, err = x.ReadString(b[off:])
				off += l
				if err != nil {
					goto ReadFieldError
				}
				v, l, err = x.ReadI64(b[off:])
				off += l
				if err != nil {
					goto ReadFieldError
				}
				p.Null5[k] = v
			}
		case 0x60d: // p.Null6 ID:6 thrift.MAP
			var sz int
			_, _, sz, l, err = x.ReadMapBegin(b[off:])
			off += l
			if err != nil {
				goto ReadFieldError
			}
			p.Null6 = make(map[int64]int64, sz)
			for i := 0; i < sz; i++ {
				var k int64
				var v int64
				k, l, err = x.ReadI64(b[off:])
				off += l
				if err != nil {
					goto ReadFieldError
				}
				v, l, err = x.ReadI64(b[off:])
				off += l
				if err != nil {
					goto ReadFieldError
				}
				p.Null6[k] = v
			}
		default:
			l, err = x.Skip(b[off:], ftyp)
			off += l
			if err != nil {
				goto SkipFieldError
			}
		}
	}
	if isset&0x1 == 0 {
		fid = 3 // Null3
		goto RequiredFieldNotSetError
	}
	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_NullStruct[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
RequiredFieldNotSetError:
	return off, thrift.NewProtocolException(thrift.INVALID_DATA, fmt.Sprintf("required field %s is not set", fieldIDToName_NullStruct[fid]))
}

func (p *NullServiceNullTestArgs) 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 *NullServiceNullTestArgs) FastWrite(b []byte) int { return p.FastWriteNocopy(b, nil) }

func (p *NullServiceNullTestArgs) 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 *NullServiceNullTestArgs) 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 = NewNullStruct()
			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_NullServiceNullTestArgs[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
}

func (p *NullServiceNullTestResult) 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 *NullServiceNullTestResult) FastWrite(b []byte) int { return p.FastWriteNocopy(b, nil) }

func (p *NullServiceNullTestResult) 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 *NullServiceNullTestResult) 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 = NewNullStruct()
			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_NullServiceNullTestResult[fid]), err)
SkipFieldError:
	return off, thrift.PrependError(fmt.Sprintf("%T skip field %d type %d error: ", p, fid, ftyp), err)
}
