1
0
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:
Darien Raymond 2018-08-31 15:15:40 +02:00
parent ab1fe09c56
commit de74460f15
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -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.