// Encode encodes the hop payload into the passed writer.
Encode encodes the hop payload into the passed writer.
// Encode encodes the hop payload into the passed writer .
func (hp *HopPayload) Encode(w io.Writer) error {
	switch hp.Type {
	case PayloadLegacy:
		break
	case PayloadTLV:
		var b [8]byte
		err := WriteVarInt(w, uint64(len(hp.Payload)), &b)
		if err != nil {
			return err
		}
	}
	if _, err := w.Write(hp.Payload); err != nil {
		return err
	}
	if _, err := w.Write(hp.HMAC[:]); err != nil {
		return err
	}
	return nil
}
func ( hp * HopPayload ) Encode ( w io . Writer ) error { switch hp . Type { case PayloadLegacy : break case PayloadTLV : var b [ 8 ] byte err := WriteVarInt ( w , uint64 ( len ( hp . Payload ) ) , & b ) if err != nil { return err } } if _ , err := w . Write ( hp . Payload ) ; err != nil { return err } if _ , err := w . Write ( hp . HMAC [ : ] ) ; err != nil { return err } return nil }
Encode encodes the hop payload into the passed writer.
Encode encodes the hop payload into the passed writer .
// For the legacy payload, we don't need to add any additional bytes as // our realm byte serves as our zero prefix byte. // For the TLV payload, we'll first prepend the length of the payload // as a var-int. // Finally, we'll write out the raw payload, then the HMAC in series.