• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang msgp.NewWriter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: RawPut

func (db *KVAutobus) RawPut(key storage.Key, value []byte) error {
	b64key := encodeKey(key)
	url := fmt.Sprintf("%s/kvautobus/api/value/%s/%s/", db.host, db.collection, b64key)
	var bin Binary
	if value == nil {
		bin = Binary{}
	} else {
		bin = Binary(value)
	}

	storage.StoreKeyBytesWritten <- len(key)
	storage.StoreValueBytesWritten <- len(value)

	// Create pipe from encoding to posting
	pr, pw := io.Pipe()
	w := msgp.NewWriter(pw)
	go func() {
		bin.EncodeMsg(w)
		w.Flush()
		pw.Close()
	}()

	resp, err := db.client.Post(url, "application/x-msgpack", pr)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusConflict {
		return fmt.Errorf("Can't POST to an already stored key.  KVAutobus returned status %d (%s)", resp.StatusCode, url)
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("Bad status code returned (%d) from put request: %s", resp.StatusCode, url)
	}
	return nil
}
开发者ID:tartavull,项目名称:dvid,代码行数:35,代码来源:kvautobus.go


示例2: WriteTo

func (c *MsgpackDeltasCodec) WriteTo(w io.Writer) error {
	c.encode()
	mw := msgp.NewWriter(w)
	err := c.docs.EncodeMsg(mw)
	mw.Flush()
	return err
}
开发者ID:JustinAzoff,项目名称:flow-indexer,代码行数:7,代码来源:codec.go


示例3: putRange

func (db *KVAutobus) putRange(kvs []storage.KeyValue) error {
	// Transform to an encodable type
	mkvs := make(KVs, len(kvs))
	for i, kv := range kvs {
		storage.StoreKeyBytesWritten <- len(kv.K)
		storage.StoreValueBytesWritten <- len(kv.V)
		mkvs[i] = KV{Binary(kv.K), Binary(kv.V)}
	}

	// Create pipe from encoding to posting
	pr, pw := io.Pipe()
	w := msgp.NewWriter(pw)
	go func() {
		mkvs.EncodeMsg(w)
		w.Flush()
		pw.Close()
	}()

	// Send the data
	url := fmt.Sprintf("%s/kvautobus/api/keyvalue_range/", db.host)
	resp, err := http.Post(url, "application/x-msgpack", pr)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusConflict {
		return fmt.Errorf("Can't POST to an already stored key.  KVAutobus returned status %d (%s)", resp.StatusCode, url)
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("Bad status code returned (%d) from put range request: %s", resp.StatusCode, url)
	}
	return nil
}
开发者ID:jmptrader,项目名称:dvid,代码行数:33,代码来源:kvautobus.go


示例4: RawPut

func (db *KVAutobus) RawPut(key storage.Key, value []byte) error {
	b64key := encodeKey(key)
	url := fmt.Sprintf("%s/kvautobus/api/value/%s/", db.host, b64key)
	bin := Binary(value)

	dvid.Debugf("Begin RawPut on key %s (%d bytes)\n", hex.EncodeToString(key), len(bin))

	// Create pipe from encoding to posting
	pr, pw := io.Pipe()
	w := msgp.NewWriter(pw)
	go func() {
		dvid.Debugf("Starting msgpack encoding...\n")
		bin.EncodeMsg(w)
		w.Flush()
		pw.Close()
		dvid.Debugf("Done msgpack encoding.\n")
	}()

	dvid.Debugf("Beginning POST to kvautobus: %s\n", url)
	resp, err := http.Post(url, "application/x-msgpack", pr)
	dvid.Debugf("Done POST with err %v\n", err)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusConflict {
		return fmt.Errorf("Can't POST to an already stored key.  KVAutobus returned status %d (%s)", resp.StatusCode, url)
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("Bad status code returned (%d) from put request: %s", resp.StatusCode, url)
	}
	return nil
}
开发者ID:jmptrader,项目名称:dvid,代码行数:33,代码来源:kvautobus.go


示例5: NewCodec

func NewCodec(conn io.ReadWriteCloser) *codec {
	c := &codec{
		conn: conn,
		r:    msgp.NewReader(conn),
		w:    msgp.NewWriter(conn),
	}
	return c
}
开发者ID:sztanpet,项目名称:bimpc,代码行数:8,代码来源:generic.go


示例6: NewCodec

func NewCodec(ws *websocket.Conn) *codec {
	c := &codec{
		ws: ws,
		r:  msgp.NewReader(nil),
		w:  msgp.NewWriter(nil),
	}
	return c
}
开发者ID:sztanpet,项目名称:bimpc,代码行数:8,代码来源:websocket.go


示例7: NewCodec

func NewCodec(db *redis.Database, channel string) *codec {
	c := &codec{
		db: db,
		ch: channel,
		r:  msgp.NewReader(nil),
		w:  msgp.NewWriter(nil),
	}
	return c
}
开发者ID:sztanpet,项目名称:bimpc,代码行数:9,代码来源:redis.go


示例8: AddRecord

func (s *testKinesisShard) AddRecord(sn SequenceNumber, rec map[string]interface{}) {
	b := bytes.NewBuffer(make([]byte, 0, 1024))
	w := msgp.NewWriter(b)
	err := w.WriteMapStrIntf(rec)
	if err != nil {
		panic(err)
	}
	w.Flush()
	rs := testKinesisRecords{sn, [][]byte{b.Bytes()}}
	s.records = append(s.records, rs)
}
开发者ID:postmates,项目名称:go-triton,代码行数:11,代码来源:test_util.go


示例9: put

func (adp *AddDataPool) put(ad *AddData) {
	ad.buffer.Reset()
	ad.msgpBuffer.Reset()
	if ad.buffer.Len() > gAddDataBufferMaxLen {
		ad.buffer = &bytes.Buffer{}
	}
	if ad.msgpBuffer.Len() > gAddDataBufferMaxLen {
		ad.msgpBuffer = &bytes.Buffer{}
		ad.msgpWriter = msgp.NewWriter(ad.msgpBuffer)
	}
	adp.pool.Put(ad)
}
开发者ID:dzch,项目名称:binstore,代码行数:12,代码来源:add_req_pool.go


示例10: BenchmarkIncidentEncode

func BenchmarkIncidentEncode(b *testing.B) {
	v := Incident{}
	var buf bytes.Buffer
	msgp.Encode(&buf, &v)
	b.SetBytes(int64(buf.Len()))
	en := msgp.NewWriter(msgp.Nowhere)
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.EncodeMsg(en)
	}
	en.Flush()
}
开发者ID:postfix,项目名称:bangarang,代码行数:13,代码来源:incident_gen_test.go


示例11: newAddData

func newAddData() interface{} {
	ad := &AddData{
		buffer:         &bytes.Buffer{},
		msgpBuffer:     &bytes.Buffer{},
		fnv1a:          fnv.New32a(),
		md5:            md5.New(),
		Key:            "",
		pmsg:           &sarama.ProducerMessage{Topic: gBrokerTopic},
		brokerDoneChan: make(chan int, 1),
	}
	ad.msgpWriter = msgp.NewWriter(ad.msgpBuffer)
	return ad
}
开发者ID:dzch,项目名称:binstore,代码行数:13,代码来源:add_req_pool.go


示例12: BenchmarkEncodebitmapContainerShortIterator

func BenchmarkEncodebitmapContainerShortIterator(b *testing.B) {
	v := bitmapContainerShortIterator{}
	var buf bytes.Buffer
	msgp.Encode(&buf, &v)
	b.SetBytes(int64(buf.Len()))
	en := msgp.NewWriter(msgp.Nowhere)
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.EncodeMsg(en)
	}
	en.Flush()
}
开发者ID:RoaringBitmap,项目名称:roaring,代码行数:13,代码来源:bitmapcontainer_gen_test.go


示例13: BenchmarkNotificationEncode

func BenchmarkNotificationEncode(b *testing.B) {
	r := Notification{
		Method: "Call",
		Body:   nil,
	}

	var buf bytes.Buffer
	w := msgp.NewWriter(&buf)

	for i := 0; i < b.N; i++ {
		r.EncodeMsg(w)
		w.Flush()
		buf.Reset()
	}
}
开发者ID:micro,项目名称:go-plugins,代码行数:15,代码来源:rpc_test.go


示例14: BenchmarkRequestEncode

func BenchmarkRequestEncode(b *testing.B) {
	r := Request{
		ID:     100,
		Method: "Call",
		Body:   nil,
	}

	var buf bytes.Buffer
	w := msgp.NewWriter(&buf)

	for i := 0; i < b.N; i++ {
		r.EncodeMsg(w)
		w.Flush()
		buf.Reset()
	}
}
开发者ID:micro,项目名称:go-plugins,代码行数:16,代码来源:rpc_test.go


示例15: BenchmarkResponseEncode

func BenchmarkResponseEncode(b *testing.B) {
	r := Response{
		ID:    100,
		Error: "error",
		Body:  nil,
	}

	var buf bytes.Buffer
	w := msgp.NewWriter(&buf)

	for i := 0; i < b.N; i++ {
		r.EncodeMsg(w)
		w.Flush()
		buf.Reset()
	}
}
开发者ID:micro,项目名称:go-plugins,代码行数:16,代码来源:rpc_test.go


示例16: BenchmarkFastEncode

// benchmark encoding a small, "fast" type.
// the point here is to see how much garbage
// is generated intrinsically by the encoding/
// decoding process as opposed to the nature
// of the struct.
func BenchmarkFastEncode(b *testing.B) {
	v := &TestFast{
		Lat:  40.12398,
		Long: -41.9082,
		Alt:  201.08290,
		Data: []byte("whaaaaargharbl"),
	}
	var buf bytes.Buffer
	msgp.Encode(&buf, v)
	en := msgp.NewWriter(msgp.Nowhere)
	b.SetBytes(int64(buf.Len()))
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.EncodeMsg(en)
	}
	en.Flush()
}
开发者ID:Congenital,项目名称:msgp,代码行数:23,代码来源:gen_test.go


示例17: response

func (d *Deleter) response(w http.ResponseWriter, statusCode int, errMsg string) {
	var buf bytes.Buffer
	buf.Reset()
	res := map[string]interface{}{
		"error": map[string]interface{}{
			"errno": statusCode,
			/* some msgpack lib cannot support new encoding-spec, so let len(string) < 31 */
			//			"errmsg": "success process: /del?topic=ap_",
			"errmsg": "see errno please",
		},
	}
	wr := msgp.NewWriter(&buf)
	err := wr.WriteIntf(res)
	if err != nil {
		logger.Warning("fail to msgp.wr.WriteIntf: %s", err.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	wr.Flush()
	w.WriteHeader(statusCode)
	_, err = w.Write(buf.Bytes())
	if err != nil {
		logger.Warning("fail to http.ResponseWriter.Write(): %s", err.Error())
		return
	}
	//	/* unpack test */
	//	b := bytes.NewReader(buf.Bytes())
	//	b.Seek(0, 0)
	//	msgr := msgp.NewReader(b)
	//	reqi, err := msgr.ReadIntf()
	//	if err != nil {
	//        msg := fmt.Sprintf("fail to decode post data: %s", err.Error())
	//		logger.Warning("%s", msg)
	//		return
	//	}
	//	logger.Warning("unpack: %v", reqi)
}
开发者ID:dzch,项目名称:cachedeleter,代码行数:37,代码来源:deleter.go


示例18: addKeys

func (mc *MqClient) addKeys(keys []interface{}, doneServers map[string]interface{}, delTime, nextDelay int64, firstDel bool) (err error) {
	/* pack data */
	data := map[string]interface{}{
		gDelKeys:     keys,
		gDelDelTime:  delTime,
		gDelCurDelay: nextDelay,
		gDelFromMq:   true,
		gFirstDel:    firstDel,
		"method":     fmt.Sprintf("%s%d", gDelMethodPrefix, nextDelay), // ktransfer need it
	}
	if len(doneServers) > 0 {
		data[gDoneServers] = doneServers
	}
	var buf bytes.Buffer
	wr := msgp.NewWriter(&buf)
	err = wr.WriteIntf(data)
	if err != nil {
		logger.Warning("fail to msgp.WriteIntf: %s", err.Error())
		return
	}
	wr.Flush()
	r := bytes.NewReader(buf.Bytes())
	/* write mq */
	var mqServerAddrs []string
	if firstDel && len(mc.idcMqServerAddrs) > 0 {
		mqServerAddrs = mc.idcMqServerAddrs
	} else {
		mqServerAddrs = mc.delMqServerAddrs
	}
	toc := make(chan bool, 1)
	go mc.checkMqTimeout(toc)
	ns := len(mqServerAddrs)
	mc.lastServerId = (mc.lastServerId + 1) % ns
	i := 0
	for {
		r.Seek(0, 0)
		url := fmt.Sprintf("http://%s?topic=%s&method=%s%d", mqServerAddrs[mc.lastServerId], mc.clusterName, gDelMethodPrefix, nextDelay)
		req, err1 := http.NewRequest("POST", url, r)
		if err1 != nil {
			logger.Warning("fail to http.NewRequest: %s, %s", url, err1.Error())
			err = err1
			return
		}
		rsp, err1 := mc.client.Do(req)
		if err1 != nil {
			logger.Warning("fail to http.Client.Do: %s, %s", url, err1.Error())
			select {
			case <-toc:
				err = errors.New("add back to mq timeout")
				return
			default:
				/* do nothing */
			}
			i++
			if i == ns {
				err = errors.New("fail to add back to mq, all servers have been retried")
				return
			}
			mc.lastServerId = (mc.lastServerId + 1) % ns
			continue
		} else {
			rsp.Body.Close()
			logger.Notice("success add back to mq: %s", url)
			return nil
		}
	}
}
开发者ID:dzch,项目名称:cachedeleter,代码行数:67,代码来源:mq_client.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang msgp.ReadArrayHeaderBytes函数代码示例发布时间:2022-05-28
下一篇:
Golang msgp.NewReader函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap