github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_encoder_native_map_above_go118.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package jzon 5 6 import ( 7 "unsafe" 8 ) 9 10 func (enc *directMapEncoder) Encode(ptr unsafe.Pointer, s *Streamer, _ *EncOpts) { 11 if s.Error != nil { 12 return 13 } 14 if ptr == nil { 15 s.Null() 16 return 17 } 18 ptr = *(*unsafe.Pointer)(ptr) 19 if ptr == nil { 20 s.Null() 21 return 22 } 23 s.ObjectStart() 24 var iter hiter 25 mapiterinit(enc.mapRType, ptr, &iter) 26 for i := 0; iter.key != nil; i++ { 27 enc.keyEncoder.Encode(iter.key, s) 28 if s.Error != nil { 29 return 30 } 31 enc.elemEncoder.Encode(iter.elem, s, nil) 32 if s.Error != nil { 33 return 34 } 35 mapiternext(&iter) 36 } 37 s.ObjectEnd() 38 }