aboutsummaryrefslogtreecommitdiff
path: root/hotline/file_resume_data.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2025-07-06 16:02:53 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2025-07-06 16:02:53 -0700
commite61b3160bc8936b7ffb0af5c89b13742a7081826 (patch)
treedb3ba0e6cf0add99da6fa806709670d4b39d4bbf /hotline/file_resume_data.go
parentc0ec79dcfd267f7495274a9186b36a1b0669f000 (diff)
Add ForkType type alias for improved type safety
- Replace [4]byte with ForkType in ForkInfoList struct - Update constants ForkTypeDATA and ForkTypeMACR to use ForkType - Add String() method to ForkType for better debugging - Improve consistency with existing type patterns (FieldType, TranType) - Clean up unused code and improve documentation
Diffstat (limited to 'hotline/file_resume_data.go')
-rw-r--r--hotline/file_resume_data.go57
1 files changed, 24 insertions, 33 deletions
diff --git a/hotline/file_resume_data.go b/hotline/file_resume_data.go
index 5dfd2d8..80f5fe5 100644
--- a/hotline/file_resume_data.go
+++ b/hotline/file_resume_data.go
@@ -3,38 +3,54 @@ package hotline
import (
"bytes"
"encoding/binary"
+ "fmt"
)
// FileResumeData is sent when a client or server would like to resume a transfer from an offset
type FileResumeData struct {
Format [4]byte // "RFLT"
Version [2]byte // Always 1
- RSVD [34]byte // Unused
+ RSVD [34]byte // Present in the Hotline protocol docs, but unused. Left here for documentation purposes.
ForkCount [2]byte // Length of ForkInfoList. Either 2 or 3 depending on whether file has a resource fork
ForkInfoList []ForkInfoList
+}
+
+// ForkType represents a 4-byte fork type identifier
+type ForkType [4]byte
- //readOffset int // TODO
+// String returns a string representation of the fork type
+func (ft ForkType) String() string {
+ return fmt.Sprintf("%c%c%c%c", ft[0], ft[1], ft[2], ft[3])
}
type ForkInfoList struct {
- Fork [4]byte // "DATA" or "MACR"
- DataSize [4]byte // offset from which to resume the transfer of data
- RSVDA [4]byte // Unused
- RSVDB [4]byte // Unused
+ Fork ForkType // "DATA" or "MACR"
+ DataSize [4]byte // offset from which to resume the transfer of data
+ RSVDA [4]byte // Present in the Hotline protocol docs, but unused. Left here for documentation purposes.
+ RSVDB [4]byte // Present in the Hotline protocol docs, but unused. Left here for documentation purposes.
}
+var (
+ ForkTypeDATA = ForkType{0x44, 0x41, 0x54, 0x41} // DATA: Data fork
+ ForkTypeMACR = ForkType{0x4d, 0x41, 0x43, 0x52} // MACR: Mac resource fork
+)
+
func NewForkInfoList(b []byte) *ForkInfoList {
return &ForkInfoList{
- Fork: [4]byte{0x44, 0x41, 0x54, 0x41},
+ Fork: ForkTypeDATA,
DataSize: [4]byte{b[0], b[1], b[2], b[3]},
RSVDA: [4]byte{},
RSVDB: [4]byte{},
}
}
+var (
+ FormatRFLT = [4]byte{0x52, 0x46, 0x4C, 0x54} // File resume format: "RFLT" (?)
+)
+
func NewFileResumeData(list []ForkInfoList) *FileResumeData {
return &FileResumeData{
- Format: [4]byte{0x52, 0x46, 0x4C, 0x54}, // RFLT
+ Format: FormatRFLT,
Version: [2]byte{0, 1},
RSVD: [34]byte{},
ForkCount: [2]byte{0, uint8(len(list))},
@@ -42,31 +58,6 @@ func NewFileResumeData(list []ForkInfoList) *FileResumeData {
}
}
-//
-//func (frd *FileResumeData) Read(p []byte) (int, error) {
-// buf := slices.Concat(
-// frd.Format[:],
-// frd.Version[:],
-// frd.RSVD[:],
-// frd.ForkCount[:],
-// )
-// for _, fil := range frd.ForkInfoList {
-// buf = append(buf, fil...)
-// _ = binary.Write(&buf, binary.LittleEndian, fil)
-// }
-//
-// var buf bytes.Buffer
-// _ = binary.Write(&buf, binary.LittleEndian, frd.Format)
-// _ = binary.Write(&buf, binary.LittleEndian, frd.Version)
-// _ = binary.Write(&buf, binary.LittleEndian, frd.RSVD)
-// _ = binary.Write(&buf, binary.LittleEndian, frd.ForkCount)
-// for _, fil := range frd.ForkInfoList {
-// _ = binary.Write(&buf, binary.LittleEndian, fil)
-// }
-//
-// return buf.Bytes(), nil
-//}
-
func (frd *FileResumeData) BinaryMarshal() ([]byte, error) {
var buf bytes.Buffer
_ = binary.Write(&buf, binary.LittleEndian, frd.Format)