]> git.r.bdr.sh - rbdr/mobius/blob - hotline/transfer.go
Refactor and cleanup
[rbdr/mobius] / hotline / transfer.go
1 package hotline
2
3 import (
4 "bytes"
5 "encoding/binary"
6 "errors"
7 )
8
9 type transfer struct {
10 Protocol [4]byte // "HTXF" 0x48545846
11 ReferenceNumber [4]byte // Unique ID generated for the transfer
12 DataSize [4]byte // File size
13 RSVD [4]byte // Not implemented in Hotline Protocol
14 }
15
16 var HTXF = [4]byte{0x48, 0x54, 0x58, 0x46} // (HTXF) is the only supported transfer protocol
17
18 func (tf *transfer) Write(b []byte) (int, error) {
19 if err := binary.Read(bytes.NewReader(b), binary.BigEndian, tf); err != nil {
20 return 0, err
21 }
22
23 if tf.Protocol != HTXF {
24 return 0, errors.New("invalid protocol")
25 }
26
27 return len(b), nil
28 }