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


Golang encoding.BinaryMarshaler類代碼示例

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


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

示例1: Send

func (s *simpleSender) Send(topic string, value encoding.BinaryMarshaler) error {
	buf, err := value.MarshalBinary()
	if err != nil {
		return err
	}
	return s.p.Produce(topic, nil, buf)
}
開發者ID:h12w,項目名稱:kpax,代碼行數:7,代碼來源:sender.go

示例2: mustMarshal

func mustMarshal(v encoding.BinaryMarshaler) []byte {
	res, err := v.MarshalBinary()
	if err != nil {
		panic(err)
	}
	return res
}
開發者ID:ably-forks,項目名稱:flynn,代碼行數:7,代碼來源:compare_test.go

示例3: Delete

// Delete implements KeyValueStore.
func (l *LevelDB) Delete(key encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	return l.storage.Delete(k, l.writeOpts)
}
開發者ID:gitlabuser,項目名稱:prometheus,代碼行數:8,代碼來源:leveldb.go

示例4: Delete

// Delete implements Batch.
func (b *LevelDBBatch) Delete(key encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	b.batch.Delete(k)
	return nil
}
開發者ID:RMeharg,項目名稱:prometheus,代碼行數:9,代碼來源:leveldb.go

示例5: encodeBinaryMarshaler

func (enc *Encoder) encodeBinaryMarshaler(v encoding.BinaryMarshaler) error {
	b, err := v.MarshalBinary()
	if err != nil {
		return err
	}
	_, errr := enc.w.Write(b)
	return errr
}
開發者ID:castaneai,項目名稱:go-binstruct,代碼行數:8,代碼來源:encoder.go

示例6: sendcmd

func sendcmd(conn io.Writer, m encoding.BinaryMarshaler) {
	if bs, err := m.MarshalBinary(); err != nil {
		log.Fatalln(err)
	} else if !*n {
		if _, err := conn.Write(bs); err != nil {
			log.Fatalln(err)
		}
	} else {
		log.Println("ok", m)
	}
}
開發者ID:Reinaesaya,項目名稱:go-cuddlebot,代碼行數:11,代碼來源:main.go

示例7: Put

// Put implements KeyValueStore.
func (l *LevelDB) Put(key, value encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	v, err := value.MarshalBinary()
	if err != nil {
		return err
	}
	return l.storage.Put(k, v, l.writeOpts)
}
開發者ID:RMeharg,項目名稱:prometheus,代碼行數:12,代碼來源:leveldb.go

示例8: EncodeLV

// EncodeLV encodes v to a binary format and writes the length-value record to w.
func EncodeLV(w io.Writer, v encoding.BinaryMarshaler) error {
	buf, err := v.MarshalBinary()
	if err != nil {
		return err
	}

	if err := WriteLV(w, buf); err != nil {
		return err
	}
	return nil
}
開發者ID:seiflotfy,項目名稱:influxdb,代碼行數:12,代碼來源:service.go

示例9: Write

func (r *Transceiver) Write(msg encoding.BinaryMarshaler) error {
	packet, err := msg.MarshalBinary()
	if err != nil {
		return err
	}

	if _, err := r.stream.Write(packet); err != nil {
		return err
	}

	return nil
}
開發者ID:yebinMoon,項目名稱:cherry,代碼行數:12,代碼來源:transceiver.go

示例10: copyBinary

func copyBinary(t *testing.T, from encoding.BinaryMarshaler, to encoding.BinaryUnmarshaler) {
	data, err := from.MarshalBinary()
	if err != nil {
		t.Errorf(err.Error())
		return
	}

	err = to.UnmarshalBinary(data)
	if err != nil {
		t.Errorf(err.Error())
		return
	}
}
開發者ID:docwalter,項目名稱:bitset,代碼行數:13,代碼來源:bitset_test.go

示例11: Delete

// Delete implements KeyValueStore.
func (l *LevelDB) Delete(key encoding.BinaryMarshaler) (bool, error) {
	k, err := key.MarshalBinary()
	if err != nil {
		return false, err
	}
	err = l.storage.Delete(k, l.writeOpts)
	if err == leveldb.ErrNotFound {
		return false, nil
	}
	if err != nil {
		return false, err
	}
	return true, nil
}
開發者ID:bluecmd,項目名稱:prometheus,代碼行數:15,代碼來源:leveldb.go

示例12: sendPacket

// sendPacket marshals p according to RFC 4234.
func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error {
	bb, err := m.MarshalBinary()
	if err != nil {
		return fmt.Errorf("marshal2(%#v): binary marshaller failed", err)
	}
	l := uint32(len(bb))
	hdr := []byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}
	debug("send packet %T, len: %v", m, l)
	_, err = w.Write(hdr)
	if err != nil {
		return err
	}
	_, err = w.Write(bb)
	return err
}
開發者ID:marete,項目名稱:restic,代碼行數:16,代碼來源:packet.go

示例13: testMarshalExpect

func testMarshalExpect(t *testing.T, m encoding.BinaryMarshaler, expect []byte) {
	subject, err := m.MarshalBinary()
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("Bytes: %v", subject)
	if len(subject) != len(expect) {
		t.Fatalf("Expected %d bytes, got %d", len(expect), len(subject))
	}
	for i, v := range subject {
		if v != expect[i] {
			t.Fatal("Bytes did not match expected")
		}
	}
}
開發者ID:Reinaesaya,項目名稱:go-cuddlebot,代碼行數:15,代碼來源:msgtype_test.go

示例14: Marshaler

//  Marshaler encodes a encoding.BinaryMarshaler into buffer
func (e *Enc) Marshaler(x encoding.BinaryMarshaler) {
	if e.err != nil {
		return
	}
	if x == nil {
		e.err = errEncode
		return
	}
	var buf []byte
	buf, e.err = x.MarshalBinary()
	if e.err != nil {
		return
	}
	e.ByteSlice(buf)
}
開發者ID:mrkovec,項目名稱:encdec,代碼行數:16,代碼來源:encdec.go

示例15: Get

// Get implements KeyValueStore.
func (l *LevelDB) Get(key encoding.BinaryMarshaler, value encoding.BinaryUnmarshaler) (bool, error) {
	k, err := key.MarshalBinary()
	if err != nil {
		return false, err
	}
	raw, err := l.storage.Get(k, l.readOpts)
	if err == leveldb.ErrNotFound {
		return false, nil
	}
	if err != nil {
		return false, err
	}
	if value == nil {
		return true, nil
	}
	return true, value.UnmarshalBinary(raw)
}
開發者ID:RMeharg,項目名稱:prometheus,代碼行數:18,代碼來源:leveldb.go


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