本文整理汇总了Golang中encoding.BinaryMarshaler.MarshalBinary方法的典型用法代码示例。如果您正苦于以下问题:Golang BinaryMarshaler.MarshalBinary方法的具体用法?Golang BinaryMarshaler.MarshalBinary怎么用?Golang BinaryMarshaler.MarshalBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类encoding.BinaryMarshaler
的用法示例。
在下文中一共展示了BinaryMarshaler.MarshalBinary方法的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)
}
示例2: mustMarshal
func mustMarshal(v encoding.BinaryMarshaler) []byte {
res, err := v.MarshalBinary()
if err != nil {
panic(err)
}
return res
}
示例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)
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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")
}
}
}
示例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)
}
示例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)
}