github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_encoder_native_map_below_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 iter := mapiterinit(enc.mapRType, ptr) 25 for i := 0; iter.key != nil; i++ { 26 enc.keyEncoder.Encode(iter.key, s) 27 if s.Error != nil { 28 return 29 } 30 enc.elemEncoder.Encode(iter.elem, s, nil) 31 if s.Error != nil { 32 return 33 } 34 mapiternext(iter) 35 } 36 s.ObjectEnd() 37 }