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

     1  package jzon
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  // float32 encoder
     8  type float32Encoder struct{}
     9  
    10  func (*float32Encoder) IsEmpty(ptr unsafe.Pointer) bool {
    11  	return *(*float32)(ptr) == 0
    12  }
    13  
    14  func (*float32Encoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    15  	if ptr == nil {
    16  		s.Null()
    17  		return
    18  	}
    19  	s.Float32(*(*float32)(ptr))
    20  }
    21  
    22  // float64 encoder
    23  type float64Encoder struct{}
    24  
    25  func (*float64Encoder) IsEmpty(ptr unsafe.Pointer) bool {
    26  	return *(*float64)(ptr) == 0
    27  }
    28  
    29  func (*float64Encoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    30  	if ptr == nil {
    31  		s.Null()
    32  		return
    33  	}
    34  	s.Float64(*(*float64)(ptr))
    35  }