Closed nichoth closed 2 years ago
See the tests :)
It needs to be a function.
This should be in the README. If not, a PR to make it more clear would be appreciated :)
Actually, absent() is explained in the README already. See previous definitions of the seek
argument in the README, a bit above the description of absent()
So, looking at #191 -- it's not clear to me what these example values are used for. And what does the seekChannel
function do here?
const B_VALUE = Buffer.from('value')
const B_CHANNEL = Buffer.from('channel')
const B_CONTENT = Buffer.from('content')
function seekChannel (buffer) {
var p = 0 // note you pass in p!
p = bipf.seekKey(buffer, p, B_VALUE)
if (~p) {
p = bipf.seekKey(buffer, p, B_CONTENT)
if (~p) return bipf.seekKey(buffer, p, B_CHANNEL)
}
}
This is assuming a standard message format --
{
key: '%1HbhmsEc4OCiLD5o8raRl+x8QUO7Y6oZ3C57vwNM78c=.sha256',
value: {
previous: '%CCceib4KRShqtaN95hPGl0qORtefsTEb/qwbB0YZVyQ=.sha256',
sequence: 3,
author: '@lV5MISER9oGaZJ7OLhlsUNVWHu982USYgMEWfIs6le0=.ed25519',
timestamp: 1638820387617,
hash: 'sha256',
content: { type: 'post', text: 'three' },
signature: 'E2sC6mH9F+HhfIVl6MjobLdZX6RG3QRwFBiMoT5vb64L6XkS5TutPh2gYRRIqKZSzzW5ld0sLvvEc81pcrRtCQ==.sig.ed25519'
},
timestamp: 1638820387618
}
As an example, lets say you are looking for messages that are not replies to other messages, so messages without a root
property in the JSON
What are you trying to do here? It seems like you are looking for isRoot. Why not just use that? Also absent is very special is means as the name implies that the value is absent, not even undefined.
It seems like you are looking for
isRoot
.
Thanks for that; i didn't know about that one.
absent is very special is means as the name implies that the value is absent, not even undefined.
That's interesting; I didn't know that you could detect a difference between undefined
vs not existing.
This is part of this sbot -- https://github.com/planetary-social/planetary-pub/blob/7ea9eb2fd3b021f1f862eaea9b0349a5fb0c2d97/viewer.js#L133
What is the type of value does
absent
take?