当前位置: 首页>>代码示例>>Golang>>正文


Golang jwriter.Writer类代码示例

本文整理汇总了Golang中github.com/trdata/easyjson/jwriter.Writer的典型用法代码示例。如果您正苦于以下问题:Golang Writer类的具体用法?Golang Writer怎么用?Golang Writer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Writer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MarshalEasyJSON

// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Int32) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Int32(v.V)
	} else {
		w.RawString("null")
	}
}
开发者ID:trdata,项目名称:easyjson,代码行数:8,代码来源:gotemplate_Int32.go

示例2: MarshalEasyJSON

// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Uint64) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Uint64(v.V)
	} else {
		w.RawString("null")
	}
}
开发者ID:trdata,项目名称:easyjson,代码行数:8,代码来源:gotemplate_Uint64.go

示例3: MarshalEasyJSON

// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Optional) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Optional(v.V)
	} else {
		w.RawString("null")
	}
}
开发者ID:trdata,项目名称:easyjson,代码行数:8,代码来源:opt.go

示例4: 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
}
开发者ID:trdata,项目名称:easyjson,代码行数:17,代码来源:helpers.go

示例5: 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)

}
开发者ID:trdata,项目名称:easyjson,代码行数:16,代码来源:easyjson_test.go

示例6: 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)
		}
	})
}
开发者ID:trdata,项目名称:easyjson,代码行数:19,代码来源:easyjson_test.go

示例7: MarshalToWriter

// MarshalToWriter marshals the data to an io.Writer.
func MarshalToWriter(v Marshaler, w io.Writer) (written int, err error) {
	jw := jwriter.Writer{}
	v.MarshalEasyJSON(&jw)
	return jw.DumpTo(w)
}
开发者ID:trdata,项目名称:easyjson,代码行数:6,代码来源:helpers.go

示例8: Marshal

// Marshal returns data as a single byte slice. Method is suboptimal as the data is likely to be copied
// from a chain of smaller chunks.
func Marshal(v Marshaler) ([]byte, error) {
	w := jwriter.Writer{}
	v.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
开发者ID:trdata,项目名称:easyjson,代码行数:7,代码来源:helpers.go


注:本文中的github.com/trdata/easyjson/jwriter.Writer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。