Esempio n. 1
2
File: sender.go Progetto: h12w/kpax
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)
}
Esempio n. 2
1
func mustMarshal(v encoding.BinaryMarshaler) []byte {
	res, err := v.MarshalBinary()
	if err != nil {
		panic(err)
	}
	return res
}
Esempio n. 3
0
// 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)
}
Esempio n. 4
0
// 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
}
Esempio n. 5
0
func (enc *Encoder) encodeBinaryMarshaler(v encoding.BinaryMarshaler) error {
	b, err := v.MarshalBinary()
	if err != nil {
		return err
	}
	_, errr := enc.w.Write(b)
	return errr
}
Esempio n. 6
0
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)
	}
}
Esempio n. 7
0
// 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)
}
Esempio n. 8
0
// 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
}
Esempio n. 9
0
// 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
}
Esempio n. 10
0
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
}
Esempio n. 11
0
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
	}
}
Esempio n. 12
0
// 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
}
Esempio n. 13
0
// 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
}
Esempio n. 14
0
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")
		}
	}
}
Esempio n. 15
0
//  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)
}
Esempio n. 16
0
// 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
}
Esempio n. 17
0
// 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)
}
Esempio n. 18
0
// 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)
}