本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例5: NewCodec
func NewCodec(conn io.ReadWriteCloser) *codec {
c := &codec{
conn: conn,
r: msgp.NewReader(conn),
w: msgp.NewWriter(conn),
}
return c
}
示例6: NewCodec
func NewCodec(ws *websocket.Conn) *codec {
c := &codec{
ws: ws,
r: msgp.NewReader(nil),
w: msgp.NewWriter(nil),
}
return c
}
示例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
}
示例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)
}
示例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)
}
示例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()
}
示例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
}
示例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()
}
示例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()
}
}
示例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()
}
}
示例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()
}
}