(buf *bytes.Buffer, elemType types.Type, valueExpr string)
| 315 | } |
| 316 | |
| 317 | func generateOptionValueRead(buf *bytes.Buffer, elemType types.Type, valueExpr string) error { |
| 318 | // Handle special named types first |
| 319 | if named, ok := elemType.(*types.Named); ok { |
| 320 | typeStr := named.String() |
| 321 | switch typeStr { |
| 322 | case "time.Time", "github.com/apache/fory/go/fory.Date": |
| 323 | fmt.Fprintf(buf, "\t\t\tctx.ReadValue(reflect.ValueOf(&%s).Elem(), fory.RefModeNone, true)\n", valueExpr) |
| 324 | return nil |
| 325 | } |
| 326 | if _, ok := named.Underlying().(*types.Struct); ok { |
| 327 | fmt.Fprintf(buf, "\t\t\tctx.ReadValue(reflect.ValueOf(&%s).Elem(), fory.RefModeNone, true)\n", valueExpr) |
| 328 | return nil |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if basic, ok := elemType.Underlying().(*types.Basic); ok { |
| 333 | switch basic.Kind() { |
| 334 | case types.Bool: |
| 335 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadBool(err)\n", valueExpr) |
| 336 | case types.Int8: |
| 337 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadInt8(err)\n", valueExpr) |
| 338 | case types.Int16: |
| 339 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadInt16(err)\n", valueExpr) |
| 340 | case types.Int32: |
| 341 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadVarint32(err)\n", valueExpr) |
| 342 | case types.Int: |
| 343 | fmt.Fprintf(buf, "\t\t\t%s = int(buf.ReadVarint64(err))\n", valueExpr) |
| 344 | case types.Int64: |
| 345 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadVarint64(err)\n", valueExpr) |
| 346 | case types.Uint8: |
| 347 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadByte(err)\n", valueExpr) |
| 348 | case types.Uint16: |
| 349 | fmt.Fprintf(buf, "\t\t\t%s = uint16(buf.ReadInt16(err))\n", valueExpr) |
| 350 | case types.Uint32: |
| 351 | fmt.Fprintf(buf, "\t\t\t%s = uint32(buf.ReadInt32(err))\n", valueExpr) |
| 352 | case types.Uint: |
| 353 | fmt.Fprintf(buf, "\t\t\t%s = uint(buf.ReadInt64(err))\n", valueExpr) |
| 354 | case types.Uint64: |
| 355 | fmt.Fprintf(buf, "\t\t\t%s = uint64(buf.ReadInt64(err))\n", valueExpr) |
| 356 | case types.Float32: |
| 357 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadFloat32(err)\n", valueExpr) |
| 358 | case types.Float64: |
| 359 | fmt.Fprintf(buf, "\t\t\t%s = buf.ReadFloat64(err)\n", valueExpr) |
| 360 | case types.String: |
| 361 | fmt.Fprintf(buf, "\t\t\t%s = ctx.ReadString()\n", valueExpr) |
| 362 | default: |
| 363 | fmt.Fprintf(buf, "\t\t\t// TODO: unsupported basic type %s\n", basic.String()) |
| 364 | } |
| 365 | return nil |
| 366 | } |
| 367 | |
| 368 | if slice, ok := elemType.(*types.Slice); ok { |
| 369 | return generateSliceReadInlineNoNull(buf, slice, valueExpr) |
| 370 | } |
| 371 | if mapType, ok := elemType.(*types.Map); ok { |
| 372 | return generateMapReadInlineNoNull(buf, mapType, valueExpr) |
| 373 | } |
| 374 |
no test coverage detected