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) }
func mustMarshal(v encoding.BinaryMarshaler) []byte { res, err := v.MarshalBinary() if err != nil { panic(err) } return res }
// 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) }
// 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 }
func (enc *Encoder) encodeBinaryMarshaler(v encoding.BinaryMarshaler) error { b, err := v.MarshalBinary() if err != nil { return err } _, errr := enc.w.Write(b) return errr }
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) } }
// 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) }
// 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 }
// Put implements Batch. func (b *LevelDBBatch) Put(key, value encoding.BinaryMarshaler) error { k, err := key.MarshalBinary() if err != nil { return err } v, err := value.MarshalBinary() if err != nil { return err } b.batch.Put(k, v) return nil }
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 }
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 } }
// 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 }
// 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 }
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") } } }
// 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) }
// Delete implements KeyValueStore. func (l *LevelDB) Delete(key encoding.BinaryMarshaler) (bool, error) { k, err := key.MarshalBinary() if err != nil { return false, err } // Note that Delete returns nil if k does not exist. So we have to test // for existence with Has first. if has, err := l.storage.Has(k, l.readOpts); !has || err != nil { return false, err } if err = l.storage.Delete(k, l.writeOpts); err != nil { return false, err } return true, nil }
// 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) }
// sendPacket marshals p according to RFC 4234. func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error { bb, err := m.MarshalBinary() if err != nil { return errors.Wrap(err, "binary marshaller failed") } if debugDumpTxPacketBytes { debug("send packet: %s %d bytes %x", fxp(bb[0]), len(bb), bb[1:]) } else if debugDumpTxPacket { debug("send packet: %s %d bytes", fxp(bb[0]), len(bb)) } l := uint32(len(bb)) hdr := []byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)} _, err = w.Write(hdr) if err != nil { return err } _, err = w.Write(bb) return err }
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) { bs, fnerr := iv.MarshalBinary() f.e.marshal(bs, fnerr, false, c_RAW) }