mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-05 00:47:51 -05:00
extract logic for write frame
This commit is contained in:
parent
ab1fe09c56
commit
de74460f15
@ -61,22 +61,26 @@ func (w *Writer) writeMetaOnly() error {
|
|||||||
return w.writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
|
return w.writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) writeData(mb buf.MultiBuffer) error {
|
func writeMetaWithFrame(writer buf.Writer, meta FrameMetadata, data buf.MultiBuffer) error {
|
||||||
meta := w.getNextFrameMeta()
|
|
||||||
meta.Option.Set(OptionData)
|
|
||||||
|
|
||||||
frame := buf.New()
|
frame := buf.New()
|
||||||
if err := meta.WriteTo(frame); err != nil {
|
if err := meta.WriteTo(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := frame.AppendSupplier(serial.WriteUint16(uint16(mb.Len()))); err != nil {
|
if err := frame.AppendSupplier(serial.WriteUint16(uint16(data.Len()))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
mb2 := buf.NewMultiBufferCap(int32(len(mb)) + 1)
|
mb2 := buf.NewMultiBufferCap(int32(len(data)) + 1)
|
||||||
mb2.Append(frame)
|
mb2.Append(frame)
|
||||||
mb2.AppendMulti(mb)
|
mb2.AppendMulti(data)
|
||||||
return w.writer.WriteMultiBuffer(mb2)
|
return writer.WriteMultiBuffer(mb2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) writeData(mb buf.MultiBuffer) error {
|
||||||
|
meta := w.getNextFrameMeta()
|
||||||
|
meta.Option.Set(OptionData)
|
||||||
|
|
||||||
|
return writeMetaWithFrame(w.writer, meta, mb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMultiBuffer implements buf.Writer.
|
// WriteMultiBuffer implements buf.Writer.
|
||||||
|
Loading…
Reference in New Issue
Block a user