FILE / ScuroNeko/mtg

mtproto/rwc.go

Исходный файл и его история в репозитории.
FILE 2c387cc21344ec69f648661d635afb04ac70aa8e
Files
mtg/mtproto/rwc.go
T
2018-07-02 10:33:25 +03:00

49 lines
792 B
Go

package mtproto
import (
"bytes"
"io"
)
type BytesRWC interface {
Write(*bytes.Buffer) (int, error)
Read([]byte) (int, error)
Close() error
}
type StartBytesRWC struct {
conn BytesRWC
}
func (s *StartBytesRWC) Write(p []byte) (int, error) {
buf := GetBuffer()
buf.Write(p)
defer ReturnBuffer(buf)
return s.conn.Write(buf)
}
func (s *StartBytesRWC) Read(p []byte) (int, error) {
return s.conn.Read(p)
}
func (s *StartBytesRWC) Close() error {
return s.conn.Close()
}
type FinishBytesRWC struct {
conn io.ReadWriteCloser
}
func (f *FinishBytesRWC) Write(buf *bytes.Buffer) (int, error) {
return f.conn.Write(buf.Bytes())
}
func (f *FinishBytesRWC) Read(p []byte) (int, error) {
return f.conn.Read(p)
}
func (f *FinishBytesRWC) Close() error {
return f.conn.Close()
}