@@ -28,6 +28,7 @@ const bigEndian = uInt8Float64Array[7] === 0
28
28
class Encoder {
29
29
constructor ( limit = SOFT_LIMIT ) {
30
30
this . _limit = limit
31
+ this . _metadataBytes = new Chunk ( 1024 )
31
32
this . _eventBytes = new Chunk ( )
32
33
this . _stringBytes = new Chunk ( )
33
34
this . _client = new Client ( )
@@ -117,19 +118,21 @@ class Encoder {
117
118
}
118
119
119
120
makePayload ( ) {
120
- const eventSize = this . _eventBytes . length + 5
121
- const serviceLength = Buffer . byteLength ( service )
122
- const buffer = Buffer . allocUnsafe ( eventSize + 18 + serviceLength )
121
+ this . _encodeMap ( this . _metadataBytes , { service } ) // HACK
122
+
123
+ const metadataBytes = this . _metadataBytes
124
+ const metadataSize = metadataBytes . length + 9
125
+ const eventSize = this . _eventBytes . length + 5 + 7
126
+ const buffer = Buffer . allocUnsafe ( 1 + metadataSize + eventSize )
123
127
124
128
let offset = 0
125
129
126
130
buffer [ offset ++ ] = 0x82 // fixmap(2)
127
131
128
- buffer [ offset ++ ] = 0xa7 // fixstr(7)
129
- offset += buffer . write ( 'service' , offset )
130
- buffer [ offset ++ ] = 0xd9 // str8
131
- buffer [ offset ++ ] = serviceLength
132
- offset += buffer . write ( service , offset )
132
+ buffer [ offset ++ ] = 0xa8 // fixstr(8)
133
+ offset += buffer . write ( 'metadata' , offset )
134
+ offset += metadataBytes . buffer . copy ( buffer , offset , 0 , metadataBytes . length )
135
+
133
136
buffer [ offset ++ ] = 0xa6 // fixstr(6)
134
137
offset += buffer . write ( 'events' , offset )
135
138
offset = this . _writeEvents ( buffer , offset )
@@ -167,6 +170,7 @@ class Encoder {
167
170
}
168
171
169
172
_reset ( ) {
173
+ this . _metadataBytes . length = 0
170
174
this . _eventCount = 0
171
175
this . _eventBytes . length = 0
172
176
this . _stringCount = 0
0 commit comments