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