MCPcopy Create free account
hub / github.com/bet365/jingo / ptrstringval

Method ptrstringval

structencoder.go:460–480  ·  view source on GitHub ↗

ptrstringval is essentially the same as ptrval but quotes strings if not nil

(conv func(unsafe.Pointer, *Buffer))

Source from the content-addressed store, hash-verified

458
459// ptrstringval is essentially the same as ptrval but quotes strings if not nil
460func (e *StructEncoder) ptrstringval(conv func(unsafe.Pointer, *Buffer)) {
461 e.flunk() // flush any chunk data we've buffered
462
463 // avoids allocs at runtime
464 null := []byte("null")
465
466 f := e.f
467 e.appendInstructionFun(func(v unsafe.Pointer, w *Buffer) {
468
469 p := unsafe.Pointer(*(*unsafe.Pointer)(unsafe.Pointer(uintptr(v) + f.Offset)))
470 if p == unsafe.Pointer(nil) {
471 w.Write(null)
472 return
473 }
474
475 // quotes need to be at runtime here because we don't know if we're going to have to null the field
476 w.WriteByte('"')
477 conv(p, w)
478 w.WriteByte('"')
479 })
480}
481
482// JSONEncoder works with the `.encoder` option. Fields can implement this to encode their own JSON string straight
483// into the working buffer. This can be useful if you're working with interface fields at runtime.

Callers 3

NewStructEncoderFunction · 0.95
optInstrEscapeMethod · 0.95
valueInstMethod · 0.95

Calls 4

flunkMethod · 0.95
appendInstructionFunMethod · 0.95
WriteMethod · 0.80
WriteByteMethod · 0.80

Tested by

no test coverage detected