github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/encoder_bool.go (about) 1 package jsonfmt 2 3 import ( 4 "context" 5 "unsafe" 6 ) 7 8 type boolEncoder struct { 9 } 10 11 func (encoder *boolEncoder) Encode(ctx context.Context, space []byte, ptr unsafe.Pointer) []byte { 12 if *(*bool)(ptr) { 13 space = append(space, 't', 'r', 'u', 'e') 14 } else { 15 space = append(space, 'f', 'a', 'l', 's', 'e') 16 } 17 return space 18 }