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

     1  package jzon
     2  
     3  import (
     4  	"encoding"
     5  )
     6  
     7  type textMarshalerValEncoder struct{}
     8  
     9  func (textMarshalerValEncoder) Encode(o interface{}, s *Streamer, opts *EncOpts) {
    10  	if s.Error != nil {
    11  		return
    12  	}
    13  	b, err := o.(encoding.TextMarshaler).MarshalText()
    14  	if err != nil {
    15  		s.Error = err
    16  		return
    17  	}
    18  	s.String(localByteToString(b))
    19  }