File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Thrift , TCompactProtocol , TBufferedTransport } from 'thrift'
2+
3+ export default abstract class Payload {
4+ /**
5+ * Write this payload into the specified stream
6+ */
7+ encode ( proto : TCompactProtocol ) : Promise < void > {
8+ return null
9+ }
10+
11+ /**
12+ * Decodes thrift buffer into this payload
13+ */
14+ decode ( data : Buffer ) : Promise < void > {
15+ return null
16+ }
17+
18+ /**
19+ * Get topic this payload should published to
20+ * Only single-level topics have been observed,
21+ * but mqtt works with multiple, possibly dynamically
22+ * generated topics.
23+ */
24+ getTopic ( ) : string {
25+ // Maybe thrown?
26+ return null
27+ }
28+
29+ /**
30+ * Static convenience method for writing a payload to a
31+ * buffered transport and returning it as a buffer
32+ */
33+ static encodePayload ( payload : Payload ) : Promise < Buffer > {
34+ return new Promise < Buffer > ( ( resolve , reject ) => {
35+ const trans = new TBufferedTransport ( null , ( msg , seqid ) => {
36+ resolve ( msg )
37+ } )
38+
39+ const proto = new TCompactProtocol ( trans )
40+ payload . encode ( proto )
41+
42+ proto . flush ( )
43+ } )
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ import Payload from './Payload'
2+
3+ export { Payload }
4+
5+ export const encodePayload = Payload . encodePayload
You can’t perform that action at this time.
0 commit comments