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

Method gBase

gen/marshal.go:356–417  ·  view source on GitHub ↗
(b *BaseElem)

Source from the content-addressed store, hash-verified

354}
355
356func (m *marshalGen) gBase(b *BaseElem) {
357 if !m.p.ok() {
358 return
359 }
360 m.fuseHook()
361 vname := b.Varname()
362 if b.Convert {
363 if b.ShimMode == Cast {
364 vname = tobaseConvert(b)
365 } else {
366 vname = randIdent()
367 m.p.printf("\nvar %s %s", vname, b.BaseType())
368 m.p.printf("\n%s, err = %s", vname, tobaseConvert(b))
369 m.p.wrapErrCheck(m.ctx.ArgsStr())
370 }
371 }
372
373 var echeck bool
374 switch b.Value {
375 case BinaryMarshaler:
376 echeck = true
377 m.binaryMarshalCall(vname, "MarshalBinary", "", "msgp.AppendBytes")
378 case BinaryAppender:
379 echeck = false
380 m.binaryAppendCall(vname, "AppendBinary", "msgp.AppendBytes")
381 case TextMarshalerBin:
382 echeck = true
383 m.binaryMarshalCall(vname, "MarshalText", "", "msgp.AppendBytes")
384 case TextAppenderBin:
385 echeck = false
386 m.binaryAppendCall(vname, "AppendText", "msgp.AppendBytes")
387 case TextMarshalerString:
388 echeck = true
389 m.binaryMarshalCall(vname, "MarshalText", "string", "msgp.AppendString")
390 case TextAppenderString:
391 echeck = false
392 m.binaryAppendCall(vname, "AppendText", "msgp.AppendString")
393 case IDENT:
394 dst := b.BaseType()
395 if b.typeParams.isPtr {
396 dst = "*" + dst
397 }
398 if remap := b.typeParams.ToPointerMap[stripTypeParams(dst)]; remap != "" {
399 vname = fmt.Sprintf(remap, vname)
400 }
401 echeck = true
402 m.p.printf("\no, err = %s.MarshalMsg(o)", vname)
403 case Intf, Ext, JsonNumber:
404 echeck = true
405 m.p.printf("\no, err = msgp.Append%s(o, %s)", b.BaseName(), vname)
406 case AInt64, AInt32, AUint64, AUint32, ABool:
407 t := strings.TrimPrefix(b.BaseName(), "atomic.")
408 echeck = false
409 m.p.printf("\no = msgp.Append%s(o, %s.Load())", t, strings.TrimPrefix(vname, "*"))
410 default:
411 m.rawAppend(b.BaseName(), literalFmt, vname)
412 }
413

Callers

nothing calls this directly

Calls 14

fuseHookMethod · 0.95
binaryMarshalCallMethod · 0.95
binaryAppendCallMethod · 0.95
rawAppendMethod · 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

Tested by

no test coverage detected