github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_encoder_native_interface.go (about)

     1  package jzon
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  type efaceEncoder struct{}
     8  
     9  func (*efaceEncoder) IsEmpty(ptr unsafe.Pointer) bool {
    10  	return *(*interface{})(ptr) == nil
    11  }
    12  
    13  func (*efaceEncoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    14  	if ptr == nil {
    15  		s.Null()
    16  		return
    17  	}
    18  	s.value(*(*interface{})(ptr), opts)
    19  }
    20  
    21  type ifaceEncoder struct{}
    22  
    23  func (*ifaceEncoder) IsEmpty(ptr unsafe.Pointer) bool {
    24  	// TODO: is this ok?
    25  	o := packIFace(ptr)
    26  	return o == nil
    27  }
    28  
    29  func (*ifaceEncoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    30  	if ptr == nil {
    31  		s.Null()
    32  		return
    33  	}
    34  	o := packIFace(ptr)
    35  	s.value(o, opts)
    36  }