github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/streamer_val.go (about) 1 package jzon 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 func (s *Streamer) value(obj interface{}, opts *EncOpts) *Streamer { 9 if s.Error != nil { 10 return s 11 } 12 if obj == nil { 13 s.Null() 14 return s 15 } 16 ef := (*eface)(unsafe.Pointer(&obj)) 17 enc := s.cfg.getEncoderFromCache(ef.rtype) 18 if enc == nil { 19 typ := reflect.TypeOf(obj) 20 enc = s.cfg.createEncoder(ef.rtype, typ) 21 } 22 enc.Encode(ef.data, s, opts) 23 return s 24 } 25 26 // Value encodes a golang object to json 27 func (s *Streamer) Value(obj interface{}) *Streamer { 28 return s.value(obj, nil) 29 }