github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/encoder_pointer.go (about)

     1  package jsonfmt
     2  
     3  import (
     4  	"unsafe"
     5  	"context"
     6  )
     7  
     8  type pointerEncoder struct {
     9  	elemEncoder Encoder
    10  }
    11  
    12  func (encoder *pointerEncoder) Encode(ctx context.Context, space []byte, ptr unsafe.Pointer) []byte {
    13  	ptrTo := *(*unsafe.Pointer)(ptr)
    14  	if ptrTo == nil {
    15  		return append(space, 'n', 'u', 'l', 'l')
    16  	}
    17  	return encoder.elemEncoder.Encode(ctx, space, ptrTo)
    18  }