當前位置: 首頁>>代碼示例>>Golang>>正文


Golang msgp.NewWriter函數代碼示例

本文整理匯總了Golang中github.com/tinylib/msgp/msgp.NewWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewWriter函數的具體用法?Golang NewWriter怎麽用?Golang NewWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/tinylib/msgp/msgp.NewWriter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。