]> git.r.bdr.sh - rbdr/mobius/blob - hotline/field.go
Implement bufio.Scanner for transaction parsing
[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 fieldBannerType = 152
27 const fieldVersion = 160
28 const fieldCommunityBannerID = 161
29 const fieldServerName = 162
30 const fieldFileNameWithInfo = 200
31 const fieldFileName = 201
32 const fieldFilePath = 202
33 const fieldFileResumeData = 203
34 const fieldFileTransferOptions = 204
35 const fieldFileTypeString = 205
36 const fieldFileCreatorString = 206
37 const fieldFileSize = 207
38 const fieldFileCreateDate = 208
39 const fieldFileModifyDate = 209
40 const fieldFileComment = 210
41 const fieldFileNewName = 211
42 const fieldFileNewPath = 212
43 const fieldFileType = 213
44 const fieldQuotingMsg = 214
45 const fieldAutomaticResponse = 215
46 const fieldFolderItemCount = 220
47 const fieldUsernameWithInfo = 300
48 const fieldNewsArtListData = 321
49 const fieldNewsCatName = 322
50 const fieldNewsCatListData15 = 323
51 const fieldNewsPath = 325
52 const fieldNewsArtID = 326
53 const fieldNewsArtDataFlav = 327
54 const fieldNewsArtTitle = 328
55 const fieldNewsArtPoster = 329
56 const fieldNewsArtDate = 330
57 const fieldNewsArtPrevArt = 331
58 const fieldNewsArtNextArt = 332
59 const fieldNewsArtData = 333
60 const fieldNewsArtFlags = 334
61 const fieldNewsArtParentArt = 335
62 const fieldNewsArt1stChildArt = 336
63 const fieldNewsArtRecurseDel = 337
64
65 type Field struct {
66 ID []byte // Type of field
67 FieldSize []byte // Size of the data part
68 Data []byte // Actual field content
69 }
70
71 type requiredField struct {
72 ID int
73 minLen int
74 maxLen int
75 }
76
77 func NewField(id uint16, data []byte) Field {
78 idBytes := make([]byte, 2)
79 binary.BigEndian.PutUint16(idBytes, id)
80
81 bs := make([]byte, 2)
82 binary.BigEndian.PutUint16(bs, uint16(len(data)))
83
84 return Field{
85 ID: idBytes,
86 FieldSize: bs,
87 Data: data,
88 }
89 }
90
91 func (f Field) Payload() []byte {
92 return concat.Slices(f.ID, f.FieldSize, f.Data)
93 }
94
95 func getField(id int, fields *[]Field) *Field {
96 for _, field := range *fields {
97 if id == int(binary.BigEndian.Uint16(field.ID)) {
98 return &field
99 }
100 }
101 return nil
102 }