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

     1  package jzon
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  type jsonNumberEncoder struct {
     8  }
     9  
    10  func (*jsonNumberEncoder) IsEmpty(ptr unsafe.Pointer) bool {
    11  	return *(*string)(ptr) == ""
    12  }
    13  
    14  func (*jsonNumberEncoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    15  	if ptr == nil {
    16  		s.Null()
    17  		return
    18  	}
    19  	str := *(*string)(ptr)
    20  	if str == "" {
    21  		str = "0"
    22  	}
    23  	// TODO: the standard library will check the validity in future
    24  	s.RawString(str)
    25  }