MCPcopy Create free account
hub / github.com/francoispqt/gojay / Float32KeyOmitEmpty

Method Float32KeyOmitEmpty

encode_number_float.go:327–345  ·  view source on GitHub ↗

Float32KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key

(key string, v float32)

Source from the content-addressed store, hash-verified

325// Float32KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0.
326// Must be used inside an object as it will encode a key
327func (enc *Encoder) Float32KeyOmitEmpty(key string, v float32) {
328 if enc.hasKeys {
329 if !enc.keyExists(key) {
330 return
331 }
332 }
333 if v == 0 {
334 return
335 }
336 enc.grow(10 + len(key))
337 r := enc.getPreviousRune()
338 if r != '{' {
339 enc.writeByte(',')
340 }
341 enc.writeByte('"')
342 enc.writeStringEscape(key)
343 enc.writeBytes(objKey)
344 enc.buf = strconv.AppendFloat(enc.buf, float64(v), 'f', -1, 32)
345}
346
347// Float32KeyNullEmpty adds a float64 to be encoded and skips it if its value is 0.
348// Must be used inside an object as it will encode a key

Callers 2

MarshalJSONObjectMethod · 0.80

Calls 6

keyExistsMethod · 0.95
growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
writeStringEscapeMethod · 0.95
writeBytesMethod · 0.95

Tested by 1

MarshalJSONObjectMethod · 0.64