mirror of
https://github.com/jpillora/chisel
synced 2026-06-08 15:07:02 +00:00
28 lines
500 B
Go
28 lines
500 B
Go
package chisel
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"net"
|
|
)
|
|
|
|
//simple protocol [2 bytes of size, size bytes of data]
|
|
|
|
//TODO add length and error checks
|
|
func SizeRead(c net.Conn) []byte {
|
|
sizeb := make([]byte, 2)
|
|
c.Read(sizeb)
|
|
size := binary.BigEndian.Uint16(sizeb)
|
|
datab := make([]byte, size)
|
|
c.Read(datab)
|
|
return datab
|
|
}
|
|
|
|
func SizeWrite(c net.Conn, data []byte) {
|
|
size := len(data)
|
|
sizeb := make([]byte, 2)
|
|
binary.BigEndian.PutUint16(sizeb, uint16(size))
|
|
c.Write(sizeb)
|
|
c.Write(data)
|
|
return
|
|
}
|