forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request newrelic#52 from will/event-intrinsics
JSON object fields writer
- Loading branch information
Showing
6 changed files
with
143 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package internal | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/newrelic/go-agent/internal/jsonx" | ||
) | ||
|
||
type jsonFieldsWriter struct { | ||
buf *bytes.Buffer | ||
needsComma bool | ||
} | ||
|
||
func (w *jsonFieldsWriter) addKey(key string) { | ||
if w.needsComma { | ||
w.buf.WriteByte(',') | ||
} else { | ||
w.needsComma = true | ||
} | ||
// defensively assume that the key needs escaping: | ||
jsonx.AppendString(w.buf, key) | ||
w.buf.WriteByte(':') | ||
} | ||
|
||
func (w *jsonFieldsWriter) stringField(key string, val string) { | ||
w.addKey(key) | ||
jsonx.AppendString(w.buf, val) | ||
} | ||
|
||
func (w *jsonFieldsWriter) intField(key string, val int64) { | ||
w.addKey(key) | ||
jsonx.AppendInt(w.buf, val) | ||
} | ||
|
||
func (w *jsonFieldsWriter) floatField(key string, val float64) { | ||
w.addKey(key) | ||
jsonx.AppendFloat(w.buf, val) | ||
} | ||
|
||
func (w *jsonFieldsWriter) rawField(key string, val JSONString) { | ||
w.addKey(key) | ||
w.buf.WriteString(string(val)) | ||
} |
Oops, something went wrong.