MCPcopy
hub / github.com/tinylib/msgp / textappend

Function textappend

parse/directives.go:474–526  ·  view source on GitHub ↗

msgp:textappend [as:string] pkg.Type pkg.Type2

(text []string, f *FileSet)

Source from the content-addressed store, hash-verified

472
473//msgp:textappend [as:string] pkg.Type pkg.Type2
474func textappend(text []string, f *FileSet) error {
475 if len(text) < 2 {
476 return fmt.Errorf("textappend directive should have at least 1 argument; found %d", len(text)-1)
477 }
478
479 // Check for as:string option anywhere in the arguments
480 var asString bool
481 var typeArgs []string
482 alwaysPtr := true
483
484 for _, item := range text[1:] {
485 trimmed := strings.TrimSpace(item)
486 if strings.HasPrefix(trimmed, "as:") {
487 option := strings.TrimPrefix(trimmed, "as:")
488 switch option {
489 case "string":
490 asString = true
491 case "bin":
492 asString = false
493 default:
494 return fmt.Errorf("invalid as: option %q, expected 'string' or 'bin'", option)
495 }
496 } else {
497 typeArgs = append(typeArgs, trimmed)
498 }
499 }
500
501 if len(typeArgs) == 0 {
502 return fmt.Errorf("textappend directive should have at least 1 type argument")
503 }
504
505 for _, item := range typeArgs {
506 name := strings.TrimSpace(item)
507 be := gen.Ident(name)
508 if asString {
509 be.Value = gen.TextAppenderString
510 } else {
511 be.Value = gen.TextAppenderBin
512 }
513 be.Alias(name)
514 be.Convert = false // Don't use conversion for marshaler types
515 be.AlwaysPtr(&alwaysPtr)
516
517 if asString {
518 infof("%s -> TextAppender (as string)\n", name)
519 } else {
520 infof("%s -> TextAppender (as bin)\n", name)
521 }
522 f.findShim(name, be, true)
523 }
524
525 return nil
526}

Callers

nothing calls this directly

Calls 5

IdentFunction · 0.92
infofFunction · 0.85
findShimMethod · 0.80
AliasMethod · 0.65
AlwaysPtrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…