ptrval creates an instruction to read from a pointer field we're marshaling
(conv func(unsafe.Pointer, *Buffer))
| 438 | |
| 439 | // ptrval creates an instruction to read from a pointer field we're marshaling |
| 440 | func (e *StructEncoder) ptrval(conv func(unsafe.Pointer, *Buffer)) { |
| 441 | |
| 442 | e.flunk() // flush any chunk data we've buffered |
| 443 | |
| 444 | // avoids allocs at runtime |
| 445 | null := []byte("null") |
| 446 | |
| 447 | f := e.f |
| 448 | e.appendInstructionFun(func(v unsafe.Pointer, w *Buffer) { |
| 449 | |
| 450 | p := unsafe.Pointer(*(*unsafe.Pointer)(unsafe.Pointer(uintptr(v) + f.Offset))) |
| 451 | if p == unsafe.Pointer(nil) { |
| 452 | w.Write(null) |
| 453 | return |
| 454 | } |
| 455 | conv(p, w) |
| 456 | }) |
| 457 | } |
| 458 | |
| 459 | // ptrstringval is essentially the same as ptrval but quotes strings if not nil |
| 460 | func (e *StructEncoder) ptrstringval(conv func(unsafe.Pointer, *Buffer)) { |
no test coverage detected