@@ -200,60 +200,142 @@ public BasicProperties()
200
200
201
201
public BasicProperties ( ReadOnlySpan < byte > span )
202
202
{
203
- int offset = WireFormatting . ReadBits ( span ,
204
- out bool contentType_present ,
205
- out bool contentEncoding_present ,
206
- out bool headers_present ,
207
- out bool deliveryMode_present ,
208
- out bool priority_present ,
209
- out bool correlationId_present ,
210
- out bool replyTo_present ,
211
- out bool expiration_present ,
212
- out bool messageId_present ,
213
- out bool timestamp_present ,
214
- out bool type_present ,
215
- out bool userId_present ,
216
- out bool appId_present ,
217
- out bool clusterId_present ) ;
218
- if ( contentType_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _contentType ) ; }
219
- if ( contentEncoding_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _contentEncoding ) ; }
220
- if ( headers_present ) { offset += WireFormatting . ReadDictionary ( span . Slice ( offset ) , out var tmpDirectory ) ; _headers = tmpDirectory ; }
221
- if ( deliveryMode_present ) { _deliveryMode = span [ offset ++ ] ; }
222
- if ( priority_present ) { _priority = span [ offset ++ ] ; }
223
- if ( correlationId_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _correlationId ) ; }
224
- if ( replyTo_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _replyTo ) ; }
225
- if ( expiration_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _expiration ) ; }
226
- if ( messageId_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _messageId ) ; }
227
- if ( timestamp_present ) { offset += WireFormatting . ReadTimestamp ( span . Slice ( offset ) , out _timestamp ) ; }
228
- if ( type_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _type ) ; }
229
- if ( userId_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _userId ) ; }
230
- if ( appId_present ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _appId ) ; }
231
- if ( clusterId_present ) { WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _clusterId ) ; }
203
+ int offset = 2 ;
204
+ ref readonly byte bits = ref span [ 0 ] ;
205
+ if ( bits . IsBitSet ( ContentTypeBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _contentType ) ; }
206
+ if ( bits . IsBitSet ( ContentEncodingBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _contentEncoding ) ; }
207
+ if ( bits . IsBitSet ( HeaderBit ) ) { offset += WireFormatting . ReadDictionary ( span . Slice ( offset ) , out var tmpDirectory ) ; _headers = tmpDirectory ; }
208
+ if ( bits . IsBitSet ( DeliveryModeBit ) ) { _deliveryMode = span [ offset ++ ] ; }
209
+ if ( bits . IsBitSet ( PriorityBit ) ) { _priority = span [ offset ++ ] ; }
210
+ if ( bits . IsBitSet ( CorrelationIdBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _correlationId ) ; }
211
+ if ( bits . IsBitSet ( ReplyToBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _replyTo ) ; }
212
+ if ( bits . IsBitSet ( ExpirationBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _expiration ) ; }
213
+
214
+ bits = ref span [ 1 ] ;
215
+ if ( bits . IsBitSet ( MessageIdBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _messageId ) ; }
216
+ if ( bits . IsBitSet ( TimestampBit ) ) { offset += WireFormatting . ReadTimestamp ( span . Slice ( offset ) , out _timestamp ) ; }
217
+ if ( bits . IsBitSet ( TypeBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _type ) ; }
218
+ if ( bits . IsBitSet ( UserIdBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _userId ) ; }
219
+ if ( bits . IsBitSet ( AppIdBit ) ) { offset += WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _appId ) ; }
220
+ if ( bits . IsBitSet ( ClusterIdBit ) ) { WireFormatting . ReadShortstr ( span . Slice ( offset ) , out _clusterId ) ; }
232
221
}
233
222
234
223
public override ushort ProtocolClassId => 60 ;
235
224
public override string ProtocolClassName => "basic" ;
236
225
226
+ //----------------------------------
227
+ // First byte
228
+ //----------------------------------
229
+ private const byte ContentTypeBit = 7 ;
230
+ private const byte ContentEncodingBit = 6 ;
231
+ private const byte HeaderBit = 5 ;
232
+ private const byte DeliveryModeBit = 4 ;
233
+ private const byte PriorityBit = 3 ;
234
+ private const byte CorrelationIdBit = 2 ;
235
+ private const byte ReplyToBit = 1 ;
236
+ private const byte ExpirationBit = 0 ;
237
+
238
+ //----------------------------------
239
+ // Second byte
240
+ //----------------------------------
241
+ private const byte MessageIdBit = 7 ;
242
+ private const byte TimestampBit = 6 ;
243
+ private const byte TypeBit = 5 ;
244
+ private const byte UserIdBit = 4 ;
245
+ private const byte AppIdBit = 3 ;
246
+ private const byte ClusterIdBit = 2 ;
247
+
237
248
internal override int WritePropertiesTo ( Span < byte > span )
238
249
{
239
- int offset = WireFormatting . WriteBits ( ref span . GetStart ( ) ,
240
- IsContentTypePresent ( ) , IsContentEncodingPresent ( ) , IsHeadersPresent ( ) , IsDeliveryModePresent ( ) , IsPriorityPresent ( ) ,
241
- IsCorrelationIdPresent ( ) , IsReplyToPresent ( ) , IsExpirationPresent ( ) , IsMessageIdPresent ( ) , IsTimestampPresent ( ) ,
242
- IsTypePresent ( ) , IsUserIdPresent ( ) , IsAppIdPresent ( ) , IsClusterIdPresent ( ) ) ;
243
- if ( IsContentTypePresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentType ) ; }
244
- if ( IsContentEncodingPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentEncoding ) ; }
245
- if ( IsHeadersPresent ( ) ) { offset += WireFormatting . WriteTable ( ref span . GetOffset ( offset ) , _headers ) ; }
246
- if ( IsDeliveryModePresent ( ) ) { span [ offset ++ ] = _deliveryMode ; }
247
- if ( IsPriorityPresent ( ) ) { span [ offset ++ ] = _priority ; }
248
- if ( IsCorrelationIdPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _correlationId ) ; }
249
- if ( IsReplyToPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _replyTo ) ; }
250
- if ( IsExpirationPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _expiration ) ; }
251
- if ( IsMessageIdPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _messageId ) ; }
252
- if ( IsTimestampPresent ( ) ) { offset += WireFormatting . WriteTimestamp ( ref span . GetOffset ( offset ) , _timestamp ) ; }
253
- if ( IsTypePresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _type ) ; }
254
- if ( IsUserIdPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _userId ) ; }
255
- if ( IsAppIdPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _appId ) ; }
256
- if ( IsClusterIdPresent ( ) ) { offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _clusterId ) ; }
250
+ int offset = 2 ;
251
+ ref byte bitValue = ref span . GetStart ( ) ;
252
+ bitValue = 0 ;
253
+ if ( IsContentTypePresent ( ) )
254
+ {
255
+ bitValue . SetBit ( ContentTypeBit ) ;
256
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentType ) ;
257
+ }
258
+
259
+ if ( IsContentEncodingPresent ( ) )
260
+ {
261
+ bitValue . SetBit ( ContentEncodingBit ) ;
262
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentEncoding ) ;
263
+ }
264
+
265
+ if ( IsHeadersPresent ( ) )
266
+ {
267
+ bitValue . SetBit ( HeaderBit ) ;
268
+ offset += WireFormatting . WriteTable ( ref span . GetOffset ( offset ) , _headers ) ;
269
+ }
270
+
271
+ if ( IsDeliveryModePresent ( ) )
272
+ {
273
+ bitValue . SetBit ( DeliveryModeBit ) ;
274
+ span . GetOffset ( offset ++ ) = _deliveryMode;
275
+ }
276
+
277
+ if ( IsPriorityPresent ( ) )
278
+ {
279
+ bitValue . SetBit ( PriorityBit ) ;
280
+ span . GetOffset ( offset ++ ) = _priority;
281
+ }
282
+
283
+ if ( IsCorrelationIdPresent ( ) )
284
+ {
285
+ bitValue . SetBit ( CorrelationIdBit ) ;
286
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _correlationId ) ;
287
+ }
288
+
289
+ if ( IsReplyToPresent ( ) )
290
+ {
291
+ bitValue . SetBit ( ReplyToBit ) ;
292
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _replyTo ) ;
293
+ }
294
+
295
+ if ( IsExpirationPresent ( ) )
296
+ {
297
+ bitValue . SetBit ( ExpirationBit ) ;
298
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _expiration ) ;
299
+ }
300
+
301
+ bitValue = ref span . GetOffset ( 1 ) ;
302
+ bitValue = 0 ;
303
+ if ( IsMessageIdPresent ( ) )
304
+ {
305
+ bitValue . SetBit ( MessageIdBit ) ;
306
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _messageId ) ;
307
+ }
308
+
309
+ if ( IsTimestampPresent ( ) )
310
+ {
311
+ bitValue . SetBit ( TimestampBit ) ;
312
+ offset += WireFormatting . WriteTimestamp ( ref span . GetOffset ( offset ) , _timestamp ) ;
313
+ }
314
+
315
+ if ( IsTypePresent ( ) )
316
+ {
317
+ bitValue . SetBit ( TypeBit ) ;
318
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _type ) ;
319
+ }
320
+
321
+ if ( IsUserIdPresent ( ) )
322
+ {
323
+ bitValue . SetBit ( UserIdBit ) ;
324
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _userId ) ;
325
+ }
326
+
327
+ if ( IsAppIdPresent ( ) )
328
+ {
329
+ bitValue . SetBit ( AppIdBit ) ;
330
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _appId ) ;
331
+ }
332
+
333
+ if ( IsClusterIdPresent ( ) )
334
+ {
335
+ bitValue . SetBit ( ClusterIdBit ) ;
336
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _clusterId ) ;
337
+ }
338
+
257
339
return offset ;
258
340
}
259
341
0 commit comments