100 lines
2.4 KiB
JavaScript
100 lines
2.4 KiB
JavaScript
import c from 'compact-encoding'
|
|
|
|
/** Read request: block index */
|
|
export const msgRead = {
|
|
encoding: c.uint32,
|
|
onmessage: null
|
|
}
|
|
|
|
/** Read response: index + data */
|
|
export const msgDataEncoding = {
|
|
preencode(state, m) {
|
|
c.uint32.preencode(state, m.index)
|
|
c.buffer.preencode(state, m.data)
|
|
},
|
|
encode(state, m) {
|
|
c.uint32.encode(state, m.index)
|
|
c.buffer.encode(state, m.data)
|
|
},
|
|
decode(state) {
|
|
return { index: c.uint32.decode(state), data: c.buffer.decode(state) }
|
|
}
|
|
}
|
|
|
|
export const msgSearchReqEncoding = {
|
|
preencode(state, m) {
|
|
c.uint32.preencode(state, m.id)
|
|
c.string.preencode(state, m.query)
|
|
},
|
|
encode(state, m) {
|
|
c.uint32.encode(state, m.id)
|
|
c.string.encode(state, m.query)
|
|
},
|
|
decode(state) {
|
|
return { id: c.uint32.decode(state), query: c.string.decode(state) }
|
|
}
|
|
}
|
|
|
|
export const msgSearchResEncoding = {
|
|
preencode(state, m) {
|
|
c.uint32.preencode(state, m.id)
|
|
c.array(c.string).preencode(state, m.matches)
|
|
},
|
|
encode(state, m) {
|
|
c.uint32.encode(state, m.id)
|
|
c.array(c.string).encode(state, m.matches)
|
|
},
|
|
decode(state) {
|
|
return {
|
|
id: c.uint32.decode(state),
|
|
matches: c.array(c.string).decode(state)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const msgRpcReqEncoding = {
|
|
preencode(state, m) {
|
|
c.uint32.preencode(state, m.id)
|
|
c.string.preencode(state, m.module)
|
|
c.string.preencode(state, m.method)
|
|
c.array(c.string).preencode(state, m.args)
|
|
},
|
|
encode(state, m) {
|
|
c.uint32.encode(state, m.id)
|
|
c.string.encode(state, m.module)
|
|
c.string.encode(state, m.method)
|
|
c.array(c.string).encode(state, m.args)
|
|
},
|
|
decode(state) {
|
|
return {
|
|
id: c.uint32.decode(state),
|
|
module: c.string.decode(state),
|
|
method: c.string.decode(state),
|
|
args: c.array(c.string).decode(state)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const msgRpcResEncoding = {
|
|
preencode(state, m) {
|
|
c.uint32.preencode(state, m.id)
|
|
c.bool.preencode(state, m.success)
|
|
c.string.preencode(state, m.result)
|
|
c.string.preencode(state, m.error)
|
|
},
|
|
encode(state, m) {
|
|
c.uint32.encode(state, m.id)
|
|
c.bool.encode(state, m.success)
|
|
c.string.encode(state, m.result || '')
|
|
c.string.encode(state, m.error || '')
|
|
},
|
|
decode(state) {
|
|
return {
|
|
id: c.uint32.decode(state),
|
|
success: c.bool.decode(state),
|
|
result: c.string.decode(state),
|
|
error: c.string.decode(state)
|
|
}
|
|
}
|
|
}
|