Summary

Class:CBAM.NATS.Implementation.NATSMessageImpl
Assembly:CBAM.NATS.Implementation
File(s):/repo-dir/contents/Source/Code/CBAM.NATS.Implementation/Message.cs
Covered lines:22
Uncovered lines:10
Coverable lines:32
Total lines:101
Line coverage:68.7%
Branch coverage:43.7%

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)201%1%
CopyDataTo(...)800.667%0.625%
GetSingleByteAt(...)400%0%
SetData(...)200%0%

File(s)

/repo-dir/contents/Source/Code/CBAM.NATS.Implementation/Message.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using System;
 19using System.Collections.Generic;
 20using System.Text;
 21using System.Threading;
 22using UtilPack;
 23
 24namespace CBAM.NATS.Implementation
 25{
 26   internal sealed class NATSMessageImpl : NATSMessage
 27   {
 28      private Byte[] _data;
 29      private Int32 _dataLength;
 30
 531      public NATSMessageImpl(
 532         String subject,
 533         Int64 subID,
 534         String replyTo,
 535         Byte[] data,
 536         Int32 dataLength
 537         )
 38      {
 539         this.Subject = ArgumentValidator.ValidateNotEmpty( nameof( subject ), subject );
 540         this.SubscriptionID = subID;
 541         this.ReplyTo = replyTo;
 542         this._data = data ?? Empty<Byte>.Array;
 543         this._dataLength = dataLength;
 544      }
 45
 246      public String Subject { get; }
 47
 048      public Int64 SubscriptionID { get; }
 49
 150      public String ReplyTo { get; }
 51
 452      public Int32 DataLength => this._data.Length;
 53
 54      public Int32 CopyDataTo( Byte[] array, Int32 offsetInMessage, Int32 offsetInArray, Int32 count )
 55      {
 256         if ( offsetInMessage < 0 )
 57         {
 058            offsetInMessage = 0;
 059         }
 260         else if ( offsetInMessage >= this._dataLength )
 61         {
 062            offsetInMessage = this._dataLength - 1;
 63         }
 64
 265         if ( count < 0 || count > this._dataLength - offsetInMessage )
 66         {
 267            count = this._dataLength - offsetInMessage;
 68         }
 69
 270         this._data.CopyTo( array, ref offsetInMessage, offsetInArray, count );
 71
 272         return count;
 73      }
 74
 75      public Byte GetSingleByteAt( Int32 offsetInMessage )
 76      {
 077         if ( offsetInMessage < 0 || offsetInMessage >= this._dataLength )
 78         {
 079            throw new ArgumentException( nameof( offsetInMessage ) );
 80         }
 081         return this._data[offsetInMessage];
 82      }
 83
 84      internal void SetData( Byte[] data, Int32 dataLength )
 85      {
 086         Interlocked.Exchange( ref this._data, data ?? Empty<Byte>.Array );
 087         Interlocked.Exchange( ref this._dataLength, dataLength );
 088      }
 89   }
 90
 91   internal sealed class NATSPublishCompletedImpl : NATSPublishCompleted
 92   {
 93
 94      public static NATSPublishCompleted Instance { get; } = new NATSPublishCompletedImpl();
 95
 96      private NATSPublishCompletedImpl()
 97      {
 98
 99      }
 100   }
 101}