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

Method gBase

gen/encode.go:360–416  ·  view source on GitHub ↗
(b *BaseElem)

Source from the content-addressed store, hash-verified

358}
359
360func (e *encodeGen) gBase(b *BaseElem) {
361 if !e.p.ok() {
362 return
363 }
364 e.fuseHook()
365 vname := b.Varname()
366 if b.Convert {
367 if b.ShimMode == Cast {
368 vname = tobaseConvert(b)
369 } else {
370 vname = randIdent()
371 e.p.printf("\nvar %s %s", vname, b.BaseType())
372 e.p.printf("\n%s, err = %s", vname, tobaseConvert(b))
373 e.p.wrapErrCheck(e.ctx.ArgsStr())
374 }
375 }
376 switch b.Value {
377 case AInt64, AInt32, AUint64, AUint32, ABool:
378 t := strings.TrimPrefix(b.BaseName(), "atomic.")
379 e.writeAndCheck(t, literalFmt, strings.TrimPrefix(vname, "*")+".Load()")
380 case BinaryMarshaler:
381 e.binaryEncodeCall(vname, "MarshalBinary", "Bytes", "")
382 case TextMarshalerBin:
383 e.binaryEncodeCall(vname, "MarshalText", "Bytes", "")
384 case TextMarshalerString:
385 e.binaryEncodeCall(vname, "MarshalText", "String", "")
386 case BinaryAppender:
387 // We do not know if the interface is implemented on pointer or value.
388 vname = strings.Trim(vname, "*()")
389 e.writeAndCheck("BinaryAppender", literalFmt, vname)
390 case TextAppenderBin:
391 vname = strings.Trim(vname, "*()")
392 e.writeAndCheck("TextAppender", literalFmt, vname)
393 case TextAppenderString:
394 vname = strings.Trim(vname, "*()")
395 e.writeAndCheck("TextAppenderString", literalFmt, vname)
396 case IDENT: // unknown identity
397 dst := b.BaseType()
398 if b.typeParams.isPtr {
399 dst = "*" + dst
400 }
401
402 // Strip type parameters from dst for lookup in ToPointerMap
403 lookupKey := stripTypeParams(dst)
404 if idx := strings.Index(dst, "["); idx != -1 {
405 lookupKey = dst[:idx]
406 }
407
408 if remap := b.typeParams.ToPointerMap[lookupKey]; remap != "" {
409 vname = fmt.Sprintf(remap, vname)
410 }
411 e.p.printf("\nerr = %s.EncodeMsg(en)", vname)
412 e.p.wrapErrCheck(e.ctx.ArgsStr())
413 default:
414 e.writeAndCheck(b.BaseName(), literalFmt, vname)
415 }
416}

Callers

nothing calls this directly

Calls 13

fuseHookMethod · 0.95
writeAndCheckMethod · 0.95
binaryEncodeCallMethod · 0.95
tobaseConvertFunction · 0.85
randIdentFunction · 0.85
stripTypeParamsFunction · 0.85
okMethod · 0.80
printfMethod · 0.80
BaseTypeMethod · 0.80
wrapErrCheckMethod · 0.80
ArgsStrMethod · 0.80
BaseNameMethod · 0.80

Tested by

no test coverage detected