Summary

Class:CBAM.NATS.Implementation.NATSPublishCompletedImpl
Assembly:CBAM.NATS.Implementation
File(s):/repo-dir/contents/Source/Code/CBAM.NATS.Implementation/Message.cs
Covered lines:0
Uncovered lines:3
Coverable lines:3
Total lines:101
Line coverage:0%

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor()100%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
 31      public NATSMessageImpl(
 32         String subject,
 33         Int64 subID,
 34         String replyTo,
 35         Byte[] data,
 36         Int32 dataLength
 37         )
 38      {
 39         this.Subject = ArgumentValidator.ValidateNotEmpty( nameof( subject ), subject );
 40         this.SubscriptionID = subID;
 41         this.ReplyTo = replyTo;
 42         this._data = data ?? Empty<Byte>.Array;
 43         this._dataLength = dataLength;
 44      }
 45
 46      public String Subject { get; }
 47
 48      public Int64 SubscriptionID { get; }
 49
 50      public String ReplyTo { get; }
 51
 52      public Int32 DataLength => this._data.Length;
 53
 54      public Int32 CopyDataTo( Byte[] array, Int32 offsetInMessage, Int32 offsetInArray, Int32 count )
 55      {
 56         if ( offsetInMessage < 0 )
 57         {
 58            offsetInMessage = 0;
 59         }
 60         else if ( offsetInMessage >= this._dataLength )
 61         {
 62            offsetInMessage = this._dataLength - 1;
 63         }
 64
 65         if ( count < 0 || count > this._dataLength - offsetInMessage )
 66         {
 67            count = this._dataLength - offsetInMessage;
 68         }
 69
 70         this._data.CopyTo( array, ref offsetInMessage, offsetInArray, count );
 71
 72         return count;
 73      }
 74
 75      public Byte GetSingleByteAt( Int32 offsetInMessage )
 76      {
 77         if ( offsetInMessage < 0 || offsetInMessage >= this._dataLength )
 78         {
 79            throw new ArgumentException( nameof( offsetInMessage ) );
 80         }
 81         return this._data[offsetInMessage];
 82      }
 83
 84      internal void SetData( Byte[] data, Int32 dataLength )
 85      {
 86         Interlocked.Exchange( ref this._data, data ?? Empty<Byte>.Array );
 87         Interlocked.Exchange( ref this._dataLength, dataLength );
 88      }
 89   }
 90
 91   internal sealed class NATSPublishCompletedImpl : NATSPublishCompleted
 92   {
 93
 094      public static NATSPublishCompleted Instance { get; } = new NATSPublishCompletedImpl();
 95
 096      private NATSPublishCompletedImpl()
 97      {
 98
 099      }
 100   }
 101}

Methods/Properties

Instance()
.ctor()