Exemple #1
0
func putVarIntList(w io.Writer, x []uint64) {
	if _, err := encVarint.WriteVarInt(w, uint64(len(x))); err != nil {
		log.Println("putVarIntList lenght:", err.Error())

	}
	for _, v := range x {
		if _, err := encVarint.WriteVarInt(w, uint64(v)); err != nil {
			log.Println("putVarIntList:", err.Error())
		}
	}
}
Exemple #2
0
func writeMsg(w io.Writer, m msg) error {
	// TODO performance: pre-allocate byte slices, share between instances.
	buf := new(bytes.Buffer)
	putBytes(buf, m.PowNonce[:])
	putUint32(buf, uint32(m.Time)) // XXX moving to uint64 soon.
	encVarint.WriteVarInt(buf, m.StreamNumber)
	putBytes(buf, m.Encrypted)
	if _, err := w.Write(buf.Bytes()); err != nil {
		log.Println("writeMessage write failed: ", err)
	}
	return nil
}
Exemple #3
0
func writeInventoryVector(w io.Writer, invs []inventoryVector) (err error) {
	if len(invs) > maxInventoryEntries {
		return fmt.Errorf("Asked to write %d inventory vectors for getdata, but the maximum is %d. Ignoring.", len(invs), maxInventoryEntries)
	}
	buf := new(bytes.Buffer)
	encVarint.WriteVarInt(buf, uint64(len(invs)))
	if err = binary.Write(buf, binary.BigEndian, invs); err != nil {
		return err
	}
	_, err = w.Write(buf.Bytes())
	return err
}