@@ -119,25 +119,25 @@ public struct Msg
119
119
/// <summary>
120
120
/// Returns true if msg is empty
121
121
/// </summary>
122
- public bool IsEmpty => m_data == null || Size == 0 ;
122
+ public readonly bool IsEmpty => m_data == null || Size == 0 ;
123
123
124
124
/// <summary>
125
125
/// Returns true if the msg is join message
126
126
/// </summary>
127
- public bool IsJoin => MsgType == MsgType . Join ;
127
+ public readonly bool IsJoin => MsgType == MsgType . Join ;
128
128
129
129
/// <summary>
130
130
/// Returns true if the msg is leave message
131
131
/// </summary>
132
- public bool IsLeave => MsgType == MsgType . Leave ;
132
+ public readonly bool IsLeave => MsgType == MsgType . Leave ;
133
133
134
134
/// <summary>
135
135
/// Gets the position of the first element in the Data property delimited by the message,
136
136
/// relative to the start of the original array.
137
137
/// Deprecated: use <see cref="Slice()"/> or implicit casting to Span
138
138
/// </summary>
139
139
[ Obsolete ( "Use implicit casting to Span or Slice instead" ) ]
140
- public int Offset => m_offset ;
140
+ public readonly int Offset => m_offset ;
141
141
142
142
#region MsgType
143
143
@@ -149,14 +149,14 @@ public struct Msg
149
149
/// which would indicate that this message is intended for use simply to mark a boundary
150
150
/// between other parts of some unit of communication.
151
151
/// </summary>
152
- public bool IsDelimiter => MsgType == MsgType . Delimiter ;
152
+ public readonly bool IsDelimiter => MsgType == MsgType . Delimiter ;
153
153
154
154
/// <summary>Get whether this <see cref="Msg"/> is initialised and ready for use.</summary>
155
155
/// <remarks>A newly constructed <see cref="Msg"/> is uninitialised, and can be initialised via one
156
156
/// of <see cref="InitEmpty"/>, <see cref="InitDelimiter"/>, <see cref="InitGC(byte[],int)"/>, <see cref="InitGC(byte[],int,int)"/>, or <see cref="InitPool"/>.
157
157
/// Calling <see cref="Close"/> will cause the <see cref="Msg"/> to become uninitialised again.</remarks>
158
158
/// <returns><c>true</c> if the <see cref="Msg"/> is initialised, otherwise <c>false</c>.</returns>
159
- public bool IsInitialised => MsgType != MsgType . Uninitialised ;
159
+ public readonly bool IsInitialised => MsgType != MsgType . Uninitialised ;
160
160
161
161
#endregion
162
162
@@ -170,20 +170,20 @@ public struct Msg
170
170
/// <summary>
171
171
/// Get the "Has-More" flag, which when set on a message-queue frame indicates that there are more frames to follow.
172
172
/// </summary>
173
- public bool HasMore => ( Flags & MsgFlags . More ) == MsgFlags . More ;
173
+ public readonly bool HasMore => ( Flags & MsgFlags . More ) == MsgFlags . More ;
174
174
175
- internal bool HasCommand => ( Flags & MsgFlags . Command ) == MsgFlags . Command ;
175
+ internal readonly bool HasCommand => ( Flags & MsgFlags . Command ) == MsgFlags . Command ;
176
176
177
177
/// <summary>
178
178
/// Get whether the <see cref="Data"/> buffer of this <see cref="Msg"/> is shared with another instance.
179
179
/// Only applies to pooled message types.
180
180
/// </summary>
181
- public bool IsShared => ( Flags & MsgFlags . Shared ) != 0 ;
181
+ public readonly bool IsShared => ( Flags & MsgFlags . Shared ) != 0 ;
182
182
183
183
/// <summary>
184
184
/// Get whether the Identity bit is set on the Flags property.
185
185
/// </summary>
186
- public bool IsIdentity => ( Flags & MsgFlags . Identity ) != 0 ;
186
+ public readonly bool IsIdentity => ( Flags & MsgFlags . Identity ) != 0 ;
187
187
188
188
/// <summary>
189
189
/// Set the indicated Flags bits.
@@ -210,7 +210,7 @@ public void ResetFlags(MsgFlags flags)
210
210
/// </summary>
211
211
public uint RoutingId
212
212
{
213
- get => m_routingId ;
213
+ readonly get => m_routingId ;
214
214
set
215
215
{
216
216
if ( value == 0 )
@@ -233,7 +233,7 @@ internal void ResetRoutingId()
233
233
/// <exception cref="InvalidException">Value is larger than 255.</exception>
234
234
public string Group
235
235
{
236
- get => m_group ;
236
+ readonly get => m_group ;
237
237
set
238
238
{
239
239
if ( value . Length > MaxGroupLength )
@@ -252,13 +252,13 @@ public string Group
252
252
/// <see cref="NetMQ.MsgType.Empty"/> or <see cref="NetMQ.MsgType.Delimiter"/>.
253
253
/// </remarks>
254
254
[ Obsolete ( "Use implicit casting to Span or Slice instead" ) ]
255
- public byte [ ] ? Data => m_data ;
255
+ public readonly byte [ ] ? Data => m_data ;
256
256
257
257
/// <summary>
258
258
/// Return the internal buffer as Span
259
259
/// </summary>
260
260
/// <returns>The span</returns>
261
- public Span < byte > Slice ( )
261
+ public readonly Span < byte > Slice ( )
262
262
{
263
263
if ( m_data == null )
264
264
return Span < byte > . Empty ;
@@ -270,7 +270,7 @@ public Span<byte> Slice()
270
270
/// Return the internal buffer as Memory
271
271
/// </summary>
272
272
/// <returns>The memory</returns>
273
- public Memory < byte > SliceAsMemory ( )
273
+ public readonly Memory < byte > SliceAsMemory ( )
274
274
{
275
275
if ( m_data == null )
276
276
return Memory < byte > . Empty ;
@@ -282,7 +282,7 @@ public Memory<byte> SliceAsMemory()
282
282
/// Returns a slice of the internal buffer.
283
283
/// </summary>
284
284
/// <param name="offset">The offset to take the span from</param>
285
- public Span < byte > Slice ( int offset )
285
+ public readonly Span < byte > Slice ( int offset )
286
286
{
287
287
if ( m_data == null && offset > 0 )
288
288
throw new ArgumentOutOfRangeException ( nameof ( offset ) ) ;
@@ -298,7 +298,7 @@ public Span<byte> Slice(int offset)
298
298
/// </summary>
299
299
/// <param name="offset">The offset to take the span from</param>
300
300
/// <param name="count">The size of the slice</param>
301
- public Span < byte > Slice ( int offset , int count )
301
+ public readonly Span < byte > Slice ( int offset , int count )
302
302
{
303
303
if ( m_data == null && offset > 0 )
304
304
throw new ArgumentOutOfRangeException ( nameof ( offset ) ) ;
@@ -316,7 +316,7 @@ public Span<byte> Slice(int offset, int count)
316
316
/// Copy the content of the message into a Span
317
317
/// </summary>
318
318
/// <param name="span">The span to copy content to</param>
319
- public void CopyTo ( Span < byte > span )
319
+ public readonly void CopyTo ( Span < byte > span )
320
320
{
321
321
( ( Span < byte > ) this ) . CopyTo ( span ) ;
322
322
}
@@ -325,7 +325,7 @@ public void CopyTo(Span<byte> span)
325
325
/// Return a copy of the internal buffer as byte array
326
326
/// </summary>
327
327
/// <returns>Byte array</returns>
328
- public byte [ ] ToArray ( )
328
+ public readonly byte [ ] ToArray ( )
329
329
{
330
330
var data = new byte [ Size ] ;
331
331
@@ -357,7 +357,7 @@ public static implicit operator ReadOnlySpan<byte>(Msg msg)
357
357
/// Returns span enumerator, to iterate of the Msg
358
358
/// </summary>
359
359
/// <returns>Span Enumerator</returns>
360
- public Span < byte > . Enumerator GetEnumerator ( )
360
+ public readonly Span < byte > . Enumerator GetEnumerator ( )
361
361
{
362
362
return ( ( Span < byte > ) this ) . GetEnumerator ( ) ;
363
363
}
@@ -536,7 +536,7 @@ public void RemoveReferences(int amount)
536
536
/// Override the Object ToString method to show the object-type, and values of the MsgType, Size, and Flags properties.
537
537
/// </summary>
538
538
/// <returns>a string that provides some detail about this Msg's state</returns>
539
- public override string ToString ( )
539
+ public override readonly string ToString ( )
540
540
{
541
541
return base . ToString ( ) + "[" + MsgType + "," + Size + "," + Flags + "]" ;
542
542
}
@@ -546,7 +546,7 @@ public override string ToString()
546
546
/// </summary>
547
547
/// <param name="encoding">The encoding to use for the conversion</param>
548
548
/// <returns>The string</returns>
549
- public string GetString ( Encoding encoding )
549
+ public readonly string GetString ( Encoding encoding )
550
550
{
551
551
Assumes . NotNull ( m_data ) ;
552
552
return encoding . GetString ( m_data , m_offset , Size ) ;
@@ -559,7 +559,7 @@ public string GetString(Encoding encoding)
559
559
/// <param name="offset">Offset to start conversion from</param>
560
560
/// <param name="count">Number of bytes to convert</param>
561
561
/// <returns>The string</returns>
562
- public string GetString ( Encoding encoding , int offset , int count )
562
+ public readonly string GetString ( Encoding encoding , int offset , int count )
563
563
{
564
564
Assumes . NotNull ( m_data ) ;
565
565
return encoding . GetString ( m_data , m_offset + offset , count ) ;
@@ -571,7 +571,7 @@ public string GetString(Encoding encoding, int offset, int count)
571
571
/// <param name="src">the source byte-array to copy from</param>
572
572
/// <param name="dstOffset">index within the internal Data array to copy that byte to</param>
573
573
/// <param name="len">the number of bytes to copy</param>
574
- public void Put ( byte [ ] ? src , int dstOffset , int len )
574
+ public readonly void Put ( byte [ ] ? src , int dstOffset , int len )
575
575
{
576
576
if ( len == 0 || src == null )
577
577
return ;
@@ -586,7 +586,7 @@ public void Put(byte[]? src, int dstOffset, int len)
586
586
/// <param name="srcOffset">first byte in the source byte-array</param>
587
587
/// <param name="dstOffset">index within the internal Data array to copy that byte to</param>
588
588
/// <param name="len">the number of bytes to copy</param>
589
- public void Put ( byte [ ] ? src , int srcOffset , int dstOffset , int len ) {
589
+ public readonly void Put ( byte [ ] ? src , int srcOffset , int dstOffset , int len ) {
590
590
if ( len == 0 || src == null )
591
591
return ;
592
592
Assumes . NotNull ( m_data ) ;
@@ -597,7 +597,7 @@ public void Put(byte[]? src, int srcOffset, int dstOffset, int len) {
597
597
/// Copy the given single byte to this Msg's Data buffer.
598
598
/// </summary>
599
599
/// <param name="b">the source byte to copy from</param>
600
- public void Put ( byte b )
600
+ public readonly void Put ( byte b )
601
601
{
602
602
Assumes . NotNull ( m_data ) ;
603
603
m_data [ m_offset ] = b ;
@@ -608,7 +608,7 @@ public void Put(byte b)
608
608
/// </summary>
609
609
/// <param name="b">the source byte to copy from</param>
610
610
/// <param name="i">index within the internal Data array to copy that byte to</param>
611
- public void Put ( byte b , int i )
611
+ public readonly void Put ( byte b , int i )
612
612
{
613
613
Assumes . NotNull ( m_data ) ;
614
614
m_data [ m_offset + i ] = b ;
@@ -620,7 +620,7 @@ public void Put(byte b, int i)
620
620
/// <param name="encoding">The encoding to use for the writing</param>
621
621
/// <param name="str">The string to write</param>
622
622
/// <param name="index">The index to write the string to</param>
623
- public void Put ( Encoding encoding , string str , int index )
623
+ public readonly void Put ( Encoding encoding , string str , int index )
624
624
{
625
625
Assumes . NotNull ( m_data ) ;
626
626
encoding . GetBytes ( str , 0 , str . Length , m_data , m_offset + index ) ;
@@ -640,7 +640,7 @@ public void Put(Span<byte> src, int offset)
640
640
/// </summary>
641
641
/// <param name="index">The index to access</param>
642
642
/// <returns></returns>
643
- public byte this [ int index ]
643
+ public readonly byte this [ int index ]
644
644
{
645
645
get
646
646
{
@@ -727,7 +727,7 @@ public void Move(ref Msg src)
727
727
/// Returns a new array containing the first <see cref="Size"/> bytes of <see cref="Data"/>.
728
728
/// Deprecated: use <see cref="ToArray()"/>
729
729
/// </summary>
730
- public byte [ ] CloneData ( )
730
+ public readonly byte [ ] CloneData ( )
731
731
{
732
732
var data = new byte [ Size ] ;
733
733
@@ -757,8 +757,8 @@ internal byte[] UnsafeToArray()
757
757
return CloneData ( ) ;
758
758
}
759
759
760
- internal byte [ ] ? UnsafeData => m_data ;
761
- internal int UnsafeOffset => m_offset ;
760
+ internal readonly byte [ ] ? UnsafeData => m_data ;
761
+ internal readonly int UnsafeOffset => m_offset ;
762
762
763
763
#endregion
764
764
}
0 commit comments