Пример #1
0
func (rsp *flowResponse) WriteTo(w *xio.PacketWriter) error {
	flags := rsp.f.flags
	if rsp.header {
		flags |= flagsHeader
	}
	if err := w.Write8(flags); err != nil {
		return err
	}
	if rsp.header {
		if err := w.Write7BitValue64(rsp.fw.fid); err != nil {
			return err
		}
		if err := w.Write7BitValue64(rsp.f.stage); err != nil {
			return err
		}
		if err := w.Write7BitValue64(rsp.f.delta); err != nil {
			return err
		}
		if len(rsp.fw.signature) != 0 {
			if err := w.WriteString8(rsp.fw.signature); err != nil {
				return err
			}
			if rsp.fr.fid != 0 {
				more := 1
				if add, err := xio.SizeOf7BitValue64(rsp.fr.fid); err != nil {
					return err
				} else {
					more += add
				}
				if err := w.Write7BitValue64(uint64(more)); err != nil {
					return err
				}
				if err := w.Write8(0x0a); err != nil {
					return err
				}
				if err := w.Write7BitValue64(rsp.fr.fid); err != nil {
					return err
				}
			}
		}
		if err := w.Write8(0); err != nil {
			return err
		}
	}
	if err := w.WriteBytes(rsp.f.data); err != nil {
		return err
	}
	return nil
}
Пример #2
0
func (rsp *helloResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write8(uint8(len(rsp.tag))); err != nil {
		return errors.New("hello.write tag.len")
	}
	if err := w.WriteBytes(rsp.tag); err != nil {
		return errors.New("hello.write tag")
	}
	if err := w.WriteString8(rsp.cookie); err != nil {
		return errors.New("hello.write value")
	}
	if err := w.WriteBytes(certificate); err != nil {
		return errors.New("hello.write certificate")
	}
	return nil
}