@@ -200,60 +200,140 @@ 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
+ if ( IsContentTypePresent ( ) )
253
+ {
254
+ bitValue . SetBit ( ContentTypeBit ) ;
255
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentType ) ;
256
+ }
257
+
258
+ if ( IsContentEncodingPresent ( ) )
259
+ {
260
+ bitValue . SetBit ( ContentEncodingBit ) ;
261
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _contentEncoding ) ;
262
+ }
263
+
264
+ if ( IsHeadersPresent ( ) )
265
+ {
266
+ bitValue . SetBit ( HeaderBit ) ;
267
+ offset += WireFormatting . WriteTable ( ref span . GetOffset ( offset ) , _headers ) ;
268
+ }
269
+
270
+ if ( IsDeliveryModePresent ( ) )
271
+ {
272
+ bitValue . SetBit ( DeliveryModeBit ) ;
273
+ span . GetOffset ( offset ++ ) = _deliveryMode;
274
+ }
275
+
276
+ if ( IsPriorityPresent ( ) )
277
+ {
278
+ bitValue . SetBit ( PriorityBit ) ;
279
+ span . GetOffset ( offset ++ ) = _priority;
280
+ }
281
+
282
+ if ( IsCorrelationIdPresent ( ) )
283
+ {
284
+ bitValue . SetBit ( CorrelationIdBit ) ;
285
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _correlationId ) ;
286
+ }
287
+
288
+ if ( IsReplyToPresent ( ) )
289
+ {
290
+ bitValue . SetBit ( ReplyToBit ) ;
291
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _replyTo ) ;
292
+ }
293
+
294
+ if ( IsExpirationPresent ( ) )
295
+ {
296
+ bitValue . SetBit ( ExpirationBit ) ;
297
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _expiration ) ;
298
+ }
299
+
300
+ bitValue = ref span . GetOffset ( 1 ) ;
301
+ if ( IsMessageIdPresent ( ) )
302
+ {
303
+ bitValue . SetBit ( MessageIdBit ) ;
304
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _messageId ) ;
305
+ }
306
+
307
+ if ( IsTimestampPresent ( ) )
308
+ {
309
+ bitValue . SetBit ( TimestampBit ) ;
310
+ offset += WireFormatting . WriteTimestamp ( ref span . GetOffset ( offset ) , _timestamp ) ;
311
+ }
312
+
313
+ if ( IsTypePresent ( ) )
314
+ {
315
+ bitValue . SetBit ( TypeBit ) ;
316
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _type ) ;
317
+ }
318
+
319
+ if ( IsUserIdPresent ( ) )
320
+ {
321
+ bitValue . SetBit ( UserIdBit ) ;
322
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _userId ) ;
323
+ }
324
+
325
+ if ( IsAppIdPresent ( ) )
326
+ {
327
+ bitValue . SetBit ( AppIdBit ) ;
328
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _appId ) ;
329
+ }
330
+
331
+ if ( IsClusterIdPresent ( ) )
332
+ {
333
+ bitValue . SetBit ( ClusterIdBit ) ;
334
+ offset += WireFormatting . WriteShortstr ( ref span . GetOffset ( offset ) , _clusterId ) ;
335
+ }
336
+
257
337
return offset ;
258
338
}
259
339
0 commit comments