]> git.r.bdr.sh - rbdr/mobius/blame - hotline/field.go
patch: v0.2.3
[rbdr/mobius] / hotline / field.go
CommitLineData
6988a057
JH
1package hotline
2
3import (
4 "encoding/binary"
5 "github.com/jhalter/mobius/concat"
6)
7
8const fieldError = 100
9const fieldData = 101
10const fieldUserName = 102
11const fieldUserID = 103
12const fieldUserIconID = 104
13const fieldUserLogin = 105
14const fieldUserPassword = 106
15const fieldRefNum = 107
16const fieldTransferSize = 108
17const fieldChatOptions = 109
18const fieldUserAccess = 110
aebc4d36
JH
19
20// const fieldUserAlias = 111 TODO: implement
6988a057
JH
21const fieldUserFlags = 112
22const fieldOptions = 113
23const fieldChatID = 114
24const fieldChatSubject = 115
25const fieldWaitingCount = 116
26const fieldVersion = 160
27const fieldCommunityBannerID = 161
28const fieldServerName = 162
29const fieldFileNameWithInfo = 200
30const fieldFileName = 201
31const fieldFilePath = 202
32const fieldFileTypeString = 205
33const fieldFileCreatorString = 206
34const fieldFileSize = 207
35const fieldFileCreateDate = 208
36const fieldFileModifyDate = 209
37const fieldFileComment = 210
38const fieldFileNewName = 211
39const fieldFileNewPath = 212
40const fieldFileType = 213
41const fieldQuotingMsg = 214 // Defined but unused in the Hotline Protocol spec
42const fieldAutomaticResponse = 215
43const fieldFolderItemCount = 220
44const fieldUsernameWithInfo = 300
45const fieldNewsArtListData = 321
46const fieldNewsCatName = 322
47const fieldNewsCatListData15 = 323
48const fieldNewsPath = 325
49const fieldNewsArtID = 326
50const fieldNewsArtDataFlav = 327
51const fieldNewsArtTitle = 328
52const fieldNewsArtPoster = 329
53const fieldNewsArtDate = 330
54const fieldNewsArtPrevArt = 331
55const fieldNewsArtNextArt = 332
56const fieldNewsArtData = 333
57const fieldNewsArtFlags = 334
58const fieldNewsArtParentArt = 335
59const fieldNewsArt1stChildArt = 336
60const fieldNewsArtRecurseDel = 337
61
62type Field struct {
63 ID []byte // Type of field
64 FieldSize []byte // Size of the data part
65 Data []byte // Actual field content
66}
67
68type requiredField struct {
69 ID int
70 minLen int
71 maxLen int
72}
73
74func NewField(id uint16, data []byte) Field {
75 idBytes := make([]byte, 2)
76 binary.BigEndian.PutUint16(idBytes, id)
77
78 bs := make([]byte, 2)
79 binary.BigEndian.PutUint16(bs, uint16(len(data)))
80
81 return Field{
82 ID: idBytes,
83 FieldSize: bs,
84 Data: data,
85 }
86}
87
88func (f Field) Payload() []byte {
89 return concat.Slices(f.ID, f.FieldSize, f.Data)
90}