本文整理匯總了Golang中github.com/mailru/easyjson/jwriter.Writer.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang Writer.Size方法的具體用法?Golang Writer.Size怎麽用?Golang Writer.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mailru/easyjson/jwriter.Writer
的用法示例。
在下文中一共展示了Writer.Size方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MarshalToHTTPResponseWriter
// MarshalToHTTPResponseWriter sets Content-Length and Content-Type headers for the
// http.ResponseWriter, and send the data to the writer. started will be equal to
// false if an error occurred before any http.ResponseWriter methods were actually
// invoked (in this case a 500 reply is possible).
func MarshalToHTTPResponseWriter(v Marshaler, w http.ResponseWriter) (started bool, written int, err error) {
jw := jwriter.Writer{}
v.MarshalEasyJSON(&jw)
if jw.Error != nil {
return false, 0, jw.Error
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(jw.Size()))
started = true
written, err = jw.DumpTo(w)
return
}
示例2: BenchmarkEJ_Marshal_M_ToWriter
func BenchmarkEJ_Marshal_M_ToWriter(b *testing.B) {
var l int64
out := &DummyWriter{}
for i := 0; i < b.N; i++ {
w := jwriter.Writer{}
largeStructData.MarshalEasyJSON(&w)
if w.Error != nil {
b.Error(w.Error)
}
l = int64(w.Size())
w.DumpTo(out)
}
b.SetBytes(l)
}
示例3: BenchmarkEJ_Marshal_L_ToWriter_Parallel
func BenchmarkEJ_Marshal_L_ToWriter_Parallel(b *testing.B) {
out := &DummyWriter{}
b.RunParallel(func(pb *testing.PB) {
var l int64
for pb.Next() {
w := jwriter.Writer{}
xlStructData.MarshalEasyJSON(&w)
if w.Error != nil {
b.Error(w.Error)
}
l = int64(w.Size())
w.DumpTo(out)
}
if l > 0 {
b.SetBytes(l)
}
})
}