This repository has been archived on 2022-09-10. You can view files and clone it, but cannot push or open issues or pull requests.
tunnel/dataframe.go

39 lines
630 B
Go
Raw Normal View History

2022-09-09 06:05:20 +00:00
package tunnel
import (
"compress/gzip"
"encoding/gob"
"io"
)
type DataFrame struct {
ID ID
Type Type
Payload []byte
}
func (d *DataFrame) Encode(w io.Writer) error {
gz := gzip.NewWriter(w)
defer gz.Close()
gob := gob.NewEncoder(gz)
return gob.Encode(d)
}
func (d *DataFrame) Decode(r io.Reader) error {
gz, err := gzip.NewReader(r)
if err != nil {
return err
}
defer gz.Close()
gob := gob.NewDecoder(gz)
return gob.Decode(d)
}
func (d *DataFrame) Read(p []byte) (int, error) {
return copy(p, d.Payload), nil
}
func (d *DataFrame) Write(p []byte) (int, error) {
return copy(d.Payload, p), nil
}