github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/testdata/kitex_gen/deep/k-deep.ref.go (about)

     1  // Code generated by Kitex v0.0.3. DO NOT EDIT.
     2  
     3  package deep
     4  
     5  import (
     6  	"bytes"
     7  	"fmt"
     8  	"reflect"
     9  	"strings"
    10  
    11  	"github.com/apache/thrift/lib/go/thrift"
    12  
    13  	"github.com/cloudwego/kitex/pkg/protocol/bthrift"
    14  )
    15  
    16  // unused protection
    17  var (
    18  	_ = fmt.Formatter(nil)
    19  	_ = (*bytes.Buffer)(nil)
    20  	_ = (*strings.Builder)(nil)
    21  	_ = reflect.Type(nil)
    22  	_ = thrift.TProtocol(nil)
    23  	_ = bthrift.BinaryWriter(nil)
    24  )
    25  
    26  func (p *TestStruct) FastRead(buf []byte) (int, error) {
    27  	var err error
    28  	var offset int
    29  	var l int
    30  	var fieldTypeId thrift.TType
    31  	var fieldId int16
    32  	_, l, err = bthrift.Binary.ReadStructBegin(buf)
    33  	offset += l
    34  	if err != nil {
    35  		goto ReadStructBeginError
    36  	}
    37  
    38  	for {
    39  		_, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:])
    40  		offset += l
    41  		if err != nil {
    42  			goto ReadFieldBeginError
    43  		}
    44  		if fieldTypeId == thrift.STOP {
    45  			break
    46  		}
    47  		switch fieldId {
    48  		case 1:
    49  			if fieldTypeId == thrift.I64 {
    50  				l, err = p.FastReadField1(buf[offset:])
    51  				offset += l
    52  				if err != nil {
    53  					goto ReadFieldError
    54  				}
    55  			} else {
    56  				l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
    57  				offset += l
    58  				if err != nil {
    59  					goto SkipFieldError
    60  				}
    61  			}
    62  		case 2:
    63  			if fieldTypeId == thrift.STRING {
    64  				l, err = p.FastReadField2(buf[offset:])
    65  				offset += l
    66  				if err != nil {
    67  					goto ReadFieldError
    68  				}
    69  			} else {
    70  				l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
    71  				offset += l
    72  				if err != nil {
    73  					goto SkipFieldError
    74  				}
    75  			}
    76  		default:
    77  			l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
    78  			offset += l
    79  			if err != nil {
    80  				goto SkipFieldError
    81  			}
    82  		}
    83  
    84  		l, err = bthrift.Binary.ReadFieldEnd(buf[offset:])
    85  		offset += l
    86  		if err != nil {
    87  			goto ReadFieldEndError
    88  		}
    89  	}
    90  	l, err = bthrift.Binary.ReadStructEnd(buf[offset:])
    91  	offset += l
    92  	if err != nil {
    93  		goto ReadStructEndError
    94  	}
    95  
    96  	return offset, nil
    97  ReadStructBeginError:
    98  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
    99  ReadFieldBeginError:
   100  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
   101  ReadFieldError:
   102  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_TestStruct[fieldId]), err)
   103  SkipFieldError:
   104  	return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
   105  ReadFieldEndError:
   106  	return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
   107  ReadStructEndError:
   108  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
   109  }
   110  
   111  func (p *TestStruct) FastReadField1(buf []byte) (int, error) {
   112  	offset := 0
   113  
   114  	if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil {
   115  		return offset, err
   116  	} else {
   117  		offset += l
   118  
   119  		p.A = v
   120  
   121  	}
   122  	return offset, nil
   123  }
   124  
   125  func (p *TestStruct) FastReadField2(buf []byte) (int, error) {
   126  	offset := 0
   127  
   128  	if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil {
   129  		return offset, err
   130  	} else {
   131  		offset += l
   132  
   133  		p.B = v
   134  
   135  	}
   136  	return offset, nil
   137  }
   138  
   139  // for compatibility
   140  func (p *TestStruct) FastWrite(buf []byte) int {
   141  	return 0
   142  }
   143  
   144  func (p *TestStruct) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   145  	offset := 0
   146  	offset += bthrift.Binary.WriteStructBegin(buf[offset:], "TestStruct")
   147  	if p != nil {
   148  		offset += p.fastWriteField1(buf[offset:], binaryWriter)
   149  		offset += p.fastWriteField2(buf[offset:], binaryWriter)
   150  	}
   151  	offset += bthrift.Binary.WriteFieldStop(buf[offset:])
   152  	offset += bthrift.Binary.WriteStructEnd(buf[offset:])
   153  	return offset
   154  }
   155  
   156  func (p *TestStruct) BLength() int {
   157  	l := 0
   158  	l += bthrift.Binary.StructBeginLength("TestStruct")
   159  	if p != nil {
   160  		l += p.field1Length()
   161  		l += p.field2Length()
   162  	}
   163  	l += bthrift.Binary.FieldStopLength()
   164  	l += bthrift.Binary.StructEndLength()
   165  	return l
   166  }
   167  
   168  func (p *TestStruct) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   169  	offset := 0
   170  	offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "a", thrift.I64, 1)
   171  	offset += bthrift.Binary.WriteI64(buf[offset:], p.A)
   172  
   173  	offset += bthrift.Binary.WriteFieldEnd(buf[offset:])
   174  	return offset
   175  }
   176  
   177  func (p *TestStruct) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   178  	offset := 0
   179  	offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "b", thrift.STRING, 2)
   180  	offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.B)
   181  
   182  	offset += bthrift.Binary.WriteFieldEnd(buf[offset:])
   183  	return offset
   184  }
   185  
   186  func (p *TestStruct) field1Length() int {
   187  	l := 0
   188  	l += bthrift.Binary.FieldBeginLength("a", thrift.I64, 1)
   189  	l += bthrift.Binary.I64Length(p.A)
   190  
   191  	l += bthrift.Binary.FieldEndLength()
   192  	return l
   193  }
   194  
   195  func (p *TestStruct) field2Length() int {
   196  	l := 0
   197  	l += bthrift.Binary.FieldBeginLength("b", thrift.STRING, 2)
   198  	l += bthrift.Binary.StringLengthNocopy(p.B)
   199  
   200  	l += bthrift.Binary.FieldEndLength()
   201  	return l
   202  }