-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathseekers.js
123 lines (105 loc) · 3.95 KB
/
seekers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-FileCopyrightText: 2021 Anders Rune Jensen
//
// SPDX-License-Identifier: LGPL-3.0-only
const { allocAndEncode, seekKey2 } = require('bipf')
const BIPF_KEY = allocAndEncode('key')
const BIPF_AUTHOR = allocAndEncode('author')
const BIPF_CONTENT = allocAndEncode('content')
const BIPF_TYPE = allocAndEncode('type')
const BIPF_ROOT = allocAndEncode('root')
const BIPF_FORK = allocAndEncode('fork')
const BIPF_ABOUT = allocAndEncode('about')
const BIPF_BRANCH = allocAndEncode('branch')
const BIPF_VOTE = allocAndEncode('vote')
const BIPF_CONTACT = allocAndEncode('contact')
const BIPF_LINK = allocAndEncode('link')
const BIPF_META = allocAndEncode('meta')
const BIPF_PRIVATE = allocAndEncode('private')
const BIPF_ENCRYPTION_FORMAT = allocAndEncode('encryptionFormat')
const BIPF_CHANNEL = allocAndEncode('channel')
const BIPF_MENTIONS = allocAndEncode('mentions')
module.exports = {
seekAuthor(buffer, start, pValue) {
if (pValue < 0) return -1
return seekKey2(buffer, pValue, BIPF_AUTHOR, 0)
},
seekType(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_TYPE, 0)
},
seekRoot(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_ROOT, 0)
},
seekFork(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_FORK, 0)
},
seekBranch(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_BRANCH, 0)
},
seekContent(buffer, start, pValue) {
if (pValue < 0) return -1
return seekKey2(buffer, pValue, BIPF_CONTENT, 0)
},
seekVoteLink(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
const pValueContentVote = seekKey2(buffer, pValueContent, BIPF_VOTE, 0)
if (pValueContentVote < 0) return -1
return seekKey2(buffer, pValueContentVote, BIPF_LINK, 0)
},
seekContact(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_CONTACT, 0)
},
seekMentions(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_MENTIONS, 0)
},
seekAbout(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_ABOUT, 0)
},
pluckLink(buffer, start) {
return seekKey2(buffer, start, BIPF_LINK, 0)
},
seekMetaPrivate(buffer, start, pValue) {
const pMeta = seekKey2(buffer, 0, BIPF_META, 0)
if (pMeta < 0) return -1
return seekKey2(buffer, pMeta, BIPF_PRIVATE, 0)
},
seekMetaEncryptionFormat(buffer, start, pValue) {
const pMeta = seekKey2(buffer, 0, BIPF_META, 0)
if (pMeta < 0) return -1
return seekKey2(buffer, pMeta, BIPF_ENCRYPTION_FORMAT, 0)
},
seekMeta(buffer, start, pValue) {
return seekKey2(buffer, 0, BIPF_META, 0)
},
seekChannel(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, BIPF_CONTENT, 0)
if (pValueContent < 0) return -1
return seekKey2(buffer, pValueContent, BIPF_CHANNEL, 0)
},
seekKey(buffer, start, pValue) {
return seekKey2(buffer, 0, BIPF_KEY, 0)
},
}