本文整理汇总了Golang中github.com/youtube/vitess/go/bytes2.NewChunkedWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewChunkedWriter函数的具体用法?Golang NewChunkedWriter怎么用?Golang NewChunkedWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewChunkedWriter函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: MarshalToStream
// MarshalToStream marshals val into writer.
func MarshalToStream(writer io.Writer, val interface{}) (err error) {
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
if err = MarshalToBuffer(buf, val); err != nil {
return err
}
_, err = buf.WriteTo(writer)
return err
}
开发者ID:kingpro,项目名称:vitess,代码行数:9,代码来源:marshal.go
示例2: BenchmarkEncodeInterface
func BenchmarkEncodeInterface(b *testing.B) {
values := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := 0; i < b.N; i++ {
buf := bytes2.NewChunkedWriter(2048)
EncodeInterface(buf, "Val", values)
buf.Reset()
}
}
开发者ID:hfeeki,项目名称:vitess,代码行数:8,代码来源:bson_test.go
示例3: TestEncodeFieldNil
func TestEncodeFieldNil(t *testing.T) {
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
EncodeField(buf, "Val", nil)
got := string(buf.Bytes())
want := "\nVal\x00"
if got != want {
t.Errorf("nil encode: got %q, want %q", got, want)
}
}
开发者ID:rudyLi,项目名称:vitess,代码行数:9,代码来源:bson_test.go
示例4: TestInterfaceMarshal
func TestInterfaceMarshal(t *testing.T) {
for _, tcase := range interfaceMarshalCases {
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
EncodeInterface(buf, "Val", tcase.in)
got := string(buf.Bytes())
if got != tcase.out {
t.Errorf("%s: got \n%q, want \n%q", tcase.desc, got, tcase.out)
}
}
}
开发者ID:hfeeki,项目名称:vitess,代码行数:10,代码来源:custom_test.go
示例5: WriteRequest
// WriteRequest sends the request to the server
func (cc *ClientCodec) WriteRequest(r *rpc.Request, body interface{}) error {
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
if err := bson.MarshalToBuffer(buf, &RequestBson{r}); err != nil {
return err
}
if err := bson.MarshalToBuffer(buf, body); err != nil {
return err
}
_, err := buf.WriteTo(cc.rwc)
return err
}
开发者ID:haoqoo,项目名称:vitess,代码行数:12,代码来源:codecs.go
示例6: String
// String prints a readable version of Query, and also truncates
// data if it's too long
func (query *Query) String() string {
buf := bytes2.NewChunkedWriter(1024)
fmt.Fprintf(buf, "Sql: %#v, BindVars: {", query.Sql)
for k, v := range query.BindVariables {
switch val := v.(type) {
case []byte:
fmt.Fprintf(buf, "%s: %#v, ", k, slimit(string(val)))
case string:
fmt.Fprintf(buf, "%s: %#v, ", k, slimit(val))
default:
fmt.Fprintf(buf, "%s: %v, ", k, v)
}
}
fmt.Fprintf(buf, "}")
return string(buf.Bytes())
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:18,代码来源:structs.go
示例7: QueryAsString
// QueryAsString prints a readable version of query+bind variables,
// and also truncates data if it's too long
func QueryAsString(sql string, bindVariables map[string]interface{}) string {
buf := bytes2.NewChunkedWriter(1024)
fmt.Fprintf(buf, "Sql: %#v, BindVars: {", sql)
for k, v := range bindVariables {
switch val := v.(type) {
case []byte:
fmt.Fprintf(buf, "%s: %#v, ", k, slimit(string(val)))
case string:
fmt.Fprintf(buf, "%s: %#v, ", k, slimit(val))
default:
fmt.Fprintf(buf, "%s: %v, ", k, v)
}
}
fmt.Fprintf(buf, "}")
return string(buf.Bytes())
}
开发者ID:CowLeo,项目名称:vitess,代码行数:18,代码来源:bound_query.go
示例8: TestInterfaceMarshalFailure
func TestInterfaceMarshalFailure(t *testing.T) {
want := "don't know how to marshal chan int"
func() {
defer func() {
if x := recover(); x != nil {
got := x.(BsonError).Error()
if got != want {
t.Errorf("got %s, want %s", got, want)
}
return
}
}()
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
EncodeInterface(buf, "Val", make(chan int))
t.Errorf("got no error, want %s", want)
}()
}
开发者ID:hfeeki,项目名称:vitess,代码行数:17,代码来源:custom_test.go
示例9: NewServerCodec
// NewServerCodec creates a new server codec for bsonrpc communication
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
return &ServerCodec{conn, bytes2.NewChunkedWriter(DefaultBufferSize)}
}
开发者ID:haoqoo,项目名称:vitess,代码行数:4,代码来源:codecs.go
示例10: Marshal
// Marshal marshals val into encoded.
func Marshal(val interface{}) (encoded []byte, err error) {
buf := bytes2.NewChunkedWriter(DefaultBufferSize)
err = MarshalToBuffer(buf, val)
return buf.Bytes(), err
}
开发者ID:kingpro,项目名称:vitess,代码行数:6,代码来源:marshal.go
注:本文中的github.com/youtube/vitess/go/bytes2.NewChunkedWriter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论