-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce struct version of BasicProperties for basicPublish
- Loading branch information
Showing
104 changed files
with
1,025 additions
and
1,487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
// This source code is dual-licensed under the Apache License, version | ||
// 2.0, and the Mozilla Public License, version 2.0. | ||
// | ||
// The APL v2.0: | ||
// | ||
//--------------------------------------------------------------------------- | ||
// Copyright (c) 2007-2020 VMware, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//--------------------------------------------------------------------------- | ||
// | ||
// The MPL v2.0: | ||
// | ||
//--------------------------------------------------------------------------- | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved. | ||
//--------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using RabbitMQ.Client.Framing.Impl; | ||
using RabbitMQ.Client.Impl; | ||
|
||
namespace RabbitMQ.Client | ||
{ | ||
#nullable enable | ||
/// <summary> | ||
/// AMQP specification content header properties for content class "basic". | ||
/// </summary> | ||
public struct BasicProperties : IBasicProperties, IAmqpHeader | ||
{ | ||
public string? ContentType { get; set; } | ||
public string? ContentEncoding { get; set; } | ||
public IDictionary<string, object?>? Headers { get; set; } | ||
public byte DeliveryMode { get; set; } | ||
public byte Priority { get; set; } | ||
public string? CorrelationId { get; set; } | ||
public string? ReplyTo { get; set; } | ||
public string? Expiration { get; set; } | ||
public string? MessageId { get; set; } | ||
public AmqpTimestamp Timestamp { get; set; } | ||
public string? Type { get; set; } | ||
public string? UserId { get; set; } | ||
public string? AppId { get; set; } | ||
public string? ClusterId { get; set; } | ||
|
||
public bool Persistent | ||
{ | ||
readonly get { return DeliveryMode == 2; } | ||
set { DeliveryMode = value ? (byte)2 : (byte)1; } | ||
} | ||
|
||
public PublicationAddress? ReplyToAddress | ||
{ | ||
readonly get | ||
{ | ||
PublicationAddress.TryParse(ReplyTo, out PublicationAddress result); | ||
return result; | ||
} | ||
set { ReplyTo = value?.ToString(); } | ||
} | ||
|
||
public BasicProperties(in ReadOnlyBasicProperties input) | ||
{ | ||
ContentType = input.ContentType; | ||
ContentEncoding = input.ContentEncoding; | ||
Headers = input.Headers; | ||
DeliveryMode = input.DeliveryMode; | ||
Priority = input.Priority; | ||
CorrelationId = input.CorrelationId; | ||
ReplyTo = input.ReplyTo; | ||
Expiration = input.Expiration; | ||
MessageId = input.MessageId; | ||
Timestamp = input.Timestamp; | ||
Type = input.Type; | ||
UserId = input.UserId; | ||
AppId = input.AppId; | ||
ClusterId = input.ClusterId; | ||
} | ||
|
||
public void ClearContentType() => ContentType = default; | ||
public void ClearContentEncoding() => ContentEncoding = default; | ||
public void ClearHeaders() => Headers = default; | ||
public void ClearDeliveryMode() => DeliveryMode = default; | ||
public void ClearPriority() => Priority = default; | ||
public void ClearCorrelationId() => CorrelationId = default; | ||
public void ClearReplyTo() => ReplyTo = default; | ||
public void ClearExpiration() => Expiration = default; | ||
public void ClearMessageId() => MessageId = default; | ||
public void ClearTimestamp() => Timestamp = default; | ||
public void ClearType() => Type = default; | ||
public void ClearUserId() => UserId = default; | ||
public void ClearAppId() => AppId = default; | ||
public void ClearClusterId() => ClusterId = default; | ||
|
||
public readonly bool IsContentTypePresent() => ContentType != default; | ||
public readonly bool IsContentEncodingPresent() => ContentEncoding != default; | ||
public readonly bool IsHeadersPresent() => Headers != default; | ||
public readonly bool IsDeliveryModePresent() => DeliveryMode != default; | ||
public readonly bool IsPriorityPresent() => Priority != default; | ||
public readonly bool IsCorrelationIdPresent() => CorrelationId != default; | ||
public readonly bool IsReplyToPresent() => ReplyTo != default; | ||
public readonly bool IsExpirationPresent() => Expiration != default; | ||
public readonly bool IsMessageIdPresent() => MessageId != default; | ||
public readonly bool IsTimestampPresent() => Timestamp != default; | ||
public readonly bool IsTypePresent() => Type != default; | ||
public readonly bool IsUserIdPresent() => UserId != default; | ||
public readonly bool IsAppIdPresent() => AppId != default; | ||
public readonly bool IsClusterIdPresent() => ClusterId != default; | ||
|
||
ushort IAmqpHeader.ProtocolClassId => ClassConstants.Basic; | ||
|
||
readonly int IAmqpWriteable.WriteTo(Span<byte> span) | ||
{ | ||
int offset = WireFormatting.WriteBits(ref span.GetStart(), | ||
IsContentTypePresent(), IsContentEncodingPresent(), IsHeadersPresent(), IsDeliveryModePresent(), IsPriorityPresent(), | ||
IsCorrelationIdPresent(), IsReplyToPresent(), IsExpirationPresent(), IsMessageIdPresent(), IsTimestampPresent(), | ||
IsTypePresent(), IsUserIdPresent(), IsAppIdPresent(), IsClusterIdPresent()); | ||
if (IsContentTypePresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), ContentType); } | ||
if (IsContentEncodingPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), ContentEncoding); } | ||
if (IsHeadersPresent()) { offset += WireFormatting.WriteTable(ref span.GetOffset(offset), Headers); } | ||
if (IsDeliveryModePresent()) { span[offset++] = DeliveryMode; } | ||
if (IsPriorityPresent()) { span[offset++] = Priority; } | ||
if (IsCorrelationIdPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), CorrelationId); } | ||
if (IsReplyToPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), ReplyTo); } | ||
if (IsExpirationPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), Expiration); } | ||
if (IsMessageIdPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), MessageId); } | ||
if (IsTimestampPresent()) { offset += WireFormatting.WriteTimestamp(ref span.GetOffset(offset), Timestamp); } | ||
if (IsTypePresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), Type); } | ||
if (IsUserIdPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), UserId); } | ||
if (IsAppIdPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), AppId); } | ||
if (IsClusterIdPresent()) { offset += WireFormatting.WriteShortstr(ref span.GetOffset(offset), ClusterId); } | ||
return offset; | ||
} | ||
|
||
readonly int IAmqpWriteable.GetRequiredBufferSize() | ||
{ | ||
int bufferSize = 2; // number of presence fields (14) in 2 bytes blocks | ||
if (IsContentTypePresent()) { bufferSize += 1 + WireFormatting.GetByteCount(ContentType); } // _contentType in bytes | ||
if (IsContentEncodingPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(ContentEncoding); } // _contentEncoding in bytes | ||
if (IsHeadersPresent()) { bufferSize += WireFormatting.GetTableByteCount(Headers); } // _headers in bytes | ||
if (IsDeliveryModePresent()) { bufferSize++; } // _deliveryMode in bytes | ||
if (IsPriorityPresent()) { bufferSize++; } // _priority in bytes | ||
if (IsCorrelationIdPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(CorrelationId); } // _correlationId in bytes | ||
if (IsReplyToPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(ReplyTo); } // _replyTo in bytes | ||
if (IsExpirationPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(Expiration); } // _expiration in bytes | ||
if (IsMessageIdPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(MessageId); } // _messageId in bytes | ||
if (IsTimestampPresent()) { bufferSize += 8; } // _timestamp in bytes | ||
if (IsTypePresent()) { bufferSize += 1 + WireFormatting.GetByteCount(Type); } // _type in bytes | ||
if (IsUserIdPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(UserId); } // _userId in bytes | ||
if (IsAppIdPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(AppId); } // _appId in bytes | ||
if (IsClusterIdPresent()) { bufferSize += 1 + WireFormatting.GetByteCount(ClusterId); } // _clusterId in bytes | ||
return bufferSize; | ||
} | ||
} | ||
} |
Oops, something went wrong.