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

     1  // Code generated by Kitex v0.0.3. DO NOT EDIT.
     2  
     3  package skip
     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 *TestListMap) 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.LIST {
    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  		default:
    63  			l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
    64  			offset += l
    65  			if err != nil {
    66  				goto SkipFieldError
    67  			}
    68  		}
    69  
    70  		l, err = bthrift.Binary.ReadFieldEnd(buf[offset:])
    71  		offset += l
    72  		if err != nil {
    73  			goto ReadFieldEndError
    74  		}
    75  	}
    76  	l, err = bthrift.Binary.ReadStructEnd(buf[offset:])
    77  	offset += l
    78  	if err != nil {
    79  		goto ReadStructEndError
    80  	}
    81  
    82  	return offset, nil
    83  ReadStructBeginError:
    84  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
    85  ReadFieldBeginError:
    86  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
    87  ReadFieldError:
    88  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_TestListMap[fieldId]), err)
    89  SkipFieldError:
    90  	return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
    91  ReadFieldEndError:
    92  	return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
    93  ReadStructEndError:
    94  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
    95  }
    96  
    97  func (p *TestListMap) FastReadField1(buf []byte) (int, error) {
    98  	offset := 0
    99  
   100  	_, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:])
   101  	offset += l
   102  	if err != nil {
   103  		return offset, err
   104  	}
   105  	p.ListMap = make([]map[string]string, 0, size)
   106  	for i := 0; i < size; i++ {
   107  		_, _, size, l, err := bthrift.Binary.ReadMapBegin(buf[offset:])
   108  		offset += l
   109  		if err != nil {
   110  			return offset, err
   111  		}
   112  		_elem := make(map[string]string, size)
   113  		for i := 0; i < size; i++ {
   114  			var _key string
   115  			if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil {
   116  				return offset, err
   117  			} else {
   118  				offset += l
   119  
   120  				_key = v
   121  
   122  			}
   123  
   124  			var _val string
   125  			if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil {
   126  				return offset, err
   127  			} else {
   128  				offset += l
   129  
   130  				_val = v
   131  
   132  			}
   133  
   134  			_elem[_key] = _val
   135  		}
   136  		if l, err := bthrift.Binary.ReadMapEnd(buf[offset:]); err != nil {
   137  			return offset, err
   138  		} else {
   139  			offset += l
   140  		}
   141  
   142  		p.ListMap = append(p.ListMap, _elem)
   143  	}
   144  	if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil {
   145  		return offset, err
   146  	} else {
   147  		offset += l
   148  	}
   149  	return offset, nil
   150  }
   151  
   152  // for compatibility
   153  func (p *TestListMap) FastWrite(buf []byte) int {
   154  	return 0
   155  }
   156  
   157  func (p *TestListMap) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   158  	offset := 0
   159  	offset += bthrift.Binary.WriteStructBegin(buf[offset:], "TestListMap")
   160  	if p != nil {
   161  		offset += p.fastWriteField1(buf[offset:], binaryWriter)
   162  	}
   163  	offset += bthrift.Binary.WriteFieldStop(buf[offset:])
   164  	offset += bthrift.Binary.WriteStructEnd(buf[offset:])
   165  	return offset
   166  }
   167  
   168  func (p *TestListMap) BLength() int {
   169  	l := 0
   170  	l += bthrift.Binary.StructBeginLength("TestListMap")
   171  	if p != nil {
   172  		l += p.field1Length()
   173  	}
   174  	l += bthrift.Binary.FieldStopLength()
   175  	l += bthrift.Binary.StructEndLength()
   176  	return l
   177  }
   178  
   179  func (p *TestListMap) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   180  	offset := 0
   181  	offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "listMap", thrift.LIST, 1)
   182  	offset += bthrift.Binary.WriteListBegin(buf[offset:], thrift.MAP, len(p.ListMap))
   183  	for _, v := range p.ListMap {
   184  		offset += bthrift.Binary.WriteMapBegin(buf[offset:], thrift.STRING, thrift.STRING, len(v))
   185  		for k, v := range v {
   186  
   187  			offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, k)
   188  
   189  			offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, v)
   190  
   191  		}
   192  		offset += bthrift.Binary.WriteMapEnd(buf[offset:])
   193  	}
   194  	offset += bthrift.Binary.WriteListEnd(buf[offset:])
   195  	offset += bthrift.Binary.WriteFieldEnd(buf[offset:])
   196  	return offset
   197  }
   198  
   199  func (p *TestListMap) field1Length() int {
   200  	l := 0
   201  	l += bthrift.Binary.FieldBeginLength("listMap", thrift.LIST, 1)
   202  	l += bthrift.Binary.ListBeginLength(thrift.MAP, len(p.ListMap))
   203  	for _, v := range p.ListMap {
   204  		l += bthrift.Binary.MapBeginLength(thrift.STRING, thrift.STRING, len(v))
   205  		for k, v := range v {
   206  
   207  			l += bthrift.Binary.StringLengthNocopy(k)
   208  
   209  			l += bthrift.Binary.StringLengthNocopy(v)
   210  
   211  		}
   212  		l += bthrift.Binary.MapEndLength()
   213  	}
   214  	l += bthrift.Binary.ListEndLength()
   215  	l += bthrift.Binary.FieldEndLength()
   216  	return l
   217  }
   218  
   219  func (p *SkipTestTestListMapArgs) FastRead(buf []byte) (int, error) {
   220  	var err error
   221  	var offset int
   222  	var l int
   223  	var fieldTypeId thrift.TType
   224  	var fieldId int16
   225  	_, l, err = bthrift.Binary.ReadStructBegin(buf)
   226  	offset += l
   227  	if err != nil {
   228  		goto ReadStructBeginError
   229  	}
   230  
   231  	for {
   232  		_, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:])
   233  		offset += l
   234  		if err != nil {
   235  			goto ReadFieldBeginError
   236  		}
   237  		if fieldTypeId == thrift.STOP {
   238  			break
   239  		}
   240  		switch fieldId {
   241  		case 1:
   242  			if fieldTypeId == thrift.STRUCT {
   243  				l, err = p.FastReadField1(buf[offset:])
   244  				offset += l
   245  				if err != nil {
   246  					goto ReadFieldError
   247  				}
   248  			} else {
   249  				l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
   250  				offset += l
   251  				if err != nil {
   252  					goto SkipFieldError
   253  				}
   254  			}
   255  		default:
   256  			l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
   257  			offset += l
   258  			if err != nil {
   259  				goto SkipFieldError
   260  			}
   261  		}
   262  
   263  		l, err = bthrift.Binary.ReadFieldEnd(buf[offset:])
   264  		offset += l
   265  		if err != nil {
   266  			goto ReadFieldEndError
   267  		}
   268  	}
   269  	l, err = bthrift.Binary.ReadStructEnd(buf[offset:])
   270  	offset += l
   271  	if err != nil {
   272  		goto ReadStructEndError
   273  	}
   274  
   275  	return offset, nil
   276  ReadStructBeginError:
   277  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
   278  ReadFieldBeginError:
   279  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
   280  ReadFieldError:
   281  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SkipTestTestListMapArgs[fieldId]), err)
   282  SkipFieldError:
   283  	return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
   284  ReadFieldEndError:
   285  	return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
   286  ReadStructEndError:
   287  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
   288  }
   289  
   290  func (p *SkipTestTestListMapArgs) FastReadField1(buf []byte) (int, error) {
   291  	offset := 0
   292  	p.Req = NewTestListMap()
   293  	if l, err := p.Req.FastRead(buf[offset:]); err != nil {
   294  		return offset, err
   295  	} else {
   296  		offset += l
   297  	}
   298  	return offset, nil
   299  }
   300  
   301  // for compatibility
   302  func (p *SkipTestTestListMapArgs) FastWrite(buf []byte) int {
   303  	return 0
   304  }
   305  
   306  func (p *SkipTestTestListMapArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   307  	offset := 0
   308  	offset += bthrift.Binary.WriteStructBegin(buf[offset:], "TestListMap_args")
   309  	if p != nil {
   310  		offset += p.fastWriteField1(buf[offset:], binaryWriter)
   311  	}
   312  	offset += bthrift.Binary.WriteFieldStop(buf[offset:])
   313  	offset += bthrift.Binary.WriteStructEnd(buf[offset:])
   314  	return offset
   315  }
   316  
   317  func (p *SkipTestTestListMapArgs) BLength() int {
   318  	l := 0
   319  	l += bthrift.Binary.StructBeginLength("TestListMap_args")
   320  	if p != nil {
   321  		l += p.field1Length()
   322  	}
   323  	l += bthrift.Binary.FieldStopLength()
   324  	l += bthrift.Binary.StructEndLength()
   325  	return l
   326  }
   327  
   328  func (p *SkipTestTestListMapArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   329  	offset := 0
   330  	offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 1)
   331  	offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter)
   332  	offset += bthrift.Binary.WriteFieldEnd(buf[offset:])
   333  	return offset
   334  }
   335  
   336  func (p *SkipTestTestListMapArgs) field1Length() int {
   337  	l := 0
   338  	l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 1)
   339  	l += p.Req.BLength()
   340  	l += bthrift.Binary.FieldEndLength()
   341  	return l
   342  }
   343  
   344  func (p *SkipTestTestListMapResult) FastRead(buf []byte) (int, error) {
   345  	var err error
   346  	var offset int
   347  	var l int
   348  	var fieldTypeId thrift.TType
   349  	var fieldId int16
   350  	_, l, err = bthrift.Binary.ReadStructBegin(buf)
   351  	offset += l
   352  	if err != nil {
   353  		goto ReadStructBeginError
   354  	}
   355  
   356  	for {
   357  		_, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:])
   358  		offset += l
   359  		if err != nil {
   360  			goto ReadFieldBeginError
   361  		}
   362  		if fieldTypeId == thrift.STOP {
   363  			break
   364  		}
   365  		switch fieldId {
   366  		case 0:
   367  			if fieldTypeId == thrift.STRUCT {
   368  				l, err = p.FastReadField0(buf[offset:])
   369  				offset += l
   370  				if err != nil {
   371  					goto ReadFieldError
   372  				}
   373  			} else {
   374  				l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
   375  				offset += l
   376  				if err != nil {
   377  					goto SkipFieldError
   378  				}
   379  			}
   380  		default:
   381  			l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId)
   382  			offset += l
   383  			if err != nil {
   384  				goto SkipFieldError
   385  			}
   386  		}
   387  
   388  		l, err = bthrift.Binary.ReadFieldEnd(buf[offset:])
   389  		offset += l
   390  		if err != nil {
   391  			goto ReadFieldEndError
   392  		}
   393  	}
   394  	l, err = bthrift.Binary.ReadStructEnd(buf[offset:])
   395  	offset += l
   396  	if err != nil {
   397  		goto ReadStructEndError
   398  	}
   399  
   400  	return offset, nil
   401  ReadStructBeginError:
   402  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
   403  ReadFieldBeginError:
   404  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
   405  ReadFieldError:
   406  	return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SkipTestTestListMapResult[fieldId]), err)
   407  SkipFieldError:
   408  	return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
   409  ReadFieldEndError:
   410  	return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
   411  ReadStructEndError:
   412  	return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
   413  }
   414  
   415  func (p *SkipTestTestListMapResult) FastReadField0(buf []byte) (int, error) {
   416  	offset := 0
   417  	p.Success = NewTestListMap()
   418  	if l, err := p.Success.FastRead(buf[offset:]); err != nil {
   419  		return offset, err
   420  	} else {
   421  		offset += l
   422  	}
   423  	return offset, nil
   424  }
   425  
   426  // for compatibility
   427  func (p *SkipTestTestListMapResult) FastWrite(buf []byte) int {
   428  	return 0
   429  }
   430  
   431  func (p *SkipTestTestListMapResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   432  	offset := 0
   433  	offset += bthrift.Binary.WriteStructBegin(buf[offset:], "TestListMap_result")
   434  	if p != nil {
   435  		offset += p.fastWriteField0(buf[offset:], binaryWriter)
   436  	}
   437  	offset += bthrift.Binary.WriteFieldStop(buf[offset:])
   438  	offset += bthrift.Binary.WriteStructEnd(buf[offset:])
   439  	return offset
   440  }
   441  
   442  func (p *SkipTestTestListMapResult) BLength() int {
   443  	l := 0
   444  	l += bthrift.Binary.StructBeginLength("TestListMap_result")
   445  	if p != nil {
   446  		l += p.field0Length()
   447  	}
   448  	l += bthrift.Binary.FieldStopLength()
   449  	l += bthrift.Binary.StructEndLength()
   450  	return l
   451  }
   452  
   453  func (p *SkipTestTestListMapResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int {
   454  	offset := 0
   455  	if p.IsSetSuccess() {
   456  		offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0)
   457  		offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter)
   458  		offset += bthrift.Binary.WriteFieldEnd(buf[offset:])
   459  	}
   460  	return offset
   461  }
   462  
   463  func (p *SkipTestTestListMapResult) field0Length() int {
   464  	l := 0
   465  	if p.IsSetSuccess() {
   466  		l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0)
   467  		l += p.Success.BLength()
   468  		l += bthrift.Binary.FieldEndLength()
   469  	}
   470  	return l
   471  }
   472  
   473  func (p *SkipTestTestListMapArgs) GetFirstArgument() interface{} {
   474  	return p.Req
   475  }
   476  
   477  func (p *SkipTestTestListMapResult) GetResult() interface{} {
   478  	return p.Success
   479  }