diff --git a/RabbitMQDotNetClient.sln b/RabbitMQDotNetClient.sln index 8c7cd7253c..e7b966dc5e 100644 --- a/RabbitMQDotNetClient.sln +++ b/RabbitMQDotNetClient.sln @@ -12,8 +12,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitMQ.Client", "projects EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unit", "projects\Unit\Unit.csproj", "{B8FAC024-CC03-4067-9FFC-02846FB8AE48}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apigen", "projects\Apigen\Apigen.csproj", "{B416DDB7-5E3E-4A20-B5A9-C6E518E203A2}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,10 +26,6 @@ Global {B8FAC024-CC03-4067-9FFC-02846FB8AE48}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8FAC024-CC03-4067-9FFC-02846FB8AE48}.Release|Any CPU.ActiveCfg = Release|Any CPU {B8FAC024-CC03-4067-9FFC-02846FB8AE48}.Release|Any CPU.Build.0 = Release|Any CPU - {B416DDB7-5E3E-4A20-B5A9-C6E518E203A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B416DDB7-5E3E-4A20-B5A9-C6E518E203A2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B416DDB7-5E3E-4A20-B5A9-C6E518E203A2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B416DDB7-5E3E-4A20-B5A9-C6E518E203A2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build.bat b/build.bat index c93c305127..add2a96ff9 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,4 @@ @ECHO OFF set DOTNET_CLI_TELEMETRY_OPTOUT=1 dotnet restore .\RabbitMQDotNetClient.sln -dotnet run -p .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs dotnet build .\RabbitMQDotNetClient.sln diff --git a/projects/Apigen/Apigen.csproj b/projects/Apigen/Apigen.csproj deleted file mode 100755 index 29c726c6f5..0000000000 --- a/projects/Apigen/Apigen.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - netcoreapp3.1 - Exe - - - - - - - diff --git a/projects/Apigen/apigen/AmqpEntity.cs b/projects/Apigen/apigen/AmqpEntity.cs deleted file mode 100644 index 07b62ce45a..0000000000 --- a/projects/Apigen/apigen/AmqpEntity.cs +++ /dev/null @@ -1,83 +0,0 @@ -// 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.Xml; - -namespace RabbitMQ.Client.Apigen -{ - public class AmqpEntity { - public XmlNode m_node; - - public AmqpEntity(XmlNode n) { - m_node = n; - } - - public string GetString(string path) { - return Apigen.GetString(m_node, path); - } - - public string GetString(string path, string d) { - return Apigen.GetString(m_node, path, d); - } - - public int GetInt(string path) { - return Apigen.GetInt(m_node, path); - } - - public string Name { - get { - return GetString("@name"); - } - } - - public string DocumentationComment(string prefixSpaces) { - return DocumentationComment(prefixSpaces, "doc"); - } - - public string DocumentationCommentVariant(string prefixSpaces, string tagname) { - return DocumentationComment(prefixSpaces, "doc", tagname); - } - - public string DocumentationComment(string prefixSpaces, string docXpath) { - return DocumentationComment(prefixSpaces, docXpath, "summary"); - } - - public string DocumentationComment(string prefixSpaces, string docXpath, string tagname) { - string docStr = GetString(docXpath, "").Trim(); - if (docStr.Length > 0) { - return $"{prefixSpaces}/// <{tagname}>\n{GetString(docXpath, "")}\n" - .Replace("\n", $"\n{prefixSpaces}/// "); - } else { - return $"{prefixSpaces}// (no documentation)"; - } - } - } -} diff --git a/projects/Apigen/apigen/Apigen.cs b/projects/Apigen/apigen/Apigen.cs deleted file mode 100644 index 3ccfb5590a..0000000000 --- a/projects/Apigen/apigen/Apigen.cs +++ /dev/null @@ -1,1460 +0,0 @@ -// 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 System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Xml; - -using RabbitMQ.Client.Apigen.Attributes; - -namespace RabbitMQ.Client.Apigen -{ - public static class ApigenExtensions - { - public static T Attribute(this MemberInfo mi) where T : Attribute - { - return mi.GetCustomAttribute(false); - } - - public static T Attribute(this ParameterInfo pi) where T : Attribute - { - return pi.GetCustomAttribute(false); - } - - public static T Attribute(this ICustomAttributeProvider p) where T : Attribute - { - return p.GetCustomAttributes(typeof(T), false).Cast().SingleOrDefault(); - } - } - - public class Apigen - { - /////////////////////////////////////////////////////////////////////////// - // Entry point - - public static void Main(string[] args) - { - Apigen instance = new Apigen(new List(args)); - instance.Generate(); - } - - /////////////////////////////////////////////////////////////////////////// - // XML utilities - - public static XmlNodeList GetNodes(XmlNode n0, string path) - { - return n0.SelectNodes(path); - } - - public static string GetString(XmlNode n0, string path, string d) - { - XmlNode n = n0.SelectSingleNode(path); - string pathOrDefault = (n == null) ? d : n.InnerText; - return xmlStringMapper(pathOrDefault); - } - - public static string GetString(XmlNode n0, string path) - { - string s = GetString(n0, path, null); - if (s == null) - { - throw new Exception($"Missing spec XML node: {path}"); - } - return s; - } - - public static int GetInt(XmlNode n0, string path, int d) - { - string s = GetString(n0, path, null); - return (s == null) ? d : int.Parse(s); - } - - public static int GetInt(XmlNode n0, string path) - { - return int.Parse(GetString(n0, path)); - } - - /// - /// Rename all instances of an entire string from the XML spec - /// - /// input string from XML spec - /// renamed string - private static string xmlStringMapper(string xmlString) - { - switch (xmlString) - { - case "no-wait": - return "nowait"; - default: - return xmlString; - } - } - - /////////////////////////////////////////////////////////////////////////// - // Name manipulation and mangling for C# - - public static string MangleConstant(string name) - { - // Previously, we used C_STYLE_CONSTANT_NAMES: - /* - return name - .Replace(" ", "_") - .Replace("-", "_"). - ToUpper(); - */ - // ... but TheseKindsOfNames are more in line with .NET style guidelines. - return MangleClass(name); - } - - public static IList IdentifierParts(string name) - { - IList result = new List(); - foreach (string s1 in name.Split(new char[] { '-', ' ' })) - { - result.Add(s1); - } - return result; - } - - public static string MangleClass(string name) - { - StringBuilder sb = new StringBuilder(); - foreach (string s in IdentifierParts(name)) - { - sb.Append(char.ToUpperInvariant(s[0]) + s.Substring(1).ToLowerInvariant()); - } - return sb.ToString(); - } - - public static string MangleMethod(string name) - { - StringBuilder sb = new StringBuilder(); - bool useUpper = false; - foreach (string s in IdentifierParts(name)) - { - if (useUpper) - { - sb.Append(char.ToUpperInvariant(s[0]) + s.Substring(1).ToLowerInvariant()); - } - else - { - sb.Append(s.ToLowerInvariant()); - useUpper = true; - } - } - return sb.ToString(); - } - - public static string MangleMethodClass(AmqpClass c, AmqpMethod m) - { - return MangleClass(c.Name) + MangleClass(m.Name); - } - - /////////////////////////////////////////////////////////////////////////// - - public string m_inputXmlFilename; - public string m_outputFilename; - - public XmlDocument m_spec = null; - public TextWriter m_outputFile = null; - - public int m_majorVersion; - public int m_minorVersion; - public int m_revision = 0; - public string m_apiName; - public bool m_emitComments = false; - - public Type m_modelType = typeof(RabbitMQ.Client.Impl.IFullModel); - public IList m_modelTypes = new List(); - public IList> m_constants = new List>(); - public IList m_classes = new List(); - public IDictionary m_domains = new Dictionary(); - - public static IDictionary m_primitiveTypeMap; - public static IDictionary m_primitiveTypeFlagMap; - - static Apigen() - { - m_primitiveTypeMap = new Dictionary(); - m_primitiveTypeFlagMap = new Dictionary(); - InitPrimitiveType("octet", "byte", false); - InitPrimitiveType("shortstr", "string", true); - InitPrimitiveType("longstr", "byte[]", true); - InitPrimitiveType("short", "ushort", false); - InitPrimitiveType("long", "uint", false); - InitPrimitiveType("longlong", "ulong", false); - InitPrimitiveType("bit", "bool", false); - InitPrimitiveType("table", "IDictionary", true); - InitPrimitiveType("timestamp", "AmqpTimestamp", false); - InitPrimitiveType("content", "byte[]", true); - } - - public static void InitPrimitiveType(string amqpType, string dotnetType, bool isReference) - { - m_primitiveTypeMap[amqpType] = dotnetType; - m_primitiveTypeFlagMap[amqpType] = isReference; - } - - public void HandleOption(string opt) - { - if (opt.StartsWith("--apiName:")) - { - m_apiName = opt.Substring(9); - } - else if (opt == "-c") - { - m_emitComments = true; - } - else - { - Console.Error.WriteLine($"Unsupported command-line option: {opt}"); - Usage(); - } - } - - public void Usage() - { - Console.Error.WriteLine("Usage: Apigen.exe [options ...] "); - Console.Error.WriteLine(" Options include:"); - Console.Error.WriteLine(" --apiName:"); - Console.Error.WriteLine(" The apiName option is required."); - Environment.Exit(1); - } - - public Apigen(IList args) - { - while (args.Count > 0 && args[0].StartsWith("--")) - { - HandleOption(args[0]); - args.RemoveAt(0); - } - if ((args.Count < 2) - || (m_apiName == null)) - { - Usage(); - } - m_inputXmlFilename = args[0]; - m_outputFilename = args[1]; - } - - /////////////////////////////////////////////////////////////////////////// - - public static string ApiNamespaceBase => "RabbitMQ.Client.Framing"; - - public static string ImplNamespaceBase => "RabbitMQ.Client.Framing.Impl"; - - public void Generate() - { - LoadSpec(); - ParseSpec(); - ReflectModel(); - GenerateOutput(); - } - - public void LoadSpec() - { - Console.WriteLine($"* Loading spec from '{m_inputXmlFilename}'"); - m_spec = new XmlDocument(); - - using (var stream = new FileStream(m_inputXmlFilename, FileMode.Open, FileAccess.Read)) - { - m_spec.Load(stream); - } - } - - public void ParseSpec() - { - m_majorVersion = GetInt(m_spec, "/amqp/@major"); - m_minorVersion = GetInt(m_spec, "/amqp/@minor"); - m_revision = GetInt(m_spec, "/amqp/@revision"); - - Console.WriteLine("* Parsing spec for version {0}.{1}.{2}", m_majorVersion, m_minorVersion, m_revision); - foreach (XmlNode n in m_spec.SelectNodes("/amqp/constant")) - { - m_constants.Add(new KeyValuePair(GetString(n, "@name"), GetInt(n, "@value"))); - } - foreach (XmlNode n in m_spec.SelectNodes("/amqp/class")) - { - m_classes.Add(new AmqpClass(n)); - } - foreach (XmlNode n in m_spec.SelectNodes("/amqp/domain")) - { - m_domains[GetString(n, "@name")] = GetString(n, "@type"); - } - } - - public void ReflectModel() - { - m_modelTypes.Add(m_modelType); - for (int i = 0; i < m_modelTypes.Count; i++) - { - foreach (Type intf in m_modelTypes[i].GetInterfaces()) - { - m_modelTypes.Add(intf); - } - } - } - - public string ResolveDomain(string d) - { - while (m_domains.ContainsKey(d)) - { - string newD = m_domains[d]; - if (d.Equals(newD)) - { - break; - } - - d = newD; - } - return d; - } - - public string MapDomain(string d) - { - return m_primitiveTypeMap[ResolveDomain(d)]; - } - - public string VersionToken() - { - return $"v{m_majorVersion}_{m_minorVersion}"; - } - - public void GenerateOutput() - { - Console.WriteLine($"* Generating code into '{m_outputFilename}'"); - - string directory = Path.GetDirectoryName(m_outputFilename); - - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - using (var stream = new FileStream(m_outputFilename, FileMode.Create, FileAccess.Write)) - { - m_outputFile = new StreamWriter(stream); - EmitPrelude(); - EmitPublic(); - EmitPrivate(); - m_outputFile.Dispose(); - } - } - - public void Emit(object o) - { - m_outputFile.Write(o); - } - - public void EmitLine(object o) - { - m_outputFile.WriteLine(o); - } - - public void EmitSpecComment(object o) - { - if (m_emitComments) - { - EmitLine(o); - } - } - - public void EmitPrelude() - { - const string prelude = -@"// Autogenerated code. Do not edit. - -// 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 System.Text; - -using RabbitMQ.Client; -using RabbitMQ.Client.Exceptions; -using RabbitMQ.Client.Framing.Impl; -using RabbitMQ.Client.Impl; -"; - EmitLine(prelude); - } - - public void EmitPublic() - { - int port = GetInt(m_spec, "/amqp/@port"); - string publicVars = -$@"namespace {ApiNamespaceBase} -{{ - internal sealed class Protocol : {ImplNamespaceBase}.ProtocolBase - {{ - ///Protocol major version (= {m_majorVersion}) - public override int MajorVersion => {m_majorVersion}; - - ///Protocol minor version (= {m_minorVersion}) - public override int MinorVersion => {m_minorVersion}; - - ///Protocol revision (= {m_revision}) - public override int Revision => {m_revision}; - - ///Protocol API name (= {m_apiName}) - public override string ApiName => ""{m_apiName}""; - - ///Default TCP port (= {port}) - public override int DefaultPort => {port}; -"; - - EmitLine("namespace RabbitMQ.Client"); - EmitLine("{"); - EmitLine(" public static class Constants"); - EmitLine(" {"); - foreach (KeyValuePair de in m_constants) - { - EmitLine($" ///(= {de.Value})"); - EmitLine($" public const int {MangleConstant(de.Key)} = {de.Value};"); - } - EmitLine(" }"); - EmitLine("}"); - EmitLine(publicVars); - EmitMethodArgumentReader(); - EmitLine(""); - EmitContentHeaderReader(); - EmitLine(" }"); - foreach (AmqpClass c in m_classes) - { - EmitClassMethods(c); - } - foreach (AmqpClass c in m_classes) - { - if (c.NeedsProperties) - { - EmitClassProperties(c); - } - } - EmitLine("}"); - } - - public void EmitAutogeneratedSummary(string prefixSpaces, string extra) - { - EmitLine($"{prefixSpaces}/// Autogenerated type. {extra}"); - } - - public void EmitClassMethods(AmqpClass c) - { - foreach (AmqpMethod m in c.m_Methods) - { - EmitAutogeneratedSummary(" ", $"AMQP specification method \"{c.Name}.{m.Name}\"."); - EmitSpecComment(m.DocumentationCommentVariant(" ", "remarks")); - EmitLine($" internal interface I{MangleMethodClass(c, m)} : IMethod"); - EmitLine(" {"); - foreach (AmqpField f in m.m_Fields) - { - EmitSpecComment(f.DocumentationComment(" ")); - EmitLine($" {MapDomain(f.Domain)} {MangleClass(f.Name)} {{ get; }}"); - } - EmitLine(" }"); - } - } - - public bool HasFactoryMethod(AmqpClass c) - { - foreach (Type t in m_modelTypes) - { - foreach (MethodInfo method in t.GetMethods()) - { - AmqpContentHeaderFactoryAttribute f = method.Attribute(); - if (f != null && MangleClass(f.m_contentClass) == MangleClass(c.Name)) - { - return true; - } - } - } - return false; - } - - public bool IsBoolean(AmqpField f) - { - return ResolveDomain(f.Domain) == "bit"; - } - - public bool IsReferenceType(AmqpField f) - { - return m_primitiveTypeFlagMap[ResolveDomain(f.Domain)]; - } - - public bool IsAmqpClass(Type t) - { - foreach (AmqpClass c in m_classes) - { - if (c.Name == t.Name) - { - return true; - } - } - return false; - } - - public void EmitClassProperties(AmqpClass c) - { - bool hasCommonApi = HasFactoryMethod(c); - string propertiesBaseClass = $"RabbitMQ.Client.Impl.{(hasCommonApi ? $"{MangleClass(c.Name)}Properties" : "ContentHeaderBase")}"; - string maybeOverride = hasCommonApi ? "override " : ""; - - EmitAutogeneratedSummary(" ", $"AMQP specification content header properties for content class \"{c.Name}\""); - EmitSpecComment(c.DocumentationCommentVariant(" ", "remarks")); - EmitLine($" internal sealed class {MangleClass(c.Name)}Properties : {propertiesBaseClass}"); - EmitLine(" {"); - foreach (AmqpField f in c.m_Fields) - { - EmitLine($" private {MapDomain(f.Domain)} _{MangleMethod(f.Name)};"); - } - EmitLine(""); - foreach (AmqpField f in c.m_Fields) - { - EmitSpecComment(f.DocumentationComment(" ", "@label")); - EmitLine($" public {maybeOverride}{MapDomain(f.Domain)} {MangleClass(f.Name)}"); - EmitLine(" {"); - EmitLine($" get => _{MangleMethod(f.Name)};"); - EmitLine($" set => _{MangleMethod(f.Name)} = value;"); - EmitLine(" }"); - EmitLine(""); - } - foreach (AmqpField f in c.m_Fields) - { - if (!IsBoolean(f)) - { - EmitLine($" public {maybeOverride}void Clear{MangleClass(f.Name)}() => _{MangleMethod(f.Name)} = default;"); - EmitLine(""); - } - } - - foreach (AmqpField f in c.m_Fields) - { - if (!IsBoolean(f)) - { - EmitLine($" public {maybeOverride}bool Is{MangleClass(f.Name)}Present() => _{MangleMethod(f.Name)} != default;"); - EmitLine(""); - } - } - - EmitLine($" public {MangleClass(c.Name)}Properties() {{ }}"); - EmitLine($" public override ushort ProtocolClassId => {c.Index};"); - EmitLine($" public override string ProtocolClassName => \"{c.Name}\";"); - EmitLine(""); - EmitLine(" internal override void ReadPropertiesFrom(ref Client.Impl.ContentHeaderPropertyReader reader)"); - EmitLine(" {"); - foreach (AmqpField f in c.m_Fields) - { - if (IsBoolean(f)) - { - EmitLine($" var {MangleMethod(f.Name)} = reader.ReadBit();"); - } - else - { - EmitLine($" var {MangleMethod(f.Name)}_present = reader.ReadPresence();"); - } - } - EmitLine(" reader.FinishPresence();"); - foreach (AmqpField f in c.m_Fields) - { - if (!IsBoolean(f)) - { - EmitLine($" if ({MangleMethod(f.Name)}_present) {{ _{MangleMethod(f.Name)} = reader.Read{MangleClass(ResolveDomain(f.Domain))}(); }}"); - } - } - EmitLine(" }"); - EmitLine(""); - EmitLine(" internal override void WritePropertiesTo(ref Client.Impl.ContentHeaderPropertyWriter writer)"); - EmitLine(" {"); - foreach (AmqpField f in c.m_Fields) - { - if (IsBoolean(f)) - { - EmitLine($" writer.WriteBit(_{MangleMethod(f.Name)});"); - } - else - { - EmitLine($" writer.WritePresence(Is{MangleClass(f.Name)}Present());"); - } - } - EmitLine(" writer.FinishPresence();"); - foreach (AmqpField f in c.m_Fields) - { - if (!IsBoolean(f)) - { - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ writer.Write{MangleClass(ResolveDomain(f.Domain))}(_{MangleMethod(f.Name)}); }}"); - } - } - EmitLine(" }"); - EmitLine(""); - EmitLine(" public override int GetRequiredPayloadBufferSize()"); - EmitLine(" {"); - EmitLine($" int bufferSize = {Math.Max((int)Math.Ceiling(c.m_Fields.Count / 15.0), 1) * 2}; // number of presence fields ({c.m_Fields.Count}) in 2 bytes blocks"); - foreach (AmqpField f in c.m_Fields) - { - switch (MapDomain(f.Domain)) - { - case "byte": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize++; }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "string": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += 1 + Encoding.UTF8.GetByteCount(_{MangleMethod(f.Name)}); }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "byte[]": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += 4 + _{MangleMethod(f.Name)}.Length; }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "ushort": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += 2; }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "uint": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += 4; }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "ulong": - case "AmqpTimestamp": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += 8; }} // _{MangleMethod(f.Name)} in bytes"); - break; - case "bool": - // TODO: implement if used, not used anywhere yet - break; - case "IDictionary": - EmitLine($" if (Is{MangleClass(f.Name)}Present()) {{ bufferSize += WireFormatting.GetTableByteCount(_{MangleMethod(f.Name)}); }} // _{MangleMethod(f.Name)} in bytes"); - break; - default: - throw new ArgumentOutOfRangeException($"Can't handle size calculations for type = {f.Domain};"); - } - } - - EmitLine(" return bufferSize;"); - EmitLine(" }"); - EmitLine(""); - EmitLine(" public override void AppendPropertyDebugStringTo(StringBuilder sb)"); - EmitLine(" {"); - EmitLine(" sb.Append(\"(\");"); - { - int remaining = c.m_Fields.Count; - foreach (AmqpField f in c.m_Fields) - { - Emit($" sb.Append(\"{f.Name}=\")"); - if (IsBoolean(f)) - { - Emit($".Append(_{MangleMethod(f.Name)})"); - } - else - { - Emit($".Append(Is{MangleClass(f.Name)}Present() ? _{MangleMethod(f.Name)}.ToString() : \"_\")"); - } - remaining--; - if (remaining > 0) - { - EmitLine(".Append(\", \");"); - } - else - { - EmitLine(";"); - } - } - } - EmitLine(" sb.Append(\")\");"); - EmitLine(" }"); - EmitLine(" }"); - } - - public void EmitPrivate() - { - EmitLine($"namespace {ImplNamespaceBase}"); - EmitLine("{"); - EmitLine(" internal static class ClassConstants"); - EmitLine(" {"); - foreach (AmqpClass c in m_classes) - { - EmitLine($" internal const ushort {MangleConstant(c.Name)} = {c.Index};"); - } - EmitLine(" }"); - EmitLine(""); - EmitLine(" internal enum ClassId"); - EmitLine(" {"); - foreach (AmqpClass c in m_classes) - { - EmitLine($" {MangleConstant(c.Name)} = {c.Index},"); - } - EmitLine(" Invalid = -1,"); - EmitLine(" }"); - EmitLine(""); - foreach (AmqpClass c in m_classes) - { - EmitLine($" internal static class {MangleClass(c.Name)}MethodConstants"); - EmitLine(" {"); - foreach (AmqpMethod m in c.m_Methods) - { - EmitLine($" internal const ushort {MangleConstant(m.Name)} = {m.Index};"); - } - EmitLine(" }"); - } - EmitLine(""); - foreach (AmqpClass c in m_classes) - { - EmitClassMethodImplementations(c); - } - EmitLine(""); - EmitModelImplementation(); - EmitLine("}"); - } - - public void EmitClassMethodImplementations(AmqpClass c) - { - foreach (AmqpMethod m in c.m_Methods) - { - EmitAutogeneratedSummary(" ", "Private implementation class - do not use directly."); - EmitLine($" internal sealed class {MangleMethodClass(c, m)} : Client.Impl.MethodBase, I{MangleMethodClass(c, m)}"); - EmitLine(" {"); - foreach (AmqpField f in m.m_Fields) - { - EmitLine($" public {MapDomain(f.Domain)} _{MangleMethod(f.Name)};"); - } - EmitLine(""); - foreach (AmqpField f in m.m_Fields) - { - EmitLine($" {MapDomain(f.Domain)} I{MangleMethodClass(c, m)}.{MangleClass(f.Name)} => _{MangleMethod(f.Name)};"); - } - EmitLine(""); - if (m.m_Fields.Count > 0) - { - EmitLine($" public {MangleMethodClass(c, m)}() {{}}"); - } - EmitLine($" public {MangleMethodClass(c, m)}({string.Join(", ", m.m_Fields.Select(f => $"{MapDomain(f.Domain)} @{MangleClass(f.Name)}"))})"); - EmitLine(" {"); - foreach (AmqpField f in m.m_Fields) - { - EmitLine($" _{MangleMethod(f.Name)} = @{MangleClass(f.Name)};"); - } - EmitLine(" }"); - EmitLine(""); - EmitLine($" public override ushort ProtocolClassId => ClassConstants.{MangleConstant(c.Name)};"); - EmitLine($" public override ushort ProtocolMethodId => {MangleConstant(c.Name)}MethodConstants.{MangleConstant(m.Name)};"); - EmitLine($" public override string ProtocolMethodName => \"{c.Name}.{m.Name}\";"); - EmitLine($" public override bool HasContent => {(m.HasContent ? "true" : "false")};"); - EmitLine(""); - EmitLine(" public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader)"); - EmitLine(" {"); - foreach (AmqpField f in m.m_Fields) - { - EmitLine($" _{MangleMethod(f.Name)} = reader.Read{MangleClass(ResolveDomain(f.Domain))}();"); - } - EmitLine(" }"); - EmitLine(""); - EmitLine(" public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer)"); - EmitLine(" {"); - var lastWasBitClass = false; - foreach (AmqpField f in m.m_Fields) - { - string mangleClass = MangleClass(ResolveDomain(f.Domain)); - if (mangleClass != "Bit") - { - if (lastWasBitClass) - { - EmitLine($" writer.EndBits();"); - lastWasBitClass = false; - } - } - else - { - lastWasBitClass = true; - } - - EmitLine($" writer.Write{mangleClass}(_{MangleMethod(f.Name)});"); - } - if (lastWasBitClass) - { - EmitLine($" writer.EndBits();"); - } - EmitLine(" }"); - EmitLine(""); - EmitLine(" public override int GetRequiredBufferSize()"); - EmitLine(" {"); - - int bitCount = 0; - int bytesSize = 0; - var commentBuilder = new StringBuilder(" // bytes for "); - foreach (AmqpField f in m.m_Fields) - { - switch (MapDomain(f.Domain)) - { - case "byte": - bytesSize++; - commentBuilder.Append('_').Append(MangleMethod(f.Name)).Append(", "); - break; - case "string": - bytesSize++; - commentBuilder.Append("length of _").Append(MangleMethod(f.Name)).Append(", "); - break; - case "byte[]": - bytesSize += 4; - commentBuilder.Append("length of _").Append(MangleMethod(f.Name)).Append(", "); - break; - case "ushort": - bytesSize += 2; - commentBuilder.Append('_').Append(MangleMethod(f.Name)).Append(", "); - break; - case "uint": - bytesSize += 4; - commentBuilder.Append('_').Append(MangleMethod(f.Name)).Append(", "); - break; - case "ulong": - case "AmqpTimestamp": - bytesSize += 8; - commentBuilder.Append('_').Append(MangleMethod(f.Name)).Append(", "); - break; - case "bool": - if (bitCount == 0) - { - commentBuilder.Append("bit fields, "); - } - bitCount++; - break; - case "IDictionary": - break; - default: - throw new ArgumentOutOfRangeException($"Can't handle size calculations for type = {f.Domain};"); - } - } - - // 13 = " // bytes for " - if (commentBuilder.Length > 14) - { - // cut of last ", " - commentBuilder.Length -= 2; - } - else - { - commentBuilder.Clear(); - } - bytesSize += (int)Math.Ceiling(bitCount / 8.0); - EmitLine($" int bufferSize = {bytesSize};{commentBuilder}"); - foreach (AmqpField f in m.m_Fields) - { - switch (MapDomain(f.Domain)) - { - case "byte": - case "ushort": - case "uint": - case "ulong": - case "AmqpTimestamp": - case "bool": - // size already calculated - break; - case "string": - EmitLine($" bufferSize += Encoding.UTF8.GetByteCount(_{MangleMethod(f.Name)}); // _{MangleMethod(f.Name)} in bytes"); - break; - case "byte[]": - EmitLine($" bufferSize += _{MangleMethod(f.Name)}.Length; // _{MangleMethod(f.Name)} in bytes"); - break; - case "IDictionary": - EmitLine($" bufferSize += WireFormatting.GetTableByteCount(_{MangleMethod(f.Name)}); // _{MangleMethod(f.Name)} in bytes"); - break; - default: - throw new ArgumentOutOfRangeException($"Can't handle size calculations for type = {f.Domain};"); - } - } - - EmitLine(" return bufferSize;"); - EmitLine(" }"); - EmitLine(""); - EmitLine(" public override void AppendArgumentDebugStringTo(StringBuilder sb)"); - EmitLine(" {"); - EmitLine(" sb.Append('(');"); - { - int remaining = m.m_Fields.Count; - foreach (AmqpField f in m.m_Fields) - { - Emit($" sb.Append(_{MangleMethod(f.Name)})"); - remaining--; - if (remaining > 0) - { - EmitLine(".Append(',');"); - } - else - { - EmitLine(";"); - } - } - } - EmitLine(" sb.Append(')');"); - EmitLine(" }"); - EmitLine(" }"); - } - } - - public void EmitMethodArgumentReader() - { - EmitLine(" internal override Client.Impl.MethodBase DecodeMethodFrom(ReadOnlySpan span)"); - EmitLine(" {"); - EmitLine(" ushort classId = Util.NetworkOrderDeserializer.ReadUInt16(span);"); - EmitLine(" ushort methodId = Util.NetworkOrderDeserializer.ReadUInt16(span.Slice(2));"); - EmitLine(" Client.Impl.MethodBase result = DecodeMethodFrom(classId, methodId);"); - EmitLine(" if(result != null)"); - EmitLine(" {"); - EmitLine(" Client.Impl.MethodArgumentReader reader = new Client.Impl.MethodArgumentReader(span.Slice(4));"); - EmitLine(" result.ReadArgumentsFrom(ref reader);"); - EmitLine(" return result;"); - EmitLine(" }"); - EmitLine(""); - EmitLine(" throw new Client.Exceptions.UnknownClassOrMethodException(classId, methodId);"); - EmitLine(" }"); - EmitLine(""); - EmitLine(" internal Client.Impl.MethodBase DecodeMethodFrom(ushort classId, ushort methodId)"); - EmitLine(" {"); - EmitLine(" switch ((classId << 16) | methodId)"); - EmitLine(" {"); - foreach (AmqpClass c in m_classes) - { - foreach (AmqpMethod m in c.m_Methods) - { - EmitLine($" case (ClassConstants.{MangleConstant(c.Name)} << 16) | {MangleConstant(c.Name)}MethodConstants.{MangleConstant(m.Name)}: return new Impl.{MangleMethodClass(c, m)}();"); - } - } - EmitLine(" default: return null;"); - EmitLine(" }"); - EmitLine(" }"); - EmitLine(""); - } - - public void EmitContentHeaderReader() - { - EmitLine(" internal override Client.Impl.ContentHeaderBase DecodeContentHeaderFrom(ushort classId)"); - EmitLine(" {"); - EmitLine(" switch (classId)"); - EmitLine(" {"); - foreach (AmqpClass c in m_classes) - { - if (c.NeedsProperties) - { - EmitLine($" case {c.Index}: return new {MangleClass(c.Name)}Properties();"); - } - } - EmitLine(" default: throw new Client.Exceptions.UnknownClassOrMethodException(classId, 0);"); - EmitLine(" }"); - EmitLine(" }"); - } - - public Attribute Attribute(MemberInfo mi, Type t) - { - return Attribute(mi.GetCustomAttributes(t, false), t); - } - - public Attribute Attribute(ParameterInfo pi, Type t) - { - return Attribute(pi.GetCustomAttributes(t, false), t); - } - - public Attribute Attribute(ICustomAttributeProvider p, Type t) - { - return Attribute(p.GetCustomAttributes(t, false), t); - } - - public Attribute Attribute(IEnumerable attributes, Type t) - { - TypeInfo typeInfo = t.GetTypeInfo(); - - if (typeInfo.IsSubclassOf(typeof(AmqpApigenAttribute))) - { - AmqpApigenAttribute result = null; - foreach (AmqpApigenAttribute candidate in attributes) - { - if (candidate.m_namespaceName == null && result == null) - { - result = candidate; - } - if (candidate.m_namespaceName == ApiNamespaceBase) - { - result = candidate; - } - } - return result; - } - else - { - foreach (Attribute attribute in attributes) - { - return attribute; - } - return null; - } - } - - public void EmitModelImplementation() - { - EmitLine(" internal class Model: Client.Impl.ModelBase {"); - EmitLine(" public Model(Client.Impl.ISession session): base(session) {}"); - EmitLine(" public Model(Client.Impl.ISession session, ConsumerWorkService workService): base(session, workService) {}"); - IList asynchronousHandlers = new List(); - foreach (Type t in m_modelTypes) - { - foreach (MethodInfo method in t.GetMethods()) - { - if (method.DeclaringType.Namespace != null && - method.DeclaringType.Namespace.StartsWith("RabbitMQ.Client")) - { - if (method.Name.StartsWith("Handle") || - (Attribute(method, typeof(AmqpAsynchronousHandlerAttribute)) != null)) - { - if ((Attribute(method, typeof(AmqpMethodDoNotImplementAttribute)) == null) && Attribute(method, typeof(AmqpUnsupportedAttribute)) == null) - { - asynchronousHandlers.Add(method); - } - } - else - { - MaybeEmitModelMethod(method); - } - } - } - } - EmitAsynchronousHandlers(asynchronousHandlers); - EmitLine(" }"); - } - - public void EmitContentHeaderFactory(MethodInfo method) - { - AmqpContentHeaderFactoryAttribute factoryAnnotation = (AmqpContentHeaderFactoryAttribute) - Attribute(method, typeof(AmqpContentHeaderFactoryAttribute)); - string contentClass = factoryAnnotation.m_contentClass; - EmitModelMethodPreamble(method); - EmitLine(" {"); - if (Attribute(method, typeof(AmqpUnsupportedAttribute)) != null) - { - EmitLine($" throw new UnsupportedMethodException(\"{method.Name}\");"); - } - else - { - EmitLine($" return new {MangleClass(contentClass)}Properties();"); - } - EmitLine(" }"); - } - - public void MaybeEmitModelMethod(MethodInfo method) - { - if (method.IsSpecialName) - { - // It's some kind of event- or property-related method. - // It shouldn't be autogenerated. - } - else if (method.Name.EndsWith("NoWait")) - { - // Skip *Nowait versions - } - else if (Attribute(method, typeof(AmqpMethodDoNotImplementAttribute)) != null) - { - // Skip this method, by request (AmqpMethodDoNotImplement) - } - else if (Attribute(method, typeof(AmqpContentHeaderFactoryAttribute)) != null) - { - EmitContentHeaderFactory(method); - } - else if (Attribute(method, typeof(AmqpUnsupportedAttribute)) != null) - { - EmitModelMethodPreamble(method); - EmitLine(" {"); - EmitLine($" throw new UnsupportedMethodException(\"{method.Name}\");"); - EmitLine(" }"); - } - else - { - EmitModelMethod(method); - } - } - - public string SanitisedFullName(Type t) - { - if (t.Equals(typeof(IDictionary))) - { - return "IDictionary"; - } - if (t.Equals(typeof(ReadOnlyMemory))) - { - return "ReadOnlyMemory"; - } - - switch (t.FullName) - { - case "System.Boolean": - return "bool"; - case "System.Byte[]": - return "byte[]"; - case "System.String": - return "string"; - case "System.UInt16": - return "ushort"; - case "System.UInt32": - return "uint"; - case "System.UInt64": - return "ulong"; - case "System.Void": - return "void"; - default: - return t.FullName; - }; - } - - public void EmitModelMethodPreamble(MethodInfo method) - { - ParameterInfo[] parameters = method.GetParameters(); - EmitLine($" public override {SanitisedFullName(method.ReturnType)} {method.Name} ({string.Join(", ", parameters.Select(pi => $"{SanitisedFullName(pi.ParameterType)} @{pi.Name}"))})"); - } - - public void LookupAmqpMethod(MethodInfo method, - string methodName, - out AmqpClass amqpClass, - out AmqpMethod amqpMethod) - { - amqpClass = null; - amqpMethod = null; - - // First, try autodetecting the class/method via the - // IModel method name. - - foreach (AmqpClass c in m_classes) - { - foreach (AmqpMethod m in c.m_Methods) - { - if (methodName.Equals(MangleMethodClass(c, m))) - { - amqpClass = c; - amqpMethod = m; - goto stopSearching; // wheee - } - } - } - stopSearching: - - // If an explicit mapping was provided as an attribute, - // then use that instead, whether the autodetect worked or - // not. - - { - if (Attribute(method, typeof(AmqpMethodMappingAttribute)) is AmqpMethodMappingAttribute methodMapping) - { - amqpClass = null; - foreach (AmqpClass c in m_classes) - { - if (c.Name == methodMapping.m_className) - { - amqpClass = c; - break; - } - } - amqpMethod = amqpClass.MethodNamed(methodMapping.m_methodName); - } - } - - // At this point, if can't find either the class or the - // method, we can't proceed. Complain. - - if (amqpClass == null || amqpMethod == null) - { - throw new Exception($"Could not find AMQP class or method for IModel method {method.Name}"); - } - } - - public void EmitModelMethod(MethodInfo method) - { - ParameterInfo[] parameters = method.GetParameters(); - - LookupAmqpMethod(method, method.Name, out AmqpClass amqpClass, out AmqpMethod amqpMethod); - - string requestImplClass = MangleMethodClass(amqpClass, amqpMethod); - - // At this point, we know which request method to - // send. Now compute whether it's an RPC or not. - - AmqpMethod amqpReplyMethod = null; - AmqpMethodMappingAttribute replyMapping = - Attribute(method.ReturnTypeCustomAttributes, typeof(AmqpMethodMappingAttribute)) - as AmqpMethodMappingAttribute; - if (Attribute(method, typeof(AmqpForceOneWayAttribute)) == null && - (amqpMethod.IsSimpleRpcRequest || replyMapping != null)) - { - // We're not forcing oneway, and either are a simple - // RPC request, or have an explicit replyMapping - amqpReplyMethod = amqpClass.MethodNamed(replyMapping == null - ? amqpMethod.m_ResponseMethods[0] - : replyMapping.m_methodName); - if (amqpReplyMethod == null) - { - throw new Exception($"Could not find AMQP reply method for IModel method {method.Name}"); - } - } - - // If amqpReplyMethod is null at this point, it's a - // one-way operation, and no continuation needs to be - // consed up. Otherwise, we should expect a reply of kind - // identified by amqpReplyMethod - unless there's a nowait - // parameter thrown into the equation! - // - // Examine the parameters to discover which might be - // nowait, content header or content body. - - ParameterInfo nowaitParameter = null; - string nowaitExpression = "null"; - ParameterInfo contentHeaderParameter = null; - ParameterInfo contentBodyParameter = null; - foreach (ParameterInfo pi in parameters) - { - if (Attribute(pi, typeof(AmqpNowaitArgumentAttribute)) is AmqpNowaitArgumentAttribute nwAttr) - { - nowaitParameter = pi; - if (nwAttr.m_replacementExpression != null) - { - nowaitExpression = nwAttr.m_replacementExpression; - } - } - if (Attribute(pi, typeof(AmqpContentHeaderMappingAttribute)) != null) - { - contentHeaderParameter = pi; - } - if (Attribute(pi, typeof(AmqpContentBodyMappingAttribute)) != null) - { - contentBodyParameter = pi; - } - } - - // Compute expression text for the content header and body. - - string contentHeaderExpr = - contentHeaderParameter == null - ? "null" - : $" ({MangleClass(amqpClass.Name)}Properties) {contentHeaderParameter.Name}"; - string contentBodyExpr = - contentBodyParameter == null ? "null" : contentBodyParameter.Name; - - // Emit the method declaration and preamble. - - EmitModelMethodPreamble(method); - EmitLine(" {"); - - // Emit the code to build the request. - if (parameters.Length > 0) - { - foreach (ParameterInfo unsupportedParameter in parameters.Where(x => x.Attribute() != null)) - { - EmitLine($" if (@{unsupportedParameter.Name} != null)"); - EmitLine(" {"); - EmitLine($" throw new UnsupportedMethodFieldException(\"{method.Name}\", \"{unsupportedParameter.Name}\");"); - EmitLine(" }"); - } - EmitLine($" {requestImplClass} __req = new {requestImplClass}()"); - EmitLine(" {"); - foreach (ParameterInfo pi in parameters) - { - if (pi != contentHeaderParameter && pi != contentBodyParameter) - { - if (pi.Attribute() is AmqpFieldMappingAttribute fieldMapping) - { - EmitLine($" _{fieldMapping.m_fieldName} = @{pi.Name},"); - } - else - { - EmitLine($" _{pi.Name} = @{pi.Name},"); - } - } - } - EmitLine(" };"); - } - else - { - EmitLine($" {requestImplClass} __req = new {requestImplClass}();"); - } - - // If we have a nowait parameter, sometimes that can turn - // a ModelRpc call into a ModelSend call. - - if (nowaitParameter != null) - { - EmitLine($" if ({nowaitParameter.Name}) {{"); - EmitLine($" ModelSend(__req,{contentHeaderExpr},{contentBodyExpr});"); - if (method.ReturnType == typeof(void)) - { - EmitLine(" return;"); - } - else - { - EmitLine($" return {nowaitExpression};"); - } - EmitLine(" }"); - } - - // At this point, perform either a ModelRpc or a - // ModelSend. - - if (amqpReplyMethod == null) - { - EmitLine($" ModelSend(__req,{contentHeaderExpr},{contentBodyExpr});"); - } - else - { - string replyImplClass = MangleMethodClass(amqpClass, amqpReplyMethod); - - EmitLine($" Client.Impl.MethodBase __repBase = ModelRpc(__req, {contentHeaderExpr}, {contentBodyExpr});"); - EmitLine($" if (!(__repBase is {replyImplClass}{(method.ReturnType == typeof(void) ? "" : " __rep")}))"); - EmitLine($" {{"); - EmitLine($" throw new UnexpectedMethodException(__repBase);"); - EmitLine($" }}"); - - if (method.ReturnType == typeof(void)) - { - // No need to further examine the reply. - } - else - { - // At this point, we have the reply method. Extract values from it. - if (!(Attribute(method.ReturnTypeCustomAttributes, typeof(AmqpFieldMappingAttribute)) is AmqpFieldMappingAttribute returnMapping)) - { - string fieldPrefix = IsAmqpClass(method.ReturnType) ? "_" : ""; - - // No field mapping --> it's assumed to be a struct to fill in. - EmitLine($" {method.ReturnType} __result = new {method.ReturnType}();"); - foreach (FieldInfo fi in method.ReturnType.GetFields()) - { - if (Attribute(fi, typeof(AmqpFieldMappingAttribute)) is AmqpFieldMappingAttribute returnFieldMapping) - { - EmitLine($" __result.{fi.Name} = __rep.{fieldPrefix}{returnFieldMapping.m_fieldName};"); - } - else - { - EmitLine($" __result.{fi.Name} = __rep.{fieldPrefix}{fi.Name};"); - } - } - EmitLine(" return __result;"); - } - else - { - // Field mapping --> return just the field we're interested in. - EmitLine($" return __rep._{returnMapping.m_fieldName};"); - } - } - } - - // All the IO and result-extraction has been done. Emit - // the method postamble. - - EmitLine(" }"); - } - - public void EmitAsynchronousHandlers(IList asynchronousHandlers) - { - string GetParameterString(ParameterInfo pi) - { - if (Attribute(pi, typeof(AmqpContentHeaderMappingAttribute)) != null) - { - return $"({pi.ParameterType}) cmd.Header"; - } - else if (Attribute(pi, typeof(AmqpContentBodyMappingAttribute)) != null) - { - return "cmd.Body"; - } - else if (Attribute(pi, typeof(AmqpContentBodyArrayMappingAttribute)) != null) - { - return "cmd.TakeoverPayload()"; - } - else - { - return $"__impl._{(!(Attribute(pi, typeof(AmqpFieldMappingAttribute)) is AmqpFieldMappingAttribute fieldMapping) ? pi.Name : fieldMapping.m_fieldName)}"; - } - - throw new NotImplementedException(); - } - - EmitLine(" public override bool DispatchAsynchronous(in IncomingCommand cmd) {"); - EmitLine(" switch ((cmd.Method.ProtocolClassId << 16) | cmd.Method.ProtocolMethodId)"); - EmitLine(" {"); - foreach (MethodInfo method in asynchronousHandlers) - { - string methodName = method.Name; - if (methodName.StartsWith("Handle")) - { - methodName = methodName.Substring(6); - } - - LookupAmqpMethod(method, methodName, out AmqpClass amqpClass, out AmqpMethod amqpMethod); - - string implClass = MangleMethodClass(amqpClass, amqpMethod); - - EmitLine($" case (ClassConstants.{MangleConstant(amqpClass.Name)} << 16) | {MangleClass(amqpClass.Name)}MethodConstants.{MangleConstant(amqpMethod.Name)}:"); - EmitLine(" {"); - ParameterInfo[] parameters = method.GetParameters(); - if (parameters.Length > 0) - { - EmitLine($" var __impl = ({implClass})cmd.Method;"); - EmitLine($" {method.Name}({string.Join(", ", parameters.Select(GetParameterString))});"); - } - else - { - EmitLine($" {method.Name}();"); - } - EmitLine(" return true;"); - EmitLine(" }"); - } - EmitLine(" default: return false;"); - EmitLine(" }"); - EmitLine(" }"); - } - } -} diff --git a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj index ebe5081ffb..2af20d6c4d 100755 --- a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj +++ b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj @@ -44,7 +44,6 @@ - diff --git a/projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs b/projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs index 386ee3ba79..81780480ca 100644 --- a/projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs +++ b/projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs @@ -222,7 +222,7 @@ public static AmqpTcpEndpoint Parse(string address) /// public static AmqpTcpEndpoint[] ParseMultiple(string addresses) { - string[] partsArr = addresses.Split(new[] {','}); + string[] partsArr = addresses.Split(','); var results = new List(); foreach (string partRaw in partsArr) { diff --git a/projects/RabbitMQ.Client/client/api/ExternalMechanism.cs b/projects/RabbitMQ.Client/client/api/ExternalMechanism.cs index 361c072a89..f51214ebcc 100644 --- a/projects/RabbitMQ.Client/client/api/ExternalMechanism.cs +++ b/projects/RabbitMQ.Client/client/api/ExternalMechanism.cs @@ -29,6 +29,8 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- +using System; + namespace RabbitMQ.Client { public class ExternalMechanism : IAuthMechanism @@ -38,7 +40,7 @@ public class ExternalMechanism : IAuthMechanism /// public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory) { - return new byte[0]; + return Array.Empty(); } } } diff --git a/projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs b/projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs index b8d9746c19..dfda1c75d2 100644 --- a/projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs +++ b/projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs @@ -40,12 +40,12 @@ public static T SelectOne(this IEndpointResolver resolver, Func(); - foreach(AmqpTcpEndpoint ep in resolver.All()) + foreach (AmqpTcpEndpoint ep in resolver.All()) { try { t = selector(ep); - if(t.Equals(default(T)) == false) + if (t.Equals(default(T)) == false) { return t; } @@ -56,7 +56,7 @@ public static T SelectOne(this IEndpointResolver resolver, Func 0) + if (Object.Equals(t, default(T)) && exceptions.Count > 0) { throw new AggregateException(exceptions); } @@ -64,4 +64,4 @@ public static T SelectOne(this IEndpointResolver resolver, Func method, will not throw /// or or any other during closing model. /// - [AmqpMethodDoNotImplement(null)] void Abort(); /// @@ -170,7 +168,6 @@ public interface IModel : IDisposable /// A message indicating the reason for closing the model /// /// - [AmqpMethodDoNotImplement(null)] void Abort(ushort replyCode, string replyText); /// @@ -181,7 +178,6 @@ public interface IModel : IDisposable /// /// Delete a Basic content-class consumer. /// - [AmqpMethodDoNotImplement(null)] void BasicCancel(string consumerTag); /// @@ -191,7 +187,6 @@ public interface IModel : IDisposable void BasicCancelNoWait(string consumerTag); /// Start a Basic content-class consumer. - [AmqpMethodDoNotImplement(null)] string BasicConsume( string queue, bool autoAck, @@ -206,7 +201,6 @@ string BasicConsume( /// one is available; returns null if the server answers that /// no messages are currently available. See also . /// - [AmqpMethodDoNotImplement(null)] BasicGetResult BasicGet(string queue, bool autoAck); /// Reject one or more delivered message(s). @@ -220,9 +214,7 @@ string BasicConsume( /// Routing key must be shorter than 255 bytes. /// /// - [AmqpMethodDoNotImplement(null)] - void BasicPublish(string exchange, string routingKey, bool mandatory, - IBasicProperties basicProperties, ReadOnlyMemory body); + void BasicPublish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory body); /// /// Configures QoS parameters of the Basic content-class. @@ -233,7 +225,6 @@ void BasicPublish(string exchange, string routingKey, bool mandatory, /// Indicates that a consumer has recovered. /// Deprecated. Should not be used. /// - [AmqpMethodDoNotImplement(null)] void BasicRecover(bool requeue); /// @@ -252,7 +243,6 @@ void BasicPublish(string exchange, string routingKey, bool mandatory, /// operation to complete. This method will not return to the /// caller until the shutdown is complete. /// - [AmqpMethodDoNotImplement(null)] void Close(); /// Close this session. @@ -267,31 +257,26 @@ void BasicPublish(string exchange, string routingKey, bool mandatory, /// A message indicating the reason for closing the model /// /// - [AmqpMethodDoNotImplement(null)] void Close(ushort replyCode, string replyText); /// /// Enable publisher acknowledgements. /// - [AmqpMethodDoNotImplement(null)] void ConfirmSelect(); /// /// Creates a BasicPublishBatch instance /// - [AmqpMethodDoNotImplement(null)] IBasicPublishBatch CreateBasicPublishBatch(); /// /// Creates a BasicPublishBatch instance /// - [AmqpMethodDoNotImplement(null)] IBasicPublishBatch CreateBasicPublishBatch(int sizeHint); /// /// Construct a completely empty content header for use with the Basic content class. /// - [AmqpContentHeaderFactory("basic")] IBasicProperties CreateBasicProperties(); /// @@ -301,8 +286,7 @@ void BasicPublish(string exchange, string routingKey, bool mandatory, /// /// Routing key must be shorter than 255 bytes. /// - /// - [AmqpMethodDoNotImplement(null)] + /// void ExchangeBind(string destination, string source, string routingKey, IDictionary arguments); /// @@ -312,25 +296,21 @@ void BasicPublish(string exchange, string routingKey, bool mandatory, /// /// Routing key must be shorter than 255 bytes. /// - /// - void ExchangeBindNoWait(string destination, string source, string routingKey, - IDictionary arguments); + /// + void ExchangeBindNoWait(string destination, string source, string routingKey, IDictionary arguments); /// Declare an exchange. /// /// The exchange is declared non-passive and non-internal. /// The "nowait" option is not exercised. /// - [AmqpMethodDoNotImplement(null)] - void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, - IDictionary arguments); + void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, IDictionary arguments); /// /// Same as ExchangeDeclare but sets nowait to true and returns void (as there /// will be no response from the server). /// - void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool autoDelete, - IDictionary arguments); + void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool autoDelete, IDictionary arguments); /// /// Do a passive exchange declaration. @@ -341,13 +321,11 @@ void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool auto /// It will do nothing if the exchange already exists and result /// in a channel-level protocol exception (channel closure) if not. /// - [AmqpMethodDoNotImplement(null)] void ExchangeDeclarePassive(string exchange); /// /// Delete an exchange. /// - [AmqpMethodDoNotImplement(null)] void ExchangeDelete(string exchange, bool ifUnused); /// @@ -361,11 +339,7 @@ void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool auto /// /// Routing key must be shorter than 255 bytes. /// - [AmqpMethodDoNotImplement(null)] - void ExchangeUnbind(string destination, - string source, - string routingKey, - IDictionary arguments); + void ExchangeUnbind(string destination, string source, string routingKey, IDictionary arguments); /// /// Like ExchangeUnbind but sets nowait to true. @@ -375,9 +349,7 @@ void ExchangeUnbind(string destination, /// Routing key must be shorter than 255 bytes. /// /// - [AmqpMethodDoNotImplement(null)] - void ExchangeUnbindNoWait(string destination, string source, string routingKey, - IDictionary arguments); + void ExchangeUnbindNoWait(string destination, string source, string routingKey, IDictionary arguments); /// /// Bind a queue to an exchange. @@ -386,8 +358,7 @@ void ExchangeUnbindNoWait(string destination, string source, string routingKey, /// /// Routing key must be shorter than 255 bytes. /// - /// - [AmqpMethodDoNotImplement(null)] + /// void QueueBind(string queue, string exchange, string routingKey, IDictionary arguments); /// Same as QueueBind but sets nowait parameter to true. @@ -395,21 +366,17 @@ void ExchangeUnbindNoWait(string destination, string source, string routingKey, /// /// Routing key must be shorter than 255 bytes. /// - /// + /// void QueueBindNoWait(string queue, string exchange, string routingKey, IDictionary arguments); /// Declare a queue. - [AmqpMethodDoNotImplement(null)] - QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, - bool autoDelete, IDictionary arguments); + QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary arguments); /// /// Same as QueueDeclare but sets nowait to true and returns void (as there /// will be no response from the server). /// - void QueueDeclareNoWait(string queue, bool durable, - bool exclusive, bool autoDelete, - IDictionary arguments); + void QueueDeclareNoWait(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary arguments); /// Declare a queue passively. /// @@ -417,7 +384,6 @@ void QueueDeclareNoWait(string queue, bool durable, ///non-exclusive, and non-autodelete, with no arguments. ///The queue is declared passively; i.e. only check if it exists. /// - [AmqpMethodDoNotImplement(null)] QueueDeclareOk QueueDeclarePassive(string queue); /// @@ -426,7 +392,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// an exception will be closed with an exception. /// /// The name of the queue - [AmqpMethodDoNotImplement(null)] uint MessageCount(string queue); /// @@ -435,7 +400,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// an exception will be closed with an exception. /// /// The name of the queue - [AmqpMethodDoNotImplement(null)] uint ConsumerCount(string queue); /// @@ -445,7 +409,6 @@ void QueueDeclareNoWait(string queue, bool durable, ///Returns the number of messages purged during queue deletion. /// uint.MaxValue. /// - [AmqpMethodDoNotImplement(null)] uint QueueDelete(string queue, bool ifUnused, bool ifEmpty); /// @@ -460,7 +423,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// /// Returns the number of messages purged. /// - [AmqpMethodDoNotImplement(null)] uint QueuePurge(string queue); /// @@ -470,7 +432,7 @@ void QueueDeclareNoWait(string queue, bool durable, /// /// Routing key must be shorter than 255 bytes. /// - /// + /// void QueueUnbind(string queue, string exchange, string routingKey, IDictionary arguments); /// @@ -496,7 +458,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// all the messages were ack'd (and none were nack'd). Note, /// throws an exception when called on a non-Confirm channel. /// - [AmqpMethodDoNotImplement(null)] bool WaitForConfirms(); /// @@ -512,7 +473,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// all the messages were ack'd (and none were nack'd). Note, /// throws an exception when called on a non-Confirm channel. /// - [AmqpMethodDoNotImplement(null)] bool WaitForConfirms(TimeSpan timeout); /// @@ -531,7 +491,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// all the messages were ack'd (and none were nack'd). Note, /// throws an exception when called on a non-Confirm channel. /// - [AmqpMethodDoNotImplement(null)] bool WaitForConfirms(TimeSpan timeout, out bool timedOut); /// @@ -542,7 +501,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// been ack'd by the broker. If a nack is received, throws an /// OperationInterrupedException exception immediately. /// - [AmqpMethodDoNotImplement(null)] void WaitForConfirmsOrDie(); /// @@ -553,7 +511,6 @@ void QueueDeclareNoWait(string queue, bool durable, /// been ack'd by the broker. If a nack is received or the timeout /// elapses, throws an OperationInterrupedException exception immediately. /// - [AmqpMethodDoNotImplement(null)] void WaitForConfirmsOrDie(TimeSpan timeout); /// diff --git a/projects/RabbitMQ.Client/client/events/AsyncEventHandler.cs b/projects/RabbitMQ.Client/client/events/AsyncEventHandler.cs index 877779b15d..061a59744e 100644 --- a/projects/RabbitMQ.Client/client/events/AsyncEventHandler.cs +++ b/projects/RabbitMQ.Client/client/events/AsyncEventHandler.cs @@ -9,9 +9,9 @@ internal static class AsyncEventHandlerExtensions { public static async Task InvokeAsync(this AsyncEventHandler eventHandler, object sender, TEvent @event) where TEvent : EventArgs { - if(eventHandler != null) + if (eventHandler != null) { - foreach(AsyncEventHandler handlerInstance in eventHandler.GetInvocationList()) + foreach (AsyncEventHandler handlerInstance in eventHandler.GetInvocationList()) { await handlerInstance(sender, @event).ConfigureAwait(false); } diff --git a/projects/Apigen/apigen/AmqpClass.cs b/projects/RabbitMQ.Client/client/framing/BasicAck.cs similarity index 55% rename from projects/Apigen/apigen/AmqpClass.cs rename to projects/RabbitMQ.Client/client/framing/BasicAck.cs index 559b4a3e5a..c6d2e581c8 100644 --- a/projects/Apigen/apigen/AmqpClass.cs +++ b/projects/RabbitMQ.Client/client/framing/BasicAck.cs @@ -29,51 +29,44 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- -using System.Collections.Generic; -using System.Xml; - -namespace RabbitMQ.Client.Apigen +namespace RabbitMQ.Client.Framing.Impl { - public class AmqpClass: AmqpEntity { - public IList m_Methods; - public IList m_Fields; + internal sealed class BasicAck : Client.Impl.MethodBase + { + public ulong _deliveryTag; + public bool _multiple; + + public BasicAck() + { + } - public AmqpClass(XmlNode n) - : base(n) + public BasicAck(ulong DeliveryTag, bool Multiple) { - m_Methods = new List(); - foreach (XmlNode m in n.SelectNodes("method")) { - m_Methods.Add(new AmqpMethod(m)); - } - m_Fields = new List(); - foreach (XmlNode f in n.SelectNodes("field")) { - m_Fields.Add(new AmqpField(f)); - } + _deliveryTag = DeliveryTag; + _multiple = Multiple; } - public int Index { - get { - return GetInt("@index"); - } + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Ack; + public override string ProtocolMethodName => "basic.ack"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _deliveryTag = reader.ReadLonglong(); + _multiple = reader.ReadBit(); } - public bool NeedsProperties { - get { - foreach (AmqpMethod m in m_Methods) { - if (m.HasContent) return true; - } - return false; - } + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLonglong(_deliveryTag); + writer.WriteBit(_multiple); + writer.EndBits(); } - public AmqpMethod MethodNamed(string name) { - foreach (AmqpMethod m in m_Methods) - { - if (m.Name == name) { - return m; - } - } - return null; + public override int GetRequiredBufferSize() + { + return 8 + 1; } } } diff --git a/projects/RabbitMQ.Client/client/framing/BasicCancel.cs b/projects/RabbitMQ.Client/client/framing/BasicCancel.cs new file mode 100644 index 0000000000..6ac5a5d5bb --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicCancel.cs @@ -0,0 +1,76 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicCancel : Client.Impl.MethodBase + { + public string _consumerTag; + public bool _nowait; + + public BasicCancel() + { + } + + public BasicCancel(string ConsumerTag, bool Nowait) + { + _consumerTag = ConsumerTag; + _nowait = Nowait; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Cancel; + public override string ProtocolMethodName => "basic.cancel"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _consumerTag = reader.ReadShortstr(); + _nowait = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_consumerTag); + writer.WriteBit(_nowait); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 1; // bytes for length of _consumerTag, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_consumerTag); // _consumerTag in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicCancelOk.cs b/projects/RabbitMQ.Client/client/framing/BasicCancelOk.cs new file mode 100644 index 0000000000..4363c1ae5d --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicCancelOk.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicCancelOk : Client.Impl.MethodBase + { + public string _consumerTag; + + public BasicCancelOk() + { + } + + public BasicCancelOk(string ConsumerTag) + { + _consumerTag = ConsumerTag; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.CancelOk; + public override string ProtocolMethodName => "basic.cancel-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _consumerTag = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_consumerTag); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _consumerTag + bufferSize += Encoding.UTF8.GetByteCount(_consumerTag); // _consumerTag in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicConsume.cs b/projects/RabbitMQ.Client/client/framing/BasicConsume.cs new file mode 100644 index 0000000000..a46afd86c4 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicConsume.cs @@ -0,0 +1,104 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicConsume : MethodBase + { + public ushort _reserved1; + public string _queue; + public string _consumerTag; + public bool _noLocal; + public bool _noAck; + public bool _exclusive; + public bool _nowait; + public IDictionary _arguments; + + public BasicConsume() + { + } + + public BasicConsume(ushort Reserved1, string Queue, string ConsumerTag, bool NoLocal, bool NoAck, bool Exclusive, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _queue = Queue; + _consumerTag = ConsumerTag; + _noLocal = NoLocal; + _noAck = NoAck; + _exclusive = Exclusive; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Consume; + public override string ProtocolMethodName => "basic.consume"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _consumerTag = reader.ReadShortstr(); + _noLocal = reader.ReadBit(); + _noAck = reader.ReadBit(); + _exclusive = reader.ReadBit(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteShortstr(_consumerTag); + writer.WriteBit(_noLocal); + writer.WriteBit(_noAck); + writer.WriteBit(_exclusive); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1; // bytes for _reserved1, length of _queue, length of _consumerTag, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + bufferSize += Encoding.UTF8.GetByteCount(_consumerTag); // _consumerTag in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicConsumeOk.cs b/projects/RabbitMQ.Client/client/framing/BasicConsumeOk.cs new file mode 100644 index 0000000000..46c7f50950 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicConsumeOk.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicConsumeOk : Client.Impl.MethodBase + { + public string _consumerTag; + + public BasicConsumeOk() + { + } + + public BasicConsumeOk(string ConsumerTag) + { + _consumerTag = ConsumerTag; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.ConsumeOk; + public override string ProtocolMethodName => "basic.consume-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _consumerTag = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_consumerTag); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _consumerTag + bufferSize += Encoding.UTF8.GetByteCount(_consumerTag); // _consumerTag in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicDeliver.cs b/projects/RabbitMQ.Client/client/framing/BasicDeliver.cs new file mode 100644 index 0000000000..5758a78f78 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicDeliver.cs @@ -0,0 +1,90 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicDeliver : Client.Impl.MethodBase + { + public string _consumerTag; + public ulong _deliveryTag; + public bool _redelivered; + public string _exchange; + public string _routingKey; + + public BasicDeliver() + { + } + + public BasicDeliver(string ConsumerTag, ulong DeliveryTag, bool Redelivered, string Exchange, string RoutingKey) + { + _consumerTag = ConsumerTag; + _deliveryTag = DeliveryTag; + _redelivered = Redelivered; + _exchange = Exchange; + _routingKey = RoutingKey; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Deliver; + public override string ProtocolMethodName => "basic.deliver"; + public override bool HasContent => true; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _consumerTag = reader.ReadShortstr(); + _deliveryTag = reader.ReadLonglong(); + _redelivered = reader.ReadBit(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_consumerTag); + writer.WriteLonglong(_deliveryTag); + writer.WriteBit(_redelivered); + writer.EndBits(); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 8 + 1 + 1 + 1; // bytes for length of _consumerTag, _deliveryTag, bit fields, length of _exchange, length of _routingKey + bufferSize += Encoding.UTF8.GetByteCount(_consumerTag); // _consumerTag in bytes + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicGet.cs b/projects/RabbitMQ.Client/client/framing/BasicGet.cs new file mode 100644 index 0000000000..e8a2f6e24d --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicGet.cs @@ -0,0 +1,80 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicGet : Client.Impl.MethodBase + { + public ushort _reserved1; + public string _queue; + public bool _noAck; + + public BasicGet() + { + } + + public BasicGet(ushort Reserved1, string Queue, bool NoAck) + { + _reserved1 = Reserved1; + _queue = Queue; + _noAck = NoAck; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Get; + public override string ProtocolMethodName => "basic.get"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _noAck = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteBit(_noAck); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1; // bytes for _reserved1, length of _queue, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicGetEmpty.cs b/projects/RabbitMQ.Client/client/framing/BasicGetEmpty.cs new file mode 100644 index 0000000000..089253c0ee --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicGetEmpty.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicGetEmpty : Client.Impl.MethodBase + { + public string _reserved1; + + public BasicGetEmpty() + { + } + + public BasicGetEmpty(string Reserved1) + { + _reserved1 = Reserved1; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.GetEmpty; + public override string ProtocolMethodName => "basic.get-empty"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_reserved1); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _reserved1 + bufferSize += Encoding.UTF8.GetByteCount(_reserved1); // _reserved1 in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicGetOk.cs b/projects/RabbitMQ.Client/client/framing/BasicGetOk.cs new file mode 100644 index 0000000000..9523206da7 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicGetOk.cs @@ -0,0 +1,89 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicGetOk : Client.Impl.MethodBase + { + public ulong _deliveryTag; + public bool _redelivered; + public string _exchange; + public string _routingKey; + public uint _messageCount; + + public BasicGetOk() + { + } + + public BasicGetOk(ulong DeliveryTag, bool Redelivered, string Exchange, string RoutingKey, uint MessageCount) + { + _deliveryTag = DeliveryTag; + _redelivered = Redelivered; + _exchange = Exchange; + _routingKey = RoutingKey; + _messageCount = MessageCount; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.GetOk; + public override string ProtocolMethodName => "basic.get-ok"; + public override bool HasContent => true; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _deliveryTag = reader.ReadLonglong(); + _redelivered = reader.ReadBit(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _messageCount = reader.ReadLong(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLonglong(_deliveryTag); + writer.WriteBit(_redelivered); + writer.EndBits(); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + writer.WriteLong(_messageCount); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 8 + 1 + 1 + 1 + 4; // bytes for _deliveryTag, bit fields, length of _exchange, length of _routingKey, _messageCount + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/BasicMethodConstants.cs new file mode 100644 index 0000000000..32008fc9b1 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicMethodConstants.cs @@ -0,0 +1,55 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class BasicMethodConstants + { + internal const ushort Qos = 10; + internal const ushort QosOk = 11; + internal const ushort Consume = 20; + internal const ushort ConsumeOk = 21; + internal const ushort Cancel = 30; + internal const ushort CancelOk = 31; + internal const ushort Publish = 40; + internal const ushort Return = 50; + internal const ushort Deliver = 60; + internal const ushort Get = 70; + internal const ushort GetOk = 71; + internal const ushort GetEmpty = 72; + internal const ushort Ack = 80; + internal const ushort Reject = 90; + internal const ushort RecoverAsync = 100; + internal const ushort Recover = 110; + internal const ushort RecoverOk = 111; + internal const ushort Nack = 120; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicNack.cs b/projects/RabbitMQ.Client/client/framing/BasicNack.cs new file mode 100644 index 0000000000..cfe44251fa --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicNack.cs @@ -0,0 +1,76 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicNack : Client.Impl.MethodBase + { + public ulong _deliveryTag; + public bool _multiple; + public bool _requeue; + + public BasicNack() + { + } + + public BasicNack(ulong DeliveryTag, bool Multiple, bool Requeue) + { + _deliveryTag = DeliveryTag; + _multiple = Multiple; + _requeue = Requeue; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Nack; + public override string ProtocolMethodName => "basic.nack"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _deliveryTag = reader.ReadLonglong(); + _multiple = reader.ReadBit(); + _requeue = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLonglong(_deliveryTag); + writer.WriteBit(_multiple); + writer.WriteBit(_requeue); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 8 + 1; // bytes for _deliveryTag, bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicProperties.cs b/projects/RabbitMQ.Client/client/framing/BasicProperties.cs new file mode 100644 index 0000000000..702cbb47ac --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicProperties.cs @@ -0,0 +1,289 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing +{ + /// Autogenerated type. AMQP specification content header properties for content class "basic" + internal sealed class BasicProperties : RabbitMQ.Client.Impl.BasicProperties + { + private string _contentType; + private string _contentEncoding; + private IDictionary _headers; + private byte _deliveryMode; + private byte _priority; + private string _correlationId; + private string _replyTo; + private string _expiration; + private string _messageId; + private AmqpTimestamp _timestamp; + private string _type; + private string _userId; + private string _appId; + private string _clusterId; + + public override string ContentType + { + get => _contentType; + set => _contentType = value; + } + + public override string ContentEncoding + { + get => _contentEncoding; + set => _contentEncoding = value; + } + + public override IDictionary Headers + { + get => _headers; + set => _headers = value; + } + + public override byte DeliveryMode + { + get => _deliveryMode; + set => _deliveryMode = value; + } + + public override byte Priority + { + get => _priority; + set => _priority = value; + } + + public override string CorrelationId + { + get => _correlationId; + set => _correlationId = value; + } + + public override string ReplyTo + { + get => _replyTo; + set => _replyTo = value; + } + + public override string Expiration + { + get => _expiration; + set => _expiration = value; + } + + public override string MessageId + { + get => _messageId; + set => _messageId = value; + } + + public override AmqpTimestamp Timestamp + { + get => _timestamp; + set => _timestamp = value; + } + + public override string Type + { + get => _type; + set => _type = value; + } + + public override string UserId + { + get => _userId; + set => _userId = value; + } + + public override string AppId + { + get => _appId; + set => _appId = value; + } + + public override string ClusterId + { + get => _clusterId; + set => _clusterId = value; + } + + public override void ClearContentType() => _contentType = default; + + public override void ClearContentEncoding() => _contentEncoding = default; + + public override void ClearHeaders() => _headers = default; + + public override void ClearDeliveryMode() => _deliveryMode = default; + + public override void ClearPriority() => _priority = default; + + public override void ClearCorrelationId() => _correlationId = default; + + public override void ClearReplyTo() => _replyTo = default; + + public override void ClearExpiration() => _expiration = default; + + public override void ClearMessageId() => _messageId = default; + + public override void ClearTimestamp() => _timestamp = default; + + public override void ClearType() => _type = default; + + public override void ClearUserId() => _userId = default; + + public override void ClearAppId() => _appId = default; + + public override void ClearClusterId() => _clusterId = default; + + public override bool IsContentTypePresent() => _contentType != default; + + public override bool IsContentEncodingPresent() => _contentEncoding != default; + + public override bool IsHeadersPresent() => _headers != default; + + public override bool IsDeliveryModePresent() => _deliveryMode != default; + + public override bool IsPriorityPresent() => _priority != default; + + public override bool IsCorrelationIdPresent() => _correlationId != default; + + public override bool IsReplyToPresent() => _replyTo != default; + + public override bool IsExpirationPresent() => _expiration != default; + + public override bool IsMessageIdPresent() => _messageId != default; + + public override bool IsTimestampPresent() => _timestamp != default; + + public override bool IsTypePresent() => _type != default; + + public override bool IsUserIdPresent() => _userId != default; + + public override bool IsAppIdPresent() => _appId != default; + + public override bool IsClusterIdPresent() => _clusterId != default; + + public BasicProperties() + { + } + + public override ushort ProtocolClassId => 60; + public override string ProtocolClassName => "basic"; + + internal override void ReadPropertiesFrom(ref ContentHeaderPropertyReader reader) + { + var contentType_present = reader.ReadPresence(); + var contentEncoding_present = reader.ReadPresence(); + var headers_present = reader.ReadPresence(); + var deliveryMode_present = reader.ReadPresence(); + var priority_present = reader.ReadPresence(); + var correlationId_present = reader.ReadPresence(); + var replyTo_present = reader.ReadPresence(); + var expiration_present = reader.ReadPresence(); + var messageId_present = reader.ReadPresence(); + var timestamp_present = reader.ReadPresence(); + var type_present = reader.ReadPresence(); + var userId_present = reader.ReadPresence(); + var appId_present = reader.ReadPresence(); + var clusterId_present = reader.ReadPresence(); + reader.FinishPresence(); + if (contentType_present) { _contentType = reader.ReadShortstr(); } + if (contentEncoding_present) { _contentEncoding = reader.ReadShortstr(); } + if (headers_present) { _headers = reader.ReadTable(); } + if (deliveryMode_present) { _deliveryMode = reader.ReadOctet(); } + if (priority_present) { _priority = reader.ReadOctet(); } + if (correlationId_present) { _correlationId = reader.ReadShortstr(); } + if (replyTo_present) { _replyTo = reader.ReadShortstr(); } + if (expiration_present) { _expiration = reader.ReadShortstr(); } + if (messageId_present) { _messageId = reader.ReadShortstr(); } + if (timestamp_present) { _timestamp = reader.ReadTimestamp(); } + if (type_present) { _type = reader.ReadShortstr(); } + if (userId_present) { _userId = reader.ReadShortstr(); } + if (appId_present) { _appId = reader.ReadShortstr(); } + if (clusterId_present) { _clusterId = reader.ReadShortstr(); } + } + + internal override void WritePropertiesTo(ref ContentHeaderPropertyWriter writer) + { + writer.WritePresence(IsContentTypePresent()); + writer.WritePresence(IsContentEncodingPresent()); + writer.WritePresence(IsHeadersPresent()); + writer.WritePresence(IsDeliveryModePresent()); + writer.WritePresence(IsPriorityPresent()); + writer.WritePresence(IsCorrelationIdPresent()); + writer.WritePresence(IsReplyToPresent()); + writer.WritePresence(IsExpirationPresent()); + writer.WritePresence(IsMessageIdPresent()); + writer.WritePresence(IsTimestampPresent()); + writer.WritePresence(IsTypePresent()); + writer.WritePresence(IsUserIdPresent()); + writer.WritePresence(IsAppIdPresent()); + writer.WritePresence(IsClusterIdPresent()); + writer.FinishPresence(); + if (IsContentTypePresent()) { writer.WriteShortstr(_contentType); } + if (IsContentEncodingPresent()) { writer.WriteShortstr(_contentEncoding); } + if (IsHeadersPresent()) { writer.WriteTable(_headers); } + if (IsDeliveryModePresent()) { writer.WriteOctet(_deliveryMode); } + if (IsPriorityPresent()) { writer.WriteOctet(_priority); } + if (IsCorrelationIdPresent()) { writer.WriteShortstr(_correlationId); } + if (IsReplyToPresent()) { writer.WriteShortstr(_replyTo); } + if (IsExpirationPresent()) { writer.WriteShortstr(_expiration); } + if (IsMessageIdPresent()) { writer.WriteShortstr(_messageId); } + if (IsTimestampPresent()) { writer.WriteTimestamp(_timestamp); } + if (IsTypePresent()) { writer.WriteShortstr(_type); } + if (IsUserIdPresent()) { writer.WriteShortstr(_userId); } + if (IsAppIdPresent()) { writer.WriteShortstr(_appId); } + if (IsClusterIdPresent()) { writer.WriteShortstr(_clusterId); } + } + + public override int GetRequiredPayloadBufferSize() + { + int bufferSize = 2; // number of presence fields (14) in 2 bytes blocks + if (IsContentTypePresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_contentType); } // _contentType in bytes + if (IsContentEncodingPresent()) { bufferSize += 1 + Encoding.UTF8.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 + Encoding.UTF8.GetByteCount(_correlationId); } // _correlationId in bytes + if (IsReplyToPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_replyTo); } // _replyTo in bytes + if (IsExpirationPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_expiration); } // _expiration in bytes + if (IsMessageIdPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_messageId); } // _messageId in bytes + if (IsTimestampPresent()) { bufferSize += 8; } // _timestamp in bytes + if (IsTypePresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_type); } // _type in bytes + if (IsUserIdPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_userId); } // _userId in bytes + if (IsAppIdPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_appId); } // _appId in bytes + if (IsClusterIdPresent()) { bufferSize += 1 + Encoding.UTF8.GetByteCount(_clusterId); } // _clusterId in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicPublish.cs b/projects/RabbitMQ.Client/client/framing/BasicPublish.cs new file mode 100644 index 0000000000..e7a0f949c4 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicPublish.cs @@ -0,0 +1,89 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicPublish : Client.Impl.MethodBase + { + public ushort _reserved1; + public string _exchange; + public string _routingKey; + public bool _mandatory; + public bool _immediate; + + public BasicPublish() + { + } + + public BasicPublish(ushort Reserved1, string Exchange, string RoutingKey, bool Mandatory, bool Immediate) + { + _reserved1 = Reserved1; + _exchange = Exchange; + _routingKey = RoutingKey; + _mandatory = Mandatory; + _immediate = Immediate; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Publish; + public override string ProtocolMethodName => "basic.publish"; + public override bool HasContent => true; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _mandatory = reader.ReadBit(); + _immediate = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + writer.WriteBit(_mandatory); + writer.WriteBit(_immediate); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1; // bytes for _reserved1, length of _exchange, length of _routingKey, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicQos.cs b/projects/RabbitMQ.Client/client/framing/BasicQos.cs new file mode 100644 index 0000000000..f90b7da81e --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicQos.cs @@ -0,0 +1,76 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicQos : Client.Impl.MethodBase + { + public uint _prefetchSize; + public ushort _prefetchCount; + public bool _global; + + public BasicQos() + { + } + + public BasicQos(uint PrefetchSize, ushort PrefetchCount, bool Global) + { + _prefetchSize = PrefetchSize; + _prefetchCount = PrefetchCount; + _global = Global; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Qos; + public override string ProtocolMethodName => "basic.qos"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _prefetchSize = reader.ReadLong(); + _prefetchCount = reader.ReadShort(); + _global = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLong(_prefetchSize); + writer.WriteShort(_prefetchCount); + writer.WriteBit(_global); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 4 + 2 + 1; // bytes for _prefetchSize, _prefetchCount, bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicQosOk.cs b/projects/RabbitMQ.Client/client/framing/BasicQosOk.cs new file mode 100644 index 0000000000..14f8404453 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicQosOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicQosOk : Client.Impl.MethodBase + { + public BasicQosOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.QosOk; + public override string ProtocolMethodName => "basic.qos-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/Apigen/apigen/AmqpMethod.cs b/projects/RabbitMQ.Client/client/framing/BasicRecover.cs similarity index 59% rename from projects/Apigen/apigen/AmqpMethod.cs rename to projects/RabbitMQ.Client/client/framing/BasicRecover.cs index 87701c912a..bd764e9c91 100644 --- a/projects/Apigen/apigen/AmqpMethod.cs +++ b/projects/RabbitMQ.Client/client/framing/BasicRecover.cs @@ -29,44 +29,40 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- -using System.Collections.Generic; -using System.Xml; - -namespace RabbitMQ.Client.Apigen +namespace RabbitMQ.Client.Framing.Impl { - public class AmqpMethod: AmqpEntity { - public IList m_Fields; - public IList m_ResponseMethods; + internal sealed class BasicRecover : Client.Impl.MethodBase + { + public bool _requeue; + + public BasicRecover() + { + } - public AmqpMethod(XmlNode n) - : base(n) + public BasicRecover(bool Requeue) { - m_Fields = new List(); - foreach (XmlNode f in n.SelectNodes("field")) { - m_Fields.Add(new AmqpField(f)); - } - m_ResponseMethods = new List(); - foreach (XmlNode r in n.SelectNodes("response")) { - m_ResponseMethods.Add(Apigen.GetString(r, "@name")); - } + _requeue = Requeue; } - public bool HasContent { - get { - return GetString("@content", null) != null; - } + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Recover; + public override string ProtocolMethodName => "basic.recover"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _requeue = reader.ReadBit(); } - public bool IsSimpleRpcRequest { - get { - return m_ResponseMethods.Count == 1; - } + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteBit(_requeue); + writer.EndBits(); } - public int Index { - get { - return GetInt("@index"); - } + public override int GetRequiredBufferSize() + { + return 1; // bytes for bit fields } } } diff --git a/projects/RabbitMQ.Client/client/framing/BasicRecoverAsync.cs b/projects/RabbitMQ.Client/client/framing/BasicRecoverAsync.cs new file mode 100644 index 0000000000..2fba723682 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicRecoverAsync.cs @@ -0,0 +1,68 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicRecoverAsync : Client.Impl.MethodBase + { + public bool _requeue; + + public BasicRecoverAsync() + { + } + + public BasicRecoverAsync(bool Requeue) + { + _requeue = Requeue; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.RecoverAsync; + public override string ProtocolMethodName => "basic.recover-async"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _requeue = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteBit(_requeue); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 1; // bytes for bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicRecoverOk.cs b/projects/RabbitMQ.Client/client/framing/BasicRecoverOk.cs new file mode 100644 index 0000000000..a2c104bbe1 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicRecoverOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicRecoverOk : Client.Impl.MethodBase + { + public BasicRecoverOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.RecoverOk; + public override string ProtocolMethodName => "basic.recover-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicReject.cs b/projects/RabbitMQ.Client/client/framing/BasicReject.cs new file mode 100644 index 0000000000..e02e4551c0 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicReject.cs @@ -0,0 +1,72 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicReject : Client.Impl.MethodBase + { + public ulong _deliveryTag; + public bool _requeue; + + public BasicReject() + { + } + + public BasicReject(ulong DeliveryTag, bool Requeue) + { + _deliveryTag = DeliveryTag; + _requeue = Requeue; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Reject; + public override string ProtocolMethodName => "basic.reject"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _deliveryTag = reader.ReadLonglong(); + _requeue = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLonglong(_deliveryTag); + writer.WriteBit(_requeue); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 8 + 1; // bytes for _deliveryTag, bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/BasicReturn.cs b/projects/RabbitMQ.Client/client/framing/BasicReturn.cs new file mode 100644 index 0000000000..c271d88bad --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/BasicReturn.cs @@ -0,0 +1,85 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class BasicReturn : Client.Impl.MethodBase + { + public ushort _replyCode; + public string _replyText; + public string _exchange; + public string _routingKey; + + public BasicReturn() + { + } + + public BasicReturn(ushort ReplyCode, string ReplyText, string Exchange, string RoutingKey) + { + _replyCode = ReplyCode; + _replyText = ReplyText; + _exchange = Exchange; + _routingKey = RoutingKey; + } + + public override ushort ProtocolClassId => ClassConstants.Basic; + public override ushort ProtocolMethodId => BasicMethodConstants.Return; + public override string ProtocolMethodName => "basic.return"; + public override bool HasContent => true; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _replyCode = reader.ReadShort(); + _replyText = reader.ReadShortstr(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_replyCode); + writer.WriteShortstr(_replyText); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1; // bytes for _replyCode, length of _replyText, length of _exchange, length of _routingKey + bufferSize += Encoding.UTF8.GetByteCount(_replyText); // _replyText in bytes + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ChannelClose.cs b/projects/RabbitMQ.Client/client/framing/ChannelClose.cs new file mode 100644 index 0000000000..8c82a16e62 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelClose.cs @@ -0,0 +1,83 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelClose : Client.Impl.MethodBase + { + public ushort _replyCode; + public string _replyText; + public ushort _classId; + public ushort _methodId; + + public ChannelClose() + { + } + + public ChannelClose(ushort ReplyCode, string ReplyText, ushort ClassId, ushort MethodId) + { + _replyCode = ReplyCode; + _replyText = ReplyText; + _classId = ClassId; + _methodId = MethodId; + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.Close; + public override string ProtocolMethodName => "channel.close"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _replyCode = reader.ReadShort(); + _replyText = reader.ReadShortstr(); + _classId = reader.ReadShort(); + _methodId = reader.ReadShort(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_replyCode); + writer.WriteShortstr(_replyText); + writer.WriteShort(_classId); + writer.WriteShort(_methodId); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 2 + 2; // bytes for _replyCode, length of _replyText, _classId, _methodId + bufferSize += Encoding.UTF8.GetByteCount(_replyText); // _replyText in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ChannelCloseOk.cs b/projects/RabbitMQ.Client/client/framing/ChannelCloseOk.cs new file mode 100644 index 0000000000..1dc5601b9d --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelCloseOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelCloseOk : Client.Impl.MethodBase + { + public ChannelCloseOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.CloseOk; + public override string ProtocolMethodName => "channel.close-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ChannelFlow.cs b/projects/RabbitMQ.Client/client/framing/ChannelFlow.cs new file mode 100644 index 0000000000..7d92c2d1eb --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelFlow.cs @@ -0,0 +1,68 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelFlow : Client.Impl.MethodBase + { + public bool _active; + + public ChannelFlow() + { + } + + public ChannelFlow(bool Active) + { + _active = Active; + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.Flow; + public override string ProtocolMethodName => "channel.flow"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _active = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteBit(_active); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 1; // bytes for bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ChannelFlowOk.cs b/projects/RabbitMQ.Client/client/framing/ChannelFlowOk.cs new file mode 100644 index 0000000000..2a98104ad6 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelFlowOk.cs @@ -0,0 +1,69 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelFlowOk : Client.Impl.MethodBase + { + public bool _active; + + public ChannelFlowOk() + { + } + + public ChannelFlowOk(bool Active) + { + _active = Active; + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.FlowOk; + public override string ProtocolMethodName => "channel.flow-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _active = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteBit(_active); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for bit fields + return bufferSize; + } + } +} diff --git a/projects/Apigen/apigen/AmqpField.cs b/projects/RabbitMQ.Client/client/framing/ChannelMethodConstants.cs similarity index 72% rename from projects/Apigen/apigen/AmqpField.cs rename to projects/RabbitMQ.Client/client/framing/ChannelMethodConstants.cs index e86c6c1b21..b249e9e2b4 100644 --- a/projects/Apigen/apigen/AmqpField.cs +++ b/projects/RabbitMQ.Client/client/framing/ChannelMethodConstants.cs @@ -29,27 +29,15 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- -using System.Diagnostics; -using System.Xml; - -namespace RabbitMQ.Client.Apigen +namespace RabbitMQ.Client.Framing.Impl { - [DebuggerDisplay("{Domain,nq} {Name,nq}")] - public class AmqpField : AmqpEntity + internal static class ChannelMethodConstants { - public AmqpField(XmlNode n) : base(n) { } - - public string Domain - { - get - { - string result = GetString("@domain", ""); - if (result.Equals("")) - { - result = GetString("@type"); - } - return result; - } - } + internal const ushort Open = 10; + internal const ushort OpenOk = 11; + internal const ushort Flow = 20; + internal const ushort FlowOk = 21; + internal const ushort Close = 40; + internal const ushort CloseOk = 41; } } diff --git a/projects/RabbitMQ.Client/client/framing/ChannelOpen.cs b/projects/RabbitMQ.Client/client/framing/ChannelOpen.cs new file mode 100644 index 0000000000..45165638bd --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelOpen.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelOpen : Client.Impl.MethodBase + { + public string _reserved1; + + public ChannelOpen() + { + } + + public ChannelOpen(string Reserved1) + { + _reserved1 = Reserved1; + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.Open; + public override string ProtocolMethodName => "channel.open"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_reserved1); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _reserved1 + bufferSize += Encoding.UTF8.GetByteCount(_reserved1); // _reserved1 in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ChannelOpenOk.cs b/projects/RabbitMQ.Client/client/framing/ChannelOpenOk.cs new file mode 100644 index 0000000000..464a140059 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ChannelOpenOk.cs @@ -0,0 +1,69 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ChannelOpenOk : Client.Impl.MethodBase + { + public byte[] _reserved1; + + public ChannelOpenOk() + { + } + + public ChannelOpenOk(byte[] Reserved1) + { + _reserved1 = Reserved1; + } + + public override ushort ProtocolClassId => ClassConstants.Channel; + public override ushort ProtocolMethodId => ChannelMethodConstants.OpenOk; + public override string ProtocolMethodName => "channel.open-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadLongstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLongstr(_reserved1); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 4; // bytes for length of _reserved1 + bufferSize += _reserved1.Length; // _reserved1 in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ClassConstants.cs b/projects/RabbitMQ.Client/client/framing/ClassConstants.cs new file mode 100644 index 0000000000..af6b612ead --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ClassConstants.cs @@ -0,0 +1,44 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class ClassConstants + { + internal const ushort Connection = 10; + internal const ushort Channel = 20; + internal const ushort Exchange = 40; + internal const ushort Queue = 50; + internal const ushort Basic = 60; + internal const ushort Tx = 90; + internal const ushort Confirm = 85; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ClassId.cs b/projects/RabbitMQ.Client/client/framing/ClassId.cs new file mode 100644 index 0000000000..a29e7aa90c --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ClassId.cs @@ -0,0 +1,45 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal enum ClassId + { + Connection = 10, + Channel = 20, + Exchange = 40, + Queue = 50, + Basic = 60, + Tx = 90, + Confirm = 85, + Invalid = -1, + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConfirmMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/ConfirmMethodConstants.cs new file mode 100644 index 0000000000..26af360347 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConfirmMethodConstants.cs @@ -0,0 +1,39 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class ConfirmMethodConstants + { + internal const ushort Select = 10; + internal const ushort SelectOk = 11; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConfirmSelect.cs b/projects/RabbitMQ.Client/client/framing/ConfirmSelect.cs new file mode 100644 index 0000000000..a7af79ee48 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConfirmSelect.cs @@ -0,0 +1,68 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConfirmSelect : Client.Impl.MethodBase + { + public bool _nowait; + + public ConfirmSelect() + { + } + + public ConfirmSelect(bool Nowait) + { + _nowait = Nowait; + } + + public override ushort ProtocolClassId => ClassConstants.Confirm; + public override ushort ProtocolMethodId => ConfirmMethodConstants.Select; + public override string ProtocolMethodName => "confirm.select"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _nowait = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteBit(_nowait); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + return 1; // bytes for bit fields + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConfirmSelectOk.cs b/projects/RabbitMQ.Client/client/framing/ConfirmSelectOk.cs new file mode 100644 index 0000000000..52b058d676 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConfirmSelectOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConfirmSelectOk : Client.Impl.MethodBase + { + public ConfirmSelectOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Confirm; + public override ushort ProtocolMethodId => ConfirmMethodConstants.SelectOk; + public override string ProtocolMethodName => "confirm.select-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionBlocked.cs b/projects/RabbitMQ.Client/client/framing/ConnectionBlocked.cs new file mode 100644 index 0000000000..2517eced59 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionBlocked.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionBlocked : Client.Impl.MethodBase + { + public string _reason; + + public ConnectionBlocked() + { + } + + public ConnectionBlocked(string Reason) + { + _reason = Reason; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Blocked; + public override string ProtocolMethodName => "connection.blocked"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reason = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_reason); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _reason + bufferSize += Encoding.UTF8.GetByteCount(_reason); // _reason in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionClose.cs b/projects/RabbitMQ.Client/client/framing/ConnectionClose.cs new file mode 100644 index 0000000000..de431d5b82 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionClose.cs @@ -0,0 +1,83 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionClose : Client.Impl.MethodBase + { + public ushort _replyCode; + public string _replyText; + public ushort _classId; + public ushort _methodId; + + public ConnectionClose() + { + } + + public ConnectionClose(ushort ReplyCode, string ReplyText, ushort ClassId, ushort MethodId) + { + _replyCode = ReplyCode; + _replyText = ReplyText; + _classId = ClassId; + _methodId = MethodId; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Close; + public override string ProtocolMethodName => "connection.close"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _replyCode = reader.ReadShort(); + _replyText = reader.ReadShortstr(); + _classId = reader.ReadShort(); + _methodId = reader.ReadShort(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_replyCode); + writer.WriteShortstr(_replyText); + writer.WriteShort(_classId); + writer.WriteShort(_methodId); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 2 + 2; // bytes for _replyCode, length of _replyText, _classId, _methodId + bufferSize += Encoding.UTF8.GetByteCount(_replyText); // _replyText in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionCloseOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionCloseOk.cs new file mode 100644 index 0000000000..617761e07c --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionCloseOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionCloseOk : Client.Impl.MethodBase + { + public ConnectionCloseOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.CloseOk; + public override string ProtocolMethodName => "connection.close-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/ConnectionMethodConstants.cs new file mode 100644 index 0000000000..6ec63cf72b --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionMethodConstants.cs @@ -0,0 +1,51 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class ConnectionMethodConstants + { + internal const ushort Start = 10; + internal const ushort StartOk = 11; + internal const ushort Secure = 20; + internal const ushort SecureOk = 21; + internal const ushort Tune = 30; + internal const ushort TuneOk = 31; + internal const ushort Open = 40; + internal const ushort OpenOk = 41; + internal const ushort Close = 50; + internal const ushort CloseOk = 51; + internal const ushort Blocked = 60; + internal const ushort Unblocked = 61; + internal const ushort UpdateSecret = 70; + internal const ushort UpdateSecretOk = 71; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionOpen.cs b/projects/RabbitMQ.Client/client/framing/ConnectionOpen.cs new file mode 100644 index 0000000000..0c755d71d6 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionOpen.cs @@ -0,0 +1,81 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionOpen : Client.Impl.MethodBase + { + public string _virtualHost; + public string _reserved1; + public bool _reserved2; + + public ConnectionOpen() + { + } + + public ConnectionOpen(string VirtualHost, string Reserved1, bool Reserved2) + { + _virtualHost = VirtualHost; + _reserved1 = Reserved1; + _reserved2 = Reserved2; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Open; + public override string ProtocolMethodName => "connection.open"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _virtualHost = reader.ReadShortstr(); + _reserved1 = reader.ReadShortstr(); + _reserved2 = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_virtualHost); + writer.WriteShortstr(_reserved1); + writer.WriteBit(_reserved2); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 1 + 1; // bytes for length of _virtualHost, length of _reserved1, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_virtualHost); // _virtualHost in bytes + bufferSize += Encoding.UTF8.GetByteCount(_reserved1); // _reserved1 in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionOpenOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionOpenOk.cs new file mode 100644 index 0000000000..779a8c8254 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionOpenOk.cs @@ -0,0 +1,71 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionOpenOk : Client.Impl.MethodBase + { + public string _reserved1; + + public ConnectionOpenOk() + { + } + + public ConnectionOpenOk(string Reserved1) + { + _reserved1 = Reserved1; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.OpenOk; + public override string ProtocolMethodName => "connection.open-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_reserved1); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1; // bytes for length of _reserved1 + bufferSize += Encoding.UTF8.GetByteCount(_reserved1); // _reserved1 in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionSecure.cs b/projects/RabbitMQ.Client/client/framing/ConnectionSecure.cs new file mode 100644 index 0000000000..a70edebd9f --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionSecure.cs @@ -0,0 +1,69 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionSecure : Client.Impl.MethodBase + { + public byte[] _challenge; + + public ConnectionSecure() + { + } + + public ConnectionSecure(byte[] Challenge) + { + _challenge = Challenge; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Secure; + public override string ProtocolMethodName => "connection.secure"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _challenge = reader.ReadLongstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLongstr(_challenge); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 4; // bytes for length of _challenge + bufferSize += _challenge.Length; // _challenge in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionSecureOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionSecureOk.cs new file mode 100644 index 0000000000..21d39e4b40 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionSecureOk.cs @@ -0,0 +1,69 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionSecureOk : Client.Impl.MethodBase + { + public byte[] _response; + + public ConnectionSecureOk() + { + } + + public ConnectionSecureOk(byte[] Response) + { + _response = Response; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.SecureOk; + public override string ProtocolMethodName => "connection.secure-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _response = reader.ReadLongstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLongstr(_response); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 4; // bytes for length of _response + bufferSize += _response.Length; // _response in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionStart.cs b/projects/RabbitMQ.Client/client/framing/ConnectionStart.cs new file mode 100644 index 0000000000..4b44fa9002 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionStart.cs @@ -0,0 +1,90 @@ +// 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.Collections.Generic; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionStart : MethodBase + { + public byte _versionMajor; + public byte _versionMinor; + public IDictionary _serverProperties; + public byte[] _mechanisms; + public byte[] _locales; + + public ConnectionStart() + { + } + + public ConnectionStart(byte VersionMajor, byte VersionMinor, IDictionary ServerProperties, byte[] Mechanisms, byte[] Locales) + { + _versionMajor = VersionMajor; + _versionMinor = VersionMinor; + _serverProperties = ServerProperties; + _mechanisms = Mechanisms; + _locales = Locales; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Start; + public override string ProtocolMethodName => "connection.start"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _versionMajor = reader.ReadOctet(); + _versionMinor = reader.ReadOctet(); + _serverProperties = reader.ReadTable(); + _mechanisms = reader.ReadLongstr(); + _locales = reader.ReadLongstr(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteOctet(_versionMajor); + writer.WriteOctet(_versionMinor); + writer.WriteTable(_serverProperties); + writer.WriteLongstr(_mechanisms); + writer.WriteLongstr(_locales); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 1 + 4 + 4; // bytes for _versionMajor, _versionMinor, length of _mechanisms, length of _locales + bufferSize += WireFormatting.GetTableByteCount(_serverProperties); // _serverProperties in bytes + bufferSize += _mechanisms.Length; // _mechanisms in bytes + bufferSize += _locales.Length; // _locales in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionStartOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionStartOk.cs new file mode 100644 index 0000000000..7e7729217d --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionStartOk.cs @@ -0,0 +1,88 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionStartOk : MethodBase + { + public IDictionary _clientProperties; + public string _mechanism; + public byte[] _response; + public string _locale; + + public ConnectionStartOk() + { + } + + public ConnectionStartOk(IDictionary ClientProperties, string Mechanism, byte[] Response, string Locale) + { + _clientProperties = ClientProperties; + _mechanism = Mechanism; + _response = Response; + _locale = Locale; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.StartOk; + public override string ProtocolMethodName => "connection.start-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _clientProperties = reader.ReadTable(); + _mechanism = reader.ReadShortstr(); + _response = reader.ReadLongstr(); + _locale = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteTable(_clientProperties); + writer.WriteShortstr(_mechanism); + writer.WriteLongstr(_response); + writer.WriteShortstr(_locale); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 4 +1; // bytes for length of _mechanism, length of _response, length of _locale + bufferSize += WireFormatting.GetTableByteCount(_clientProperties); // _clientProperties in bytes + bufferSize += Encoding.UTF8.GetByteCount(_mechanism); // _mechanism in bytes + bufferSize += _response.Length; // _response in bytes + bufferSize += Encoding.UTF8.GetByteCount(_locale); // _locale in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionTune.cs b/projects/RabbitMQ.Client/client/framing/ConnectionTune.cs new file mode 100644 index 0000000000..c13643360e --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionTune.cs @@ -0,0 +1,75 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionTune : Client.Impl.MethodBase + { + public ushort _channelMax; + public uint _frameMax; + public ushort _heartbeat; + + public ConnectionTune() + { + } + + public ConnectionTune(ushort ChannelMax, uint FrameMax, ushort Heartbeat) + { + _channelMax = ChannelMax; + _frameMax = FrameMax; + _heartbeat = Heartbeat; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Tune; + public override string ProtocolMethodName => "connection.tune"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _channelMax = reader.ReadShort(); + _frameMax = reader.ReadLong(); + _heartbeat = reader.ReadShort(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_channelMax); + writer.WriteLong(_frameMax); + writer.WriteShort(_heartbeat); + } + + public override int GetRequiredBufferSize() + { + return 2 + 4 + 2; // bytes for _channelMax, _frameMax, _heartbeat + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionTuneOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionTuneOk.cs new file mode 100644 index 0000000000..c8ecff0325 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionTuneOk.cs @@ -0,0 +1,75 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionTuneOk : Client.Impl.MethodBase + { + public ushort _channelMax; + public uint _frameMax; + public ushort _heartbeat; + + public ConnectionTuneOk() + { + } + + public ConnectionTuneOk(ushort ChannelMax, uint FrameMax, ushort Heartbeat) + { + _channelMax = ChannelMax; + _frameMax = FrameMax; + _heartbeat = Heartbeat; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.TuneOk; + public override string ProtocolMethodName => "connection.tune-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _channelMax = reader.ReadShort(); + _frameMax = reader.ReadLong(); + _heartbeat = reader.ReadShort(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_channelMax); + writer.WriteLong(_frameMax); + writer.WriteShort(_heartbeat); + } + + public override int GetRequiredBufferSize() + { + return 2 + 4 + 2; // bytes for _channelMax, _frameMax, _heartbeat + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionUnblocked.cs b/projects/RabbitMQ.Client/client/framing/ConnectionUnblocked.cs new file mode 100644 index 0000000000..b27ec566bf --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionUnblocked.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionUnblocked : Client.Impl.MethodBase + { + public ConnectionUnblocked() + { + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.Unblocked; + public override string ProtocolMethodName => "connection.unblocked"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecret.cs b/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecret.cs new file mode 100644 index 0000000000..0982a592ee --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecret.cs @@ -0,0 +1,76 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionUpdateSecret : Client.Impl.MethodBase + { + public byte[] _newSecret; + public string _reason; + + public ConnectionUpdateSecret() + { + } + + public ConnectionUpdateSecret(byte[] NewSecret, string Reason) + { + _newSecret = NewSecret; + _reason = Reason; + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.UpdateSecret; + public override string ProtocolMethodName => "connection.update-secret"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _newSecret = reader.ReadLongstr(); + _reason = reader.ReadShortstr(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLongstr(_newSecret); + writer.WriteShortstr(_reason); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 4 + 1; // bytes for length of _newSecret, length of _reason + bufferSize += _newSecret.Length; // _newSecret in bytes + bufferSize += Encoding.UTF8.GetByteCount(_reason); // _reason in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecretOk.cs b/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecretOk.cs new file mode 100644 index 0000000000..37648c9103 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ConnectionUpdateSecretOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ConnectionUpdateSecretOk : Client.Impl.MethodBase + { + public ConnectionUpdateSecretOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Connection; + public override ushort ProtocolMethodId => ConnectionMethodConstants.UpdateSecretOk; + public override string ProtocolMethodName => "connection.update-secret-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/Constants.cs b/projects/RabbitMQ.Client/client/framing/Constants.cs new file mode 100644 index 0000000000..5d75f698f6 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/Constants.cs @@ -0,0 +1,85 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client +{ + public static class Constants + { + ///(= 1) + public const int FrameMethod = 1; + ///(= 2) + public const int FrameHeader = 2; + ///(= 3) + public const int FrameBody = 3; + ///(= 8) + public const int FrameHeartbeat = 8; + ///(= 4096) + public const int FrameMinSize = 4096; + ///(= 206) + public const int FrameEnd = 206; + ///(= 200) + public const int ReplySuccess = 200; + ///(= 311) + public const int ContentTooLarge = 311; + ///(= 313) + public const int NoConsumers = 313; + ///(= 320) + public const int ConnectionForced = 320; + ///(= 402) + public const int InvalidPath = 402; + ///(= 403) + public const int AccessRefused = 403; + ///(= 404) + public const int NotFound = 404; + ///(= 405) + public const int ResourceLocked = 405; + ///(= 406) + public const int PreconditionFailed = 406; + ///(= 501) + public const int FrameError = 501; + ///(= 502) + public const int SyntaxError = 502; + ///(= 503) + public const int CommandInvalid = 503; + ///(= 504) + public const int ChannelError = 504; + ///(= 505) + public const int UnexpectedFrame = 505; + ///(= 506) + public const int ResourceError = 506; + ///(= 530) + public const int NotAllowed = 530; + ///(= 540) + public const int NotImplemented = 540; + ///(= 541) + public const int InternalError = 541; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeBind.cs b/projects/RabbitMQ.Client/client/framing/ExchangeBind.cs new file mode 100644 index 0000000000..6a2b0eca2e --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeBind.cs @@ -0,0 +1,97 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeBind : MethodBase + { + public ushort _reserved1; + public string _destination; + public string _source; + public string _routingKey; + public bool _nowait; + public IDictionary _arguments; + + public ExchangeBind() + { + } + + public ExchangeBind(ushort Reserved1, string Destination, string Source, string RoutingKey, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _destination = Destination; + _source = Source; + _routingKey = RoutingKey; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.Bind; + public override string ProtocolMethodName => "exchange.bind"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _destination = reader.ReadShortstr(); + _source = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_destination); + writer.WriteShortstr(_source); + writer.WriteShortstr(_routingKey); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1 + 1; // bytes for _reserved1, length of _destination, length of _source, length of _routingKey, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_destination); // _destination in bytes + bufferSize += Encoding.UTF8.GetByteCount(_source); // _source in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeBindOk.cs b/projects/RabbitMQ.Client/client/framing/ExchangeBindOk.cs new file mode 100644 index 0000000000..d8aafba09f --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeBindOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeBindOk : Client.Impl.MethodBase + { + public ExchangeBindOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.BindOk; + public override string ProtocolMethodName => "exchange.bind-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeDeclare.cs b/projects/RabbitMQ.Client/client/framing/ExchangeDeclare.cs new file mode 100644 index 0000000000..d3ecb42fd9 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeDeclare.cs @@ -0,0 +1,108 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeDeclare : MethodBase + { + public ushort _reserved1; + public string _exchange; + public string _type; + public bool _passive; + public bool _durable; + public bool _autoDelete; + public bool _internal; + public bool _nowait; + public IDictionary _arguments; + + public ExchangeDeclare() + { + } + + public ExchangeDeclare(ushort Reserved1, string Exchange, string Type, bool Passive, bool Durable, bool AutoDelete, bool Internal, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _exchange = Exchange; + _type = Type; + _passive = Passive; + _durable = Durable; + _autoDelete = AutoDelete; + _internal = Internal; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.Declare; + public override string ProtocolMethodName => "exchange.declare"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _exchange = reader.ReadShortstr(); + _type = reader.ReadShortstr(); + _passive = reader.ReadBit(); + _durable = reader.ReadBit(); + _autoDelete = reader.ReadBit(); + _internal = reader.ReadBit(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_type); + writer.WriteBit(_passive); + writer.WriteBit(_durable); + writer.WriteBit(_autoDelete); + writer.WriteBit(_internal); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1; // bytes for _reserved1, length of _exchange, length of _type, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_type); // _type in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeDeclareOk.cs b/projects/RabbitMQ.Client/client/framing/ExchangeDeclareOk.cs new file mode 100644 index 0000000000..ba18411765 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeDeclareOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeDeclareOk : Client.Impl.MethodBase + { + public ExchangeDeclareOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.DeclareOk; + public override string ProtocolMethodName => "exchange.declare-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeDelete.cs b/projects/RabbitMQ.Client/client/framing/ExchangeDelete.cs new file mode 100644 index 0000000000..78bb7aab33 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeDelete.cs @@ -0,0 +1,84 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeDelete : Client.Impl.MethodBase + { + public ushort _reserved1; + public string _exchange; + public bool _ifUnused; + public bool _nowait; + + public ExchangeDelete() + { + } + + public ExchangeDelete(ushort Reserved1, string Exchange, bool IfUnused, bool Nowait) + { + _reserved1 = Reserved1; + _exchange = Exchange; + _ifUnused = IfUnused; + _nowait = Nowait; + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.Delete; + public override string ProtocolMethodName => "exchange.delete"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _exchange = reader.ReadShortstr(); + _ifUnused = reader.ReadBit(); + _nowait = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_exchange); + writer.WriteBit(_ifUnused); + writer.WriteBit(_nowait); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1; // bytes for _reserved1, length of _exchange, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeDeleteOk.cs b/projects/RabbitMQ.Client/client/framing/ExchangeDeleteOk.cs new file mode 100644 index 0000000000..ba97fffd6d --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeDeleteOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeDeleteOk : Client.Impl.MethodBase + { + public ExchangeDeleteOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.DeleteOk; + public override string ProtocolMethodName => "exchange.delete-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/ExchangeMethodConstants.cs new file mode 100644 index 0000000000..eb056cd632 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeMethodConstants.cs @@ -0,0 +1,45 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class ExchangeMethodConstants + { + internal const ushort Declare = 10; + internal const ushort DeclareOk = 11; + internal const ushort Delete = 20; + internal const ushort DeleteOk = 21; + internal const ushort Bind = 30; + internal const ushort BindOk = 31; + internal const ushort Unbind = 40; + internal const ushort UnbindOk = 51; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeUnbind.cs b/projects/RabbitMQ.Client/client/framing/ExchangeUnbind.cs new file mode 100644 index 0000000000..f167389cf0 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeUnbind.cs @@ -0,0 +1,97 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeUnbind : MethodBase + { + public ushort _reserved1; + public string _destination; + public string _source; + public string _routingKey; + public bool _nowait; + public IDictionary _arguments; + + public ExchangeUnbind() + { + } + + public ExchangeUnbind(ushort Reserved1, string Destination, string Source, string RoutingKey, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _destination = Destination; + _source = Source; + _routingKey = RoutingKey; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.Unbind; + public override string ProtocolMethodName => "exchange.unbind"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _destination = reader.ReadShortstr(); + _source = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_destination); + writer.WriteShortstr(_source); + writer.WriteShortstr(_routingKey); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1 + 1; // bytes for _reserved1, length of _destination, length of _source, length of _routingKey, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_destination); // _destination in bytes + bufferSize += Encoding.UTF8.GetByteCount(_source); // _source in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/ExchangeUnbindOk.cs b/projects/RabbitMQ.Client/client/framing/ExchangeUnbindOk.cs new file mode 100644 index 0000000000..5536d93aa5 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/ExchangeUnbindOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class ExchangeUnbindOk : Client.Impl.MethodBase + { + public ExchangeUnbindOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Exchange; + public override ushort ProtocolMethodId => ExchangeMethodConstants.UnbindOk; + public override string ProtocolMethodName => "exchange.unbind-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/Model.cs b/projects/RabbitMQ.Client/client/framing/Model.cs new file mode 100644 index 0000000000..1230ffb334 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/Model.cs @@ -0,0 +1,425 @@ +// 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.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal class Model: ModelBase + { + public Model(ISession session) + : base(session) + { + } + + public Model(ISession session, ConsumerWorkService workService) + : base(session, workService) + { + } + + public override void ConnectionTuneOk(ushort channelMax, uint frameMax, ushort heartbeat) + { + ModelSend(new ConnectionTuneOk(channelMax, frameMax, heartbeat)); + } + + public override void _Private_BasicCancel(string consumerTag, bool nowait) + { + ModelSend(new BasicCancel(consumerTag, nowait)); + } + + public override void _Private_BasicConsume(string queue, string consumerTag, bool noLocal, bool autoAck, bool exclusive, bool nowait, IDictionary arguments) + { + ModelSend(new BasicConsume(default, queue, consumerTag, noLocal, autoAck, exclusive, nowait, arguments)); + } + + public override void _Private_BasicGet(string queue, bool autoAck) + { + ModelSend(new BasicGet(default, queue, autoAck)); + } + + public override void _Private_BasicPublish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory body) + { + ModelSend(new BasicPublish(default, exchange, routingKey, mandatory, default), (BasicProperties) basicProperties, body); + } + + public override void _Private_BasicRecover(bool requeue) + { + ModelSend(new BasicRecover(requeue)); + } + + public override void _Private_ChannelClose(ushort replyCode, string replyText, ushort classId, ushort methodId) + { + ModelSend(new ChannelClose(replyCode, replyText, classId, methodId)); + } + + public override void _Private_ChannelCloseOk() + { + ModelSend(new ChannelCloseOk()); + } + + public override void _Private_ChannelFlowOk(bool active) + { + ModelSend(new ChannelFlowOk(active)); + } + + public override void _Private_ChannelOpen(string outOfBand) + { + ModelRpc(new ChannelOpen(outOfBand)); + } + + public override void _Private_ConfirmSelect(bool nowait) + { + var method = new ConfirmSelect(nowait); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_ConnectionClose(ushort replyCode, string replyText, ushort classId, ushort methodId) + { + ModelRpc(new ConnectionClose(replyCode, replyText, classId, methodId)); + } + + public override void _Private_ConnectionCloseOk() + { + ModelSend(new ConnectionCloseOk()); + } + + public override void _Private_ConnectionOpen(string virtualHost, string capabilities, bool insist) + { + ModelSend(new ConnectionOpen(virtualHost, capabilities, insist)); + } + + public override void _Private_ConnectionSecureOk(byte[] response) + { + ModelSend(new ConnectionSecureOk(response)); + } + + public override void _Private_ConnectionStartOk(IDictionary clientProperties, string mechanism, byte[] response, string locale) + { + ModelSend(new ConnectionStartOk(clientProperties, mechanism, response, locale)); + } + + public override void _Private_UpdateSecret(byte[] newSecret, string reason) + { + ModelRpc(new ConnectionUpdateSecret(newSecret, reason)); + } + + public override void _Private_ExchangeBind(string destination, string source, string routingKey, bool nowait, IDictionary arguments) + { + ExchangeBind method = new ExchangeBind(default, destination, source, routingKey, nowait, arguments); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_ExchangeDeclare(string exchange, string type, bool passive, bool durable, bool autoDelete, bool @internal, bool nowait, IDictionary arguments) + { + ExchangeDeclare method = new ExchangeDeclare(default, exchange, type, passive, durable, autoDelete, @internal, nowait, arguments); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_ExchangeDelete(string exchange, bool ifUnused, bool nowait) + { + ExchangeDelete method = new ExchangeDelete(default, exchange, ifUnused, nowait); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_ExchangeUnbind(string destination, string source, string routingKey, bool nowait, IDictionary arguments) + { + ExchangeUnbind method = new ExchangeUnbind(default, destination, source, routingKey, nowait, arguments); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_QueueBind(string queue, string exchange, string routingKey, bool nowait, IDictionary arguments) + { + QueueBind method = new QueueBind(default, queue, exchange, routingKey, nowait, arguments); + if (nowait) + { + ModelSend(method); + } + else + { + ModelRpc(method); + } + } + + public override void _Private_QueueDeclare(string queue, bool passive, bool durable, bool exclusive, bool autoDelete, bool nowait, IDictionary arguments) + { + QueueDeclare method = new QueueDeclare(default, queue, passive, durable, exclusive, autoDelete, nowait, arguments); + if (nowait) + { + ModelSend(method); + } + else + { + ModelSend(method); + } + } + + public override uint _Private_QueueDelete(string queue, bool ifUnused, bool ifEmpty, bool nowait) + { + QueueDelete method = new QueueDelete(default, queue, ifUnused, ifEmpty, nowait); + if (nowait) + { + ModelSend(method); + return 0xFFFFFFFF; + } + + return ModelRpc(method)._messageCount; + } + + public override uint _Private_QueuePurge(string queue, bool nowait) + { + QueuePurge method = new QueuePurge(default, queue, nowait); + if (nowait) + { + ModelSend(method); + return 0xFFFFFFFF; + } + + return ModelRpc(method)._messageCount; + } + + public override void BasicAck(ulong deliveryTag, bool multiple) + { + ModelSend(new BasicAck(deliveryTag, multiple)); + } + + public override void BasicNack(ulong deliveryTag, bool multiple, bool requeue) + { + ModelSend(new BasicNack(deliveryTag, multiple, requeue)); + } + + public override void BasicQos(uint prefetchSize, ushort prefetchCount, bool global) + { + ModelRpc(new BasicQos(prefetchSize, prefetchCount, global)); + } + + public override void BasicRecoverAsync(bool requeue) + { + ModelSend(new BasicRecoverAsync(requeue)); + } + + public override void BasicReject(ulong deliveryTag, bool requeue) + { + ModelSend(new BasicReject(deliveryTag, requeue)); + } + + public override IBasicProperties CreateBasicProperties() + { + return new BasicProperties(); + } + + public override void QueueUnbind(string queue, string exchange, string routingKey, IDictionary arguments) + { + ModelRpc(new QueueUnbind(default, queue, exchange, routingKey, arguments)); + } + + public override void TxCommit() + { + ModelRpc(new TxCommit()); + } + + public override void TxRollback() + { + ModelRpc(new TxRollback()); + } + + public override void TxSelect() + { + ModelRpc(new TxSelect()); + } + + public override bool DispatchAsynchronous(in IncomingCommand cmd) + { + switch ((cmd.Method.ProtocolClassId << 16) | cmd.Method.ProtocolMethodId) + { + case (ClassConstants.Basic << 16) | BasicMethodConstants.Deliver: + { + var __impl = (BasicDeliver)cmd.Method; + HandleBasicDeliver(__impl._consumerTag, __impl._deliveryTag, __impl._redelivered, __impl._exchange, __impl._routingKey, (IBasicProperties) cmd.Header, cmd.Body, cmd.TakeoverPayload()); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.Ack: + { + var __impl = (BasicAck)cmd.Method; + HandleBasicAck(__impl._deliveryTag, __impl._multiple); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.Cancel: + { + var __impl = (BasicCancel)cmd.Method; + HandleBasicCancel(__impl._consumerTag, __impl._nowait); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.CancelOk: + { + var __impl = (BasicCancelOk)cmd.Method; + HandleBasicCancelOk(__impl._consumerTag); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.ConsumeOk: + { + var __impl = (BasicConsumeOk)cmd.Method; + HandleBasicConsumeOk(__impl._consumerTag); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.GetEmpty: + { + HandleBasicGetEmpty(); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.GetOk: + { + var __impl = (BasicGetOk)cmd.Method; + HandleBasicGetOk(__impl._deliveryTag, __impl._redelivered, __impl._exchange, __impl._routingKey, __impl._messageCount, (IBasicProperties) cmd.Header, cmd.Body, cmd.TakeoverPayload()); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.Nack: + { + var __impl = (BasicNack)cmd.Method; + HandleBasicNack(__impl._deliveryTag, __impl._multiple, __impl._requeue); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.RecoverOk: + { + HandleBasicRecoverOk(); + return true; + } + case (ClassConstants.Basic << 16) | BasicMethodConstants.Return: + { + var __impl = (BasicReturn)cmd.Method; + HandleBasicReturn(__impl._replyCode, __impl._replyText, __impl._exchange, __impl._routingKey, (IBasicProperties) cmd.Header, cmd.Body, cmd.TakeoverPayload()); + return true; + } + case (ClassConstants.Channel << 16) | ChannelMethodConstants.Close: + { + var __impl = (ChannelClose)cmd.Method; + HandleChannelClose(__impl._replyCode, __impl._replyText, __impl._classId, __impl._methodId); + return true; + } + case (ClassConstants.Channel << 16) | ChannelMethodConstants.CloseOk: + { + HandleChannelCloseOk(); + return true; + } + case (ClassConstants.Channel << 16) | ChannelMethodConstants.Flow: + { + var __impl = (ChannelFlow)cmd.Method; + HandleChannelFlow(__impl._active); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Blocked: + { + var __impl = (ConnectionBlocked)cmd.Method; + HandleConnectionBlocked(__impl._reason); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Close: + { + var __impl = (ConnectionClose)cmd.Method; + HandleConnectionClose(__impl._replyCode, __impl._replyText, __impl._classId, __impl._methodId); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.OpenOk: + { + var __impl = (ConnectionOpenOk)cmd.Method; + HandleConnectionOpenOk(__impl._reserved1); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Secure: + { + var __impl = (ConnectionSecure)cmd.Method; + HandleConnectionSecure(__impl._challenge); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Start: + { + var __impl = (ConnectionStart)cmd.Method; + HandleConnectionStart(__impl._versionMajor, __impl._versionMinor, __impl._serverProperties, __impl._mechanisms, __impl._locales); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Tune: + { + var __impl = (ConnectionTune)cmd.Method; + HandleConnectionTune(__impl._channelMax, __impl._frameMax, __impl._heartbeat); + return true; + } + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Unblocked: + { + HandleConnectionUnblocked(); + return true; + } + case (ClassConstants.Queue << 16) | QueueMethodConstants.DeclareOk: + { + var __impl = (QueueDeclareOk)cmd.Method; + HandleQueueDeclareOk(__impl._queue, __impl._messageCount, __impl._consumerCount); + return true; + } + default: return false; + } + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/Protocol.cs b/projects/RabbitMQ.Client/client/framing/Protocol.cs new file mode 100644 index 0000000000..bc500a41ce --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/Protocol.cs @@ -0,0 +1,151 @@ +// 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 RabbitMQ.Client.Framing.Impl; + +namespace RabbitMQ.Client.Framing +{ + internal sealed class Protocol : ProtocolBase + { + ///Protocol major version (= 0) + public override int MajorVersion => 0; + + ///Protocol minor version (= 9) + public override int MinorVersion => 9; + + ///Protocol revision (= 1) + public override int Revision => 1; + + ///Protocol API name (= :AMQP_0_9_1) + public override string ApiName => ":AMQP_0_9_1"; + + ///Default TCP port (= 5672) + public override int DefaultPort => 5672; + + internal override Client.Impl.MethodBase DecodeMethodFrom(ReadOnlySpan span) + { + ushort classId = Util.NetworkOrderDeserializer.ReadUInt16(span); + ushort methodId = Util.NetworkOrderDeserializer.ReadUInt16(span.Slice(2)); + Client.Impl.MethodBase result = DecodeMethodFrom(classId, methodId); + if(result != null) + { + Client.Impl.MethodArgumentReader reader = new Client.Impl.MethodArgumentReader(span.Slice(4)); + result.ReadArgumentsFrom(ref reader); + return result; + } + + throw new Exceptions.UnknownClassOrMethodException(classId, methodId); + } + + internal Client.Impl.MethodBase DecodeMethodFrom(ushort classId, ushort methodId) + { + switch ((classId << 16) | methodId) + { + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Start: return new ConnectionStart(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.StartOk: return new ConnectionStartOk(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Secure: return new ConnectionSecure(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.SecureOk: return new ConnectionSecureOk(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Tune: return new ConnectionTune(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.TuneOk: return new ConnectionTuneOk(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Open: return new ConnectionOpen(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.OpenOk: return new ConnectionOpenOk(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Close: return new ConnectionClose(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.CloseOk: return new ConnectionCloseOk(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Blocked: return new ConnectionBlocked(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.Unblocked: return new ConnectionUnblocked(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.UpdateSecret: return new ConnectionUpdateSecret(); + case (ClassConstants.Connection << 16) | ConnectionMethodConstants.UpdateSecretOk: return new ConnectionUpdateSecretOk(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.Open: return new ChannelOpen(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.OpenOk: return new ChannelOpenOk(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.Flow: return new ChannelFlow(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.FlowOk: return new ChannelFlowOk(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.Close: return new ChannelClose(); + case (ClassConstants.Channel << 16) | ChannelMethodConstants.CloseOk: return new ChannelCloseOk(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.Declare: return new ExchangeDeclare(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.DeclareOk: return new ExchangeDeclareOk(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.Delete: return new ExchangeDelete(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.DeleteOk: return new ExchangeDeleteOk(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.Bind: return new ExchangeBind(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.BindOk: return new ExchangeBindOk(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.Unbind: return new ExchangeUnbind(); + case (ClassConstants.Exchange << 16) | ExchangeMethodConstants.UnbindOk: return new ExchangeUnbindOk(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.Declare: return new QueueDeclare(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.DeclareOk: return new Impl.QueueDeclareOk(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.Bind: return new QueueBind(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.BindOk: return new QueueBindOk(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.Unbind: return new QueueUnbind(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.UnbindOk: return new QueueUnbindOk(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.Purge: return new QueuePurge(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.PurgeOk: return new QueuePurgeOk(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.Delete: return new QueueDelete(); + case (ClassConstants.Queue << 16) | QueueMethodConstants.DeleteOk: return new QueueDeleteOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Qos: return new BasicQos(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.QosOk: return new BasicQosOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Consume: return new BasicConsume(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.ConsumeOk: return new BasicConsumeOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Cancel: return new BasicCancel(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.CancelOk: return new BasicCancelOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Publish: return new BasicPublish(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Return: return new BasicReturn(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Deliver: return new BasicDeliver(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Get: return new BasicGet(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.GetOk: return new BasicGetOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.GetEmpty: return new BasicGetEmpty(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Ack: return new BasicAck(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Reject: return new BasicReject(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.RecoverAsync: return new BasicRecoverAsync(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Recover: return new BasicRecover(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.RecoverOk: return new BasicRecoverOk(); + case (ClassConstants.Basic << 16) | BasicMethodConstants.Nack: return new BasicNack(); + case (ClassConstants.Tx << 16) | TxMethodConstants.Select: return new TxSelect(); + case (ClassConstants.Tx << 16) | TxMethodConstants.SelectOk: return new TxSelectOk(); + case (ClassConstants.Tx << 16) | TxMethodConstants.Commit: return new TxCommit(); + case (ClassConstants.Tx << 16) | TxMethodConstants.CommitOk: return new TxCommitOk(); + case (ClassConstants.Tx << 16) | TxMethodConstants.Rollback: return new TxRollback(); + case (ClassConstants.Tx << 16) | TxMethodConstants.RollbackOk: return new TxRollbackOk(); + case (ClassConstants.Confirm << 16) | ConfirmMethodConstants.Select: return new ConfirmSelect(); + case (ClassConstants.Confirm << 16) | ConfirmMethodConstants.SelectOk: return new ConfirmSelectOk(); + default: return null; + } + } + + + internal override Client.Impl.ContentHeaderBase DecodeContentHeaderFrom(ushort classId) + { + switch (classId) + { + case 60: return new BasicProperties(); + default: throw new Exceptions.UnknownClassOrMethodException(classId, 0); + } + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueBind.cs b/projects/RabbitMQ.Client/client/framing/QueueBind.cs new file mode 100644 index 0000000000..4fb7164341 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueBind.cs @@ -0,0 +1,97 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueBind : MethodBase + { + public ushort _reserved1; + public string _queue; + public string _exchange; + public string _routingKey; + public bool _nowait; + public IDictionary _arguments; + + public QueueBind() + { + } + + public QueueBind(ushort Reserved1, string Queue, string Exchange, string RoutingKey, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _queue = Queue; + _exchange = Exchange; + _routingKey = RoutingKey; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.Bind; + public override string ProtocolMethodName => "queue.bind"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1 + 1; // bytes for _reserved1, length of _queue, length of _exchange, length of _routingKey, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueBindOk.cs b/projects/RabbitMQ.Client/client/framing/QueueBindOk.cs new file mode 100644 index 0000000000..a468398af3 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueBindOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueBindOk : Client.Impl.MethodBase + { + public QueueBindOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.BindOk; + public override string ProtocolMethodName => "queue.bind-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueDeclare.cs b/projects/RabbitMQ.Client/client/framing/QueueDeclare.cs new file mode 100644 index 0000000000..efa6a126ef --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueDeclare.cs @@ -0,0 +1,103 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueDeclare : MethodBase + { + public ushort _reserved1; + public string _queue; + public bool _passive; + public bool _durable; + public bool _exclusive; + public bool _autoDelete; + public bool _nowait; + public IDictionary _arguments; + + public QueueDeclare() + { + } + + public QueueDeclare(ushort Reserved1, string Queue, bool Passive, bool Durable, bool Exclusive, bool AutoDelete, bool Nowait, IDictionary Arguments) + { + _reserved1 = Reserved1; + _queue = Queue; + _passive = Passive; + _durable = Durable; + _exclusive = Exclusive; + _autoDelete = AutoDelete; + _nowait = Nowait; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.Declare; + public override string ProtocolMethodName => "queue.declare"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _passive = reader.ReadBit(); + _durable = reader.ReadBit(); + _exclusive = reader.ReadBit(); + _autoDelete = reader.ReadBit(); + _nowait = reader.ReadBit(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteBit(_passive); + writer.WriteBit(_durable); + writer.WriteBit(_exclusive); + writer.WriteBit(_autoDelete); + writer.WriteBit(_nowait); + writer.EndBits(); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1; // bytes for _reserved1, length of _queue, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueDeclareOk.cs b/projects/RabbitMQ.Client/client/framing/QueueDeclareOk.cs new file mode 100644 index 0000000000..85bc41767c --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueDeclareOk.cs @@ -0,0 +1,79 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueDeclareOk : Client.Impl.MethodBase + { + public string _queue; + public uint _messageCount; + public uint _consumerCount; + + public QueueDeclareOk() + { + } + + public QueueDeclareOk(string Queue, uint MessageCount, uint ConsumerCount) + { + _queue = Queue; + _messageCount = MessageCount; + _consumerCount = ConsumerCount; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.DeclareOk; + public override string ProtocolMethodName => "queue.declare-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _queue = reader.ReadShortstr(); + _messageCount = reader.ReadLong(); + _consumerCount = reader.ReadLong(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShortstr(_queue); + writer.WriteLong(_messageCount); + writer.WriteLong(_consumerCount); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 1 + 4 + 4; // bytes for length of _queue, _messageCount, _consumerCount + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueDelete.cs b/projects/RabbitMQ.Client/client/framing/QueueDelete.cs new file mode 100644 index 0000000000..64cc5e14a0 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueDelete.cs @@ -0,0 +1,88 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueDelete : Client.Impl.MethodBase + { + public ushort _reserved1; + public string _queue; + public bool _ifUnused; + public bool _ifEmpty; + public bool _nowait; + + public QueueDelete() + { + } + + public QueueDelete(ushort Reserved1, string Queue, bool IfUnused, bool IfEmpty, bool Nowait) + { + _reserved1 = Reserved1; + _queue = Queue; + _ifUnused = IfUnused; + _ifEmpty = IfEmpty; + _nowait = Nowait; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.Delete; + public override string ProtocolMethodName => "queue.delete"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _ifUnused = reader.ReadBit(); + _ifEmpty = reader.ReadBit(); + _nowait = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteBit(_ifUnused); + writer.WriteBit(_ifEmpty); + writer.WriteBit(_nowait); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1; // bytes for _reserved1, length of _queue, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueDeleteOk.cs b/projects/RabbitMQ.Client/client/framing/QueueDeleteOk.cs new file mode 100644 index 0000000000..81580cc5da --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueDeleteOk.cs @@ -0,0 +1,67 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueDeleteOk : Client.Impl.MethodBase + { + public uint _messageCount; + + public QueueDeleteOk() + { + } + + public QueueDeleteOk(uint MessageCount) + { + _messageCount = MessageCount; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.DeleteOk; + public override string ProtocolMethodName => "queue.delete-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _messageCount = reader.ReadLong(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLong(_messageCount); + } + + public override int GetRequiredBufferSize() + { + return 4; // bytes for _messageCount + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/QueueMethodConstants.cs new file mode 100644 index 0000000000..6395e8aab9 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueMethodConstants.cs @@ -0,0 +1,47 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class QueueMethodConstants + { + internal const ushort Declare = 10; + internal const ushort DeclareOk = 11; + internal const ushort Bind = 20; + internal const ushort BindOk = 21; + internal const ushort Unbind = 50; + internal const ushort UnbindOk = 51; + internal const ushort Purge = 30; + internal const ushort PurgeOk = 31; + internal const ushort Delete = 40; + internal const ushort DeleteOk = 41; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueuePurge.cs b/projects/RabbitMQ.Client/client/framing/QueuePurge.cs new file mode 100644 index 0000000000..a7abb17483 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueuePurge.cs @@ -0,0 +1,80 @@ +// 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.Text; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueuePurge : Client.Impl.MethodBase + { + public ushort _reserved1; + public string _queue; + public bool _nowait; + + public QueuePurge() + { + } + + public QueuePurge(ushort Reserved1, string Queue, bool Nowait) + { + _reserved1 = Reserved1; + _queue = Queue; + _nowait = Nowait; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.Purge; + public override string ProtocolMethodName => "queue.purge"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _nowait = reader.ReadBit(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteBit(_nowait); + writer.EndBits(); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1; // bytes for _reserved1, length of _queue, bit fields + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueuePurgeOk.cs b/projects/RabbitMQ.Client/client/framing/QueuePurgeOk.cs new file mode 100644 index 0000000000..90ab57791b --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueuePurgeOk.cs @@ -0,0 +1,67 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueuePurgeOk : Client.Impl.MethodBase + { + public uint _messageCount; + + public QueuePurgeOk() + { + } + + public QueuePurgeOk(uint MessageCount) + { + _messageCount = MessageCount; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.PurgeOk; + public override string ProtocolMethodName => "queue.purge-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + _messageCount = reader.ReadLong(); + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + writer.WriteLong(_messageCount); + } + + public override int GetRequiredBufferSize() + { + return 4; // bytes for _messageCount + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueUnbind.cs b/projects/RabbitMQ.Client/client/framing/QueueUnbind.cs new file mode 100644 index 0000000000..2d036d41b2 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueUnbind.cs @@ -0,0 +1,92 @@ +// 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.Collections.Generic; +using System.Text; +using RabbitMQ.Client.Impl; + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueUnbind : MethodBase + { + public ushort _reserved1; + public string _queue; + public string _exchange; + public string _routingKey; + public IDictionary _arguments; + + public QueueUnbind() + { + } + + public QueueUnbind(ushort Reserved1, string Queue, string Exchange, string RoutingKey, IDictionary Arguments) + { + _reserved1 = Reserved1; + _queue = Queue; + _exchange = Exchange; + _routingKey = RoutingKey; + _arguments = Arguments; + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.Unbind; + public override string ProtocolMethodName => "queue.unbind"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref MethodArgumentReader reader) + { + _reserved1 = reader.ReadShort(); + _queue = reader.ReadShortstr(); + _exchange = reader.ReadShortstr(); + _routingKey = reader.ReadShortstr(); + _arguments = reader.ReadTable(); + } + + public override void WriteArgumentsTo(ref MethodArgumentWriter writer) + { + writer.WriteShort(_reserved1); + writer.WriteShortstr(_queue); + writer.WriteShortstr(_exchange); + writer.WriteShortstr(_routingKey); + writer.WriteTable(_arguments); + } + + public override int GetRequiredBufferSize() + { + int bufferSize = 2 + 1 + 1 + 1; // bytes for _reserved1, length of _queue, length of _exchange, length of _routingKey + bufferSize += Encoding.UTF8.GetByteCount(_queue); // _queue in bytes + bufferSize += Encoding.UTF8.GetByteCount(_exchange); // _exchange in bytes + bufferSize += Encoding.UTF8.GetByteCount(_routingKey); // _routingKey in bytes + bufferSize += WireFormatting.GetTableByteCount(_arguments); // _arguments in bytes + return bufferSize; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/QueueUnbindOk.cs b/projects/RabbitMQ.Client/client/framing/QueueUnbindOk.cs new file mode 100644 index 0000000000..9f56bbc904 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/QueueUnbindOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class QueueUnbindOk : Client.Impl.MethodBase + { + public QueueUnbindOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Queue; + public override ushort ProtocolMethodId => QueueMethodConstants.UnbindOk; + public override string ProtocolMethodName => "queue.unbind-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxCommit.cs b/projects/RabbitMQ.Client/client/framing/TxCommit.cs new file mode 100644 index 0000000000..04d0fa199e --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxCommit.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxCommit : Client.Impl.MethodBase + { + public TxCommit() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.Commit; + public override string ProtocolMethodName => "tx.commit"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxCommitOk.cs b/projects/RabbitMQ.Client/client/framing/TxCommitOk.cs new file mode 100644 index 0000000000..05b852515b --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxCommitOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxCommitOk : Client.Impl.MethodBase + { + public TxCommitOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.CommitOk; + public override string ProtocolMethodName => "tx.commit-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxMethodConstants.cs b/projects/RabbitMQ.Client/client/framing/TxMethodConstants.cs new file mode 100644 index 0000000000..1497b49246 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxMethodConstants.cs @@ -0,0 +1,43 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal static class TxMethodConstants + { + internal const ushort Select = 10; + internal const ushort SelectOk = 11; + internal const ushort Commit = 20; + internal const ushort CommitOk = 21; + internal const ushort Rollback = 30; + internal const ushort RollbackOk = 31; + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxRollback.cs b/projects/RabbitMQ.Client/client/framing/TxRollback.cs new file mode 100644 index 0000000000..cee9134e9a --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxRollback.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxRollback : Client.Impl.MethodBase + { + public TxRollback() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.Rollback; + public override string ProtocolMethodName => "tx.rollback"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxRollbackOk.cs b/projects/RabbitMQ.Client/client/framing/TxRollbackOk.cs new file mode 100644 index 0000000000..fc144b8bdd --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxRollbackOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxRollbackOk : Client.Impl.MethodBase + { + public TxRollbackOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.RollbackOk; + public override string ProtocolMethodName => "tx.rollback-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxSelect.cs b/projects/RabbitMQ.Client/client/framing/TxSelect.cs new file mode 100644 index 0000000000..8a194131a6 --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxSelect.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxSelect : Client.Impl.MethodBase + { + public TxSelect() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.Select; + public override string ProtocolMethodName => "tx.select"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/framing/TxSelectOk.cs b/projects/RabbitMQ.Client/client/framing/TxSelectOk.cs new file mode 100644 index 0000000000..936010025f --- /dev/null +++ b/projects/RabbitMQ.Client/client/framing/TxSelectOk.cs @@ -0,0 +1,58 @@ +// 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. +//--------------------------------------------------------------------------- + +namespace RabbitMQ.Client.Framing.Impl +{ + internal sealed class TxSelectOk : Client.Impl.MethodBase + { + public TxSelectOk() + { + } + + public override ushort ProtocolClassId => ClassConstants.Tx; + public override ushort ProtocolMethodId => TxMethodConstants.SelectOk; + public override string ProtocolMethodName => "tx.select-ok"; + public override bool HasContent => false; + + public override void ReadArgumentsFrom(ref Client.Impl.MethodArgumentReader reader) + { + } + + public override void WriteArgumentsTo(ref Client.Impl.MethodArgumentWriter writer) + { + } + + public override int GetRequiredBufferSize() + { + return 0; + } + } +} diff --git a/projects/RabbitMQ.Client/client/impl/AmqpVersion.cs b/projects/RabbitMQ.Client/client/impl/AmqpVersion.cs index e78cd5b35f..dfa5a26eab 100644 --- a/projects/RabbitMQ.Client/client/impl/AmqpVersion.cs +++ b/projects/RabbitMQ.Client/client/impl/AmqpVersion.cs @@ -45,7 +45,7 @@ namespace RabbitMQ.Client.Framing.Impl /// special-cases 8-0, rewriting it at construction time to be 0-8 instead. /// /// - class AmqpVersion + internal class AmqpVersion { /// /// Construct an from major and minor version numbers. diff --git a/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs b/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs index 0a6b0a68d6..5b313577fd 100644 --- a/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs +++ b/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs @@ -46,10 +46,10 @@ public Task Stop(IModel model) return Task.CompletedTask; } - class WorkPool + private class WorkPool { - readonly Channel _channel; - readonly IModel _model; + private readonly Channel _channel; + private readonly IModel _model; private Task _worker; private readonly int _concurrency; private SemaphoreSlim _limiter; diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs index f296c54c98..a9163f389b 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs @@ -1828,7 +1828,7 @@ public IBasicPublishBatch CreateBasicPublishBatch() throw new ObjectDisposedException(GetType().FullName); } - return ((IFullModel)_delegate).CreateBasicPublishBatch(); + return _delegate.CreateBasicPublishBatch(); } public IBasicPublishBatch CreateBasicPublishBatch(int sizeHint) @@ -1838,7 +1838,7 @@ public IBasicPublishBatch CreateBasicPublishBatch(int sizeHint) throw new ObjectDisposedException(GetType().FullName); } - return ((IFullModel)_delegate).CreateBasicPublishBatch(sizeHint); + return _delegate.CreateBasicPublishBatch(sizeHint); } } } diff --git a/projects/RabbitMQ.Client/client/impl/BasicProperties.cs b/projects/RabbitMQ.Client/client/impl/BasicProperties.cs index ab0517ea3a..9c17a7a5c1 100644 --- a/projects/RabbitMQ.Client/client/impl/BasicProperties.cs +++ b/projects/RabbitMQ.Client/client/impl/BasicProperties.cs @@ -33,7 +33,7 @@ namespace RabbitMQ.Client.Impl { - abstract class BasicProperties : ContentHeaderBase, IBasicProperties + internal abstract class BasicProperties : ContentHeaderBase, IBasicProperties { /// /// Application Id. diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index eee58a246b..0a9fb9b976 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -1043,7 +1043,7 @@ internal OutgoingCommand ChannelCloseWrapper(ushort reasonCode, string reasonTex return request; } - void StartAndTune() + private void StartAndTune() { var connectionStartCell = new BlockingCell(); _model0.m_connectionStartCell = connectionStartCell; diff --git a/projects/RabbitMQ.Client/client/impl/ConnectionStartDetails.cs b/projects/RabbitMQ.Client/client/impl/ConnectionStartDetails.cs index b792dafbe9..bb540c045a 100644 --- a/projects/RabbitMQ.Client/client/impl/ConnectionStartDetails.cs +++ b/projects/RabbitMQ.Client/client/impl/ConnectionStartDetails.cs @@ -33,7 +33,7 @@ namespace RabbitMQ.Client.Impl { - class ConnectionStartDetails + internal class ConnectionStartDetails { public byte[] m_locales; public byte[] m_mechanisms; diff --git a/projects/RabbitMQ.Client/client/impl/ConsumerWorkService.cs b/projects/RabbitMQ.Client/client/impl/ConsumerWorkService.cs index a219a8081d..4813fdaf8e 100644 --- a/projects/RabbitMQ.Client/client/impl/ConsumerWorkService.cs +++ b/projects/RabbitMQ.Client/client/impl/ConsumerWorkService.cs @@ -60,12 +60,12 @@ internal Task StopWorkAsync(IModel model) return Task.CompletedTask; } - class WorkPool + private class WorkPool { private readonly Channel _channel; private readonly int _concurrency; private Task _worker; - CancellationTokenSource _tokenSource; + private CancellationTokenSource _tokenSource; private SemaphoreSlim _limiter; public WorkPool(int concurrency) @@ -93,7 +93,7 @@ public void Enqueue(Action action) _channel.Writer.TryWrite(action); } - async Task Loop() + private async Task Loop() { while (await _channel.Reader.WaitToReadAsync().ConfigureAwait(false)) { @@ -111,7 +111,7 @@ async Task Loop() } } - async Task LoopWithConcurrency(CancellationToken cancellationToken) + private async Task LoopWithConcurrency(CancellationToken cancellationToken) { try { @@ -135,7 +135,7 @@ async Task LoopWithConcurrency(CancellationToken cancellationToken) } } - static async Task OffloadToWorkerThreadPool(Action action, SemaphoreSlim limiter) + private static async Task OffloadToWorkerThreadPool(Action action, SemaphoreSlim limiter) { try { diff --git a/projects/RabbitMQ.Client/client/impl/ContentHeaderBase.cs b/projects/RabbitMQ.Client/client/impl/ContentHeaderBase.cs index 62144d0563..b9c2592693 100644 --- a/projects/RabbitMQ.Client/client/impl/ContentHeaderBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ContentHeaderBase.cs @@ -30,11 +30,10 @@ //--------------------------------------------------------------------------- using System; -using System.Text; namespace RabbitMQ.Client.Impl { - abstract class ContentHeaderBase : IContentHeader + internal abstract class ContentHeaderBase : IContentHeader { /// /// Retrieve the AMQP class ID of this content header. @@ -51,8 +50,6 @@ public virtual object Clone() throw new NotImplementedException(); } - public abstract void AppendPropertyDebugStringTo(StringBuilder stringBuilder); - /// /// Fill this instance from the given byte buffer stream. /// diff --git a/projects/RabbitMQ.Client/client/impl/IConsumerDispatcher.cs b/projects/RabbitMQ.Client/client/impl/IConsumerDispatcher.cs index 0c6b0883e7..cc3c5ab1e7 100644 --- a/projects/RabbitMQ.Client/client/impl/IConsumerDispatcher.cs +++ b/projects/RabbitMQ.Client/client/impl/IConsumerDispatcher.cs @@ -34,7 +34,7 @@ namespace RabbitMQ.Client.Impl { - interface IConsumerDispatcher + internal interface IConsumerDispatcher { bool IsShutdown { get; } diff --git a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs index e3ae5f7931..cf0dc14b62 100644 --- a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs @@ -34,7 +34,7 @@ namespace RabbitMQ.Client.Impl { - interface IFrameHandler + internal interface IFrameHandler { AmqpTcpEndpoint Endpoint { get; } diff --git a/projects/RabbitMQ.Client/client/impl/IFullModel.cs b/projects/RabbitMQ.Client/client/impl/IFullModel.cs index 35cd7a3636..157d86ee1e 100644 --- a/projects/RabbitMQ.Client/client/impl/IFullModel.cs +++ b/projects/RabbitMQ.Client/client/impl/IFullModel.cs @@ -32,8 +32,6 @@ using System; using System.Collections.Generic; -using RabbitMQ.Client.Apigen.Attributes; - namespace RabbitMQ.Client.Impl { ///Not part of the public API. Extension of IModel to @@ -51,13 +49,11 @@ namespace RabbitMQ.Client.Impl /// /// /// - interface IFullModel : IModel + internal interface IFullModel : IModel { ///Sends a Connection.TuneOk. Used during connection ///initialisation. - void ConnectionTuneOk(ushort channelMax, - uint frameMax, - ushort heartbeat); + void ConnectionTuneOk(ushort channelMax, uint frameMax, ushort heartbeat); ///Handle incoming Basic.Deliver methods. Dispatches ///to waiting consumers. @@ -66,9 +62,9 @@ void HandleBasicDeliver(string consumerTag, bool redelivered, string exchange, string routingKey, - [AmqpContentHeaderMapping] IBasicProperties basicProperties, - [AmqpContentBodyMapping] ReadOnlyMemory body, - [AmqpContentBodyArrayMapping] byte[] rentedArray); + IBasicProperties basicProperties, + ReadOnlyMemory body, + byte[] rentedArray); ///Handle incoming Basic.Ack methods. Signals a ///BasicAckEvent. @@ -98,15 +94,13 @@ void HandleBasicGetOk(ulong deliveryTag, string exchange, string routingKey, uint messageCount, - [AmqpContentHeaderMapping] IBasicProperties basicProperties, - [AmqpContentBodyMapping] ReadOnlyMemory body, - [AmqpContentBodyArrayMapping] byte[] rentedArray); + IBasicProperties basicProperties, + ReadOnlyMemory body, + byte[] rentedArray); ///Handle incoming Basic.Nack methods. Signals a ///BasicNackEvent. - void HandleBasicNack(ulong deliveryTag, - bool multiple, - bool requeue); + void HandleBasicNack(ulong deliveryTag, bool multiple, bool requeue); ///Handle incoming Basic.RecoverOk methods ///received in reply to Basic.Recover. @@ -119,16 +113,13 @@ void HandleBasicReturn(ushort replyCode, string replyText, string exchange, string routingKey, - [AmqpContentHeaderMapping] IBasicProperties basicProperties, - [AmqpContentBodyMapping] ReadOnlyMemory body, - [AmqpContentBodyArrayMapping] byte[] takeoverPayload); + IBasicProperties basicProperties, + ReadOnlyMemory body, + byte[] takeoverPayload); ///Handle an incoming Channel.Close. Shuts down the ///session and model. - void HandleChannelClose(ushort replyCode, - string replyText, - ushort classId, - ushort methodId); + void HandleChannelClose(ushort replyCode, string replyText, ushort classId, ushort methodId); ///Handle an incoming Channel.CloseOk. void HandleChannelCloseOk(); @@ -138,18 +129,14 @@ void HandleChannelClose(ushort replyCode, void HandleChannelFlow(bool active); ///Handle an incoming Connection.Blocked. - [AmqpMethodMapping(null, "connection", "blocked")] void HandleConnectionBlocked(string reason); ///Handle an incoming Connection.Close. Shuts down the ///connection and all sessions and models. - void HandleConnectionClose(ushort replyCode, - string replyText, - ushort classId, - ushort methodId); + void HandleConnectionClose(ushort replyCode, string replyText, ushort classId, ushort methodId); ///Handle an incoming Connection.OpenOk. - void HandleConnectionOpenOk([AmqpFieldMapping("RabbitMQ.Client.Framing", "reserved1")] string knownHosts); + void HandleConnectionOpenOk(string knownHosts); /////////////////////////////////////////////////////////////////////////// // Connection-related methods, for use in channel 0 during @@ -161,227 +148,141 @@ void HandleConnectionClose(ushort replyCode, ///Handle an incoming Connection.Start. Used during ///connection initialisation. - void HandleConnectionStart(byte versionMajor, - byte versionMinor, - IDictionary serverProperties, - byte[] mechanisms, - byte[] locales); + void HandleConnectionStart(byte versionMajor, byte versionMinor, IDictionary serverProperties, byte[] mechanisms, byte[] locales); ///Handle incoming Connection.Tune ///methods. - void HandleConnectionTune(ushort channelMax, - uint frameMax, - ushort heartbeat); + void HandleConnectionTune(ushort channelMax, uint frameMax, ushort heartbeat); ///Handle an incominga Connection.Unblocked. void HandleConnectionUnblocked(); ///Handle incoming Queue.DeclareOk methods. Routes the ///information to a waiting Queue.DeclareOk continuation. - void HandleQueueDeclareOk(string queue, - uint messageCount, - uint consumerCount); + void HandleQueueDeclareOk(string queue, uint messageCount, uint consumerCount); ///Used to send a Basic.Cancel method. The public ///consume API calls this while also managing internal ///datastructures. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "basic", "cancel")] - void _Private_BasicCancel(string consumerTag, - bool nowait); + void _Private_BasicCancel(string consumerTag, bool nowait); ///Used to send a Basic.Consume method. The public ///consume API calls this while also managing internal ///datastructures. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "basic", "consume")] - void _Private_BasicConsume(string queue, - string consumerTag, - bool noLocal, - [AmqpFieldMapping(null, "noAck")] bool autoAck, - bool exclusive, - bool nowait, - IDictionary arguments); + void _Private_BasicConsume(string queue, string consumerTag, bool noLocal, bool autoAck, bool exclusive, bool nowait, IDictionary arguments); ///Used to send a Basic.Get. Basic.Get is a special ///case, since it can result in a Basic.GetOk or a ///Basic.GetEmpty, so this level of manual control is ///required. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "basic", "get")] - void _Private_BasicGet(string queue, - [AmqpFieldMapping(null, "noAck")] bool autoAck); + void _Private_BasicGet(string queue, bool autoAck); ///Used to send a Basic.Publish method. Called by the ///public publish method after potential null-reference issues ///have been rectified. - [AmqpMethodMapping(null, "basic", "publish")] - void _Private_BasicPublish(string exchange, - string routingKey, - bool mandatory, - [AmqpContentHeaderMapping] IBasicProperties basicProperties, - [AmqpContentBodyMapping] ReadOnlyMemory body); + void _Private_BasicPublish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory body); - [AmqpForceOneWay] - [AmqpMethodMapping(null, "basic", "recover")] void _Private_BasicRecover(bool requeue); ///Used to send a Channel.Close. Called during ///session shutdown. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "channel", "close")] - void _Private_ChannelClose(ushort replyCode, - string replyText, - ushort classId, - ushort methodId); + void _Private_ChannelClose(ushort replyCode, string replyText, ushort classId, ushort methodId); ///Used to send a Channel.CloseOk. Called during ///session shutdown. - [AmqpMethodMapping(null, "channel", "close-ok")] void _Private_ChannelCloseOk(); ///Used to send a Channel.FlowOk. Confirms that ///Channel.Flow from the broker was processed. - [AmqpMethodMapping(null, "channel", "flow-ok")] void _Private_ChannelFlowOk(bool active); ///Used to send a Channel.Open. Called during session ///initialisation. - [AmqpMethodMapping(null, "channel", "open")] - void _Private_ChannelOpen([AmqpFieldMapping("RabbitMQ.Client.Framing", - "reserved1")] string outOfBand); + void _Private_ChannelOpen(string outOfBand); ///Used to send a Confirm.Select method. The public ///confirm API calls this while also managing internal ///datastructures. - [AmqpMethodMapping(null, "confirm", "select")] - void _Private_ConfirmSelect([AmqpNowaitArgument(null)] bool nowait); + void _Private_ConfirmSelect(bool nowait); ///Used to send a Connection.Close. Called during ///connection shutdown. - [AmqpMethodMapping(null, "connection", "close")] - void _Private_ConnectionClose(ushort replyCode, - string replyText, - ushort classId, - ushort methodId); + void _Private_ConnectionClose(ushort replyCode, string replyText, ushort classId, ushort methodId); ///Used to send a Connection.CloseOk. Called during ///connection shutdown. - [AmqpMethodMapping(null, "connection", "close-ok")] void _Private_ConnectionCloseOk(); ///Used to send a Connection.Open. Called during ///connection startup. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "connection", "open")] - void _Private_ConnectionOpen(string virtualHost, - [AmqpFieldMapping("RabbitMQ.Client.Framing", "reserved1")] string capabilities, - [AmqpFieldMapping("RabbitMQ.Client.Framing", "reserved2")] bool insist); + void _Private_ConnectionOpen(string virtualHost, string capabilities, bool insist); ///Used to send a Connection.SecureOk. Again, this is ///special, like Basic.Get. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "connection", "secure-ok")] void _Private_ConnectionSecureOk(byte[] response); ///Used to send a Connection.StartOk. This is ///special, like Basic.Get. - [AmqpForceOneWay] - [AmqpMethodMapping(null, "connection", "start-ok")] - void _Private_ConnectionStartOk(IDictionary clientProperties, - string mechanism, - byte[] response, - string locale); + void _Private_ConnectionStartOk(IDictionary clientProperties, string mechanism, byte[] response, string locale); ///Used to send a Conection.UpdateSecret method. Called by the ///public UpdateSecret method. /// - [AmqpMethodMapping(null, "connection", "update-secret")] void _Private_UpdateSecret(byte[] newSecret, string reason); ///Used to send a Exchange.Bind method. Called by the ///public bind method. /// - [AmqpMethodMapping(null, "exchange", "bind")] - void _Private_ExchangeBind(string destination, - string source, - string routingKey, - [AmqpNowaitArgument(null)] bool nowait, - IDictionary arguments); + void _Private_ExchangeBind(string destination, string source, string routingKey, bool nowait, IDictionary arguments); ///Used to send a Exchange.Declare method. Called by the ///public declare method. /// - [AmqpMethodMapping(null, "exchange", "declare")] void _Private_ExchangeDeclare(string exchange, string type, bool passive, bool durable, bool autoDelete, bool @internal, - [AmqpNowaitArgument(null)] bool nowait, + bool nowait, IDictionary arguments); ///Used to send a Exchange.Delete method. Called by the ///public delete method. /// - [AmqpMethodMapping(null, "exchange", "delete")] - void _Private_ExchangeDelete(string exchange, - bool ifUnused, - [AmqpNowaitArgument(null)] bool nowait); + void _Private_ExchangeDelete(string exchange, bool ifUnused, bool nowait); ///Used to send a Exchange.Unbind method. Called by the ///public unbind method. /// - [AmqpMethodMapping(null, "exchange", "unbind")] - void _Private_ExchangeUnbind(string destination, - string source, - string routingKey, - [AmqpNowaitArgument(null)] bool nowait, - IDictionary arguments); + void _Private_ExchangeUnbind(string destination, string source, string routingKey, bool nowait, IDictionary arguments); ///Used to send a Queue.Bind method. Called by the ///public bind method. - [AmqpMethodMapping(null, "queue", "bind")] - void _Private_QueueBind(string queue, - string exchange, - string routingKey, - [AmqpNowaitArgument(null)] bool nowait, - IDictionary arguments); + void _Private_QueueBind(string queue, string exchange, string routingKey, bool nowait, IDictionary arguments); ///Used to send a Queue.Declare method. Called by the ///public declare method. - [AmqpMethodMapping(null, "queue", "declare")] - [AmqpForceOneWay] void _Private_QueueDeclare(string queue, bool passive, bool durable, bool exclusive, bool autoDelete, - [AmqpNowaitArgument(null)] bool nowait, + bool nowait, IDictionary arguments); ///Used to send a Queue.Delete method. Called by the ///public delete method. - [AmqpMethodMapping(null, "queue", "delete")] - [return: AmqpFieldMapping(null, "messageCount")] - uint _Private_QueueDelete(string queue, - bool ifUnused, - bool ifEmpty, - [AmqpNowaitArgument(null, "0xFFFFFFFF")] bool nowait); + uint _Private_QueueDelete(string queue, bool ifUnused, bool ifEmpty, bool nowait); ///Used to send a Queue.Purge method. Called by the ///public purge method. - [return: AmqpFieldMapping(null, "messageCount")] - [AmqpMethodMapping(null, "queue", "purge")] - uint _Private_QueuePurge(string queue, - [AmqpNowaitArgument(null, "0xFFFFFFFF")] bool nowait); + uint _Private_QueuePurge(string queue, bool nowait); } - ///Essential information from an incoming Connection.Tune ///method. - struct ConnectionTuneDetails + internal struct ConnectionTuneDetails { ///The peer's suggested channel-max parameter. public ushort m_channelMax; @@ -394,181 +295,9 @@ struct ConnectionTuneDetails } - class ConnectionSecureOrTune + internal class ConnectionSecureOrTune { public byte[] m_challenge; public ConnectionTuneDetails m_tuneDetails; } } - -namespace RabbitMQ.Client.Apigen.Attributes -{ - ///Base class for attributes for controlling the API - ///autogeneration process. - abstract class AmqpApigenAttribute : Attribute - { - ///The specification namespace (i.e. version) that - ///this attribute applies to, or null for all specification - ///versions. - public string m_namespaceName; - - public AmqpApigenAttribute(string namespaceName) - { - m_namespaceName = namespaceName; - } - } - - - ///Causes the API generator to ignore the attributed method. - /// - ///Mostly used to declare convenience overloads of - ///various AMQP methods in the IModel interface. Also used - ///to omit an autogenerated implementation of a method which - ///is not required for one protocol version. The API - ///autogeneration process should of course not attempt to produce - ///an implementation of the convenience methods, as they will be - ///implemented by hand with sensible defaults, delegating to the - ///autogenerated variant of the method concerned. - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpMethodDoNotImplementAttribute : AmqpApigenAttribute - { - public AmqpMethodDoNotImplementAttribute(string namespaceName) - : base(namespaceName) - { - } - } - - - ///Causes the API generator to generate asynchronous - ///receive code for the attributed method. - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpAsynchronousHandlerAttribute : AmqpApigenAttribute - { - public AmqpAsynchronousHandlerAttribute(string namespaceName) - : base(namespaceName) - { - } - } - - - ///Causes the API generator to generate - ///exception-throwing code for, instead of simply ignoring, the - ///attributed method. - /// - /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpUnsupportedAttribute : AmqpApigenAttribute - { - public AmqpUnsupportedAttribute(string namespaceName) - : base(namespaceName) - { - } - } - - - ///Informs the API generator which AMQP method field to - ///use for either a parameter in a request, or for a simple result - ///in a reply. - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpFieldMappingAttribute : AmqpApigenAttribute - { - public string m_fieldName; - - public AmqpFieldMappingAttribute(string namespaceName, - string fieldName) - : base(namespaceName) - { - m_fieldName = fieldName; - } - } - - - ///Informs the API generator which AMQP method to use for - ///either a request (if applied to an IModel method) or a reply - ///(if applied to an IModel method result). - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpMethodMappingAttribute : AmqpApigenAttribute - { - public string m_className; - public string m_methodName; - - public AmqpMethodMappingAttribute(string namespaceName, - string className, - string methodName) - : base(namespaceName) - { - m_className = className; - m_methodName = methodName; - } - } - - - ///This attribute, if placed on a parameter in an IModel - ///method, causes it to be interpreted as a "nowait" parameter for - ///the purposes of autogenerated RPC reply continuation management - ///and control. - [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] - class AmqpNowaitArgumentAttribute : AmqpApigenAttribute - { - public string m_replacementExpression; - - public AmqpNowaitArgumentAttribute(string namespaceName) - : this(namespaceName, null) - { - } - - public AmqpNowaitArgumentAttribute(string namespaceName, - string replacementExpression) - : base(namespaceName) - { - m_replacementExpression = replacementExpression; - } - } - - - ///This attribute, if placed on a method in IModel, - ///causes the method to be interpreted as a factory method - ///producing a protocol-specific implementation of a common - ///content header interface. - class AmqpContentHeaderFactoryAttribute : Attribute - { - public string m_contentClass; - - public AmqpContentHeaderFactoryAttribute(string contentClass) - { - m_contentClass = contentClass; - } - } - - - ///This attribute, if placed on a parameter in a - ///content-carrying IModel method, causes it to be sent as part of - ///the content header frame. - class AmqpContentHeaderMappingAttribute : Attribute - { - } - - - ///This attribute, if placed on a parameter in a - ///content-carrying IModel method, causes it to be sent as part of - ///the content body frame. - class AmqpContentBodyMappingAttribute : Attribute - { - } - - ///This attribute, if placed on a parameter in a - ///content-carrying IModel method, causes it to be calling TakeoverPayload. - class AmqpContentBodyArrayMappingAttribute : Attribute - { - } - - - ///This attribute, placed on an IModel method, causes - ///what would normally be an RPC, sent with ModelRpc, to be sent - ///as if it were oneway, with ModelSend. The assumption that this - ///is for a custom continuation (e.g. for BasicConsume/BasicCancel - ///etc.) - class AmqpForceOneWayAttribute : Attribute - { - } -} diff --git a/projects/RabbitMQ.Client/client/impl/IProtocolExtensions.cs b/projects/RabbitMQ.Client/client/impl/IProtocolExtensions.cs index bf6366d17c..fc174c6e02 100644 --- a/projects/RabbitMQ.Client/client/impl/IProtocolExtensions.cs +++ b/projects/RabbitMQ.Client/client/impl/IProtocolExtensions.cs @@ -37,7 +37,7 @@ namespace RabbitMQ.Client.Framing.Impl { - static class IProtocolExtensions + internal static class IProtocolExtensions { public static IFrameHandler CreateFrameHandler( this IProtocol protocol, diff --git a/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs b/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs index 0bd7292364..8cc84d66c0 100644 --- a/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs @@ -31,7 +31,7 @@ namespace RabbitMQ.Client.Impl { - interface IRpcContinuation + internal interface IRpcContinuation { void HandleCommand(in IncomingCommand cmd); void HandleModelShutdown(ShutdownEventArgs reason); diff --git a/projects/RabbitMQ.Client/client/impl/MethodBase.cs b/projects/RabbitMQ.Client/client/impl/MethodBase.cs index f4a1e1097d..54336dc7ff 100644 --- a/projects/RabbitMQ.Client/client/impl/MethodBase.cs +++ b/projects/RabbitMQ.Client/client/impl/MethodBase.cs @@ -29,11 +29,9 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- -using System.Text; - namespace RabbitMQ.Client.Impl { - abstract class MethodBase : IMethod + internal abstract class MethodBase : IMethod { public abstract bool HasContent { get; } @@ -52,7 +50,6 @@ abstract class MethodBase : IMethod /// public abstract string ProtocolMethodName { get; } - public abstract void AppendArgumentDebugStringTo(StringBuilder stringBuilder); public abstract void ReadArgumentsFrom(ref MethodArgumentReader reader); public abstract void WriteArgumentsTo(ref MethodArgumentWriter writer); public abstract int GetRequiredBufferSize(); diff --git a/projects/RabbitMQ.Client/client/impl/ModelBase.cs b/projects/RabbitMQ.Client/client/impl/ModelBase.cs index 8f074dfc23..3c6eba8237 100644 --- a/projects/RabbitMQ.Client/client/impl/ModelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ModelBase.cs @@ -45,7 +45,7 @@ namespace RabbitMQ.Client.Impl { - abstract class ModelBase : IFullModel, IRecoverable + internal abstract class ModelBase : IFullModel, IRecoverable { ///Only used to kick-start a connection open ///sequence. See @@ -330,14 +330,28 @@ public void HandleCommand(in IncomingCommand cmd) } } - public MethodBase ModelRpc(MethodBase method, ContentHeaderBase header, byte[] body) + public T ModelRpc(MethodBase method) where T : MethodBase { var k = new SimpleBlockingRpcContinuation(); + var outgoingCommand = new OutgoingCommand(method); + MethodBase baseResult; lock (_rpcLock) { - TransmitAndEnqueue(new OutgoingCommand(method, header, body), k); - return k.GetReply(ContinuationTimeout).Method; + TransmitAndEnqueue(outgoingCommand, k); + baseResult = k.GetReply(ContinuationTimeout).Method; } + + if (baseResult is T result) + { + return result; + } + + throw new UnexpectedMethodException(baseResult); + } + + public void ModelSend(MethodBase method) + { + ModelSend(method, null, ReadOnlyMemory.Empty); } public void ModelSend(MethodBase method, ContentHeaderBase header, ReadOnlyMemory body) diff --git a/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs b/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs index 816e6388af..6c8e2ee194 100644 --- a/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs +++ b/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs @@ -43,7 +43,7 @@ namespace RabbitMQ.Client.Impl /// under a somewhat generous reading. /// /// - class RpcContinuationQueue + internal class RpcContinuationQueue { private class EmptyRpcContinuation : IRpcContinuation { @@ -55,8 +55,9 @@ public void HandleModelShutdown(ShutdownEventArgs reason) { } } - static readonly EmptyRpcContinuation s_tmp = new EmptyRpcContinuation(); - IRpcContinuation _outstandingRpc = s_tmp; + + private static readonly EmptyRpcContinuation s_tmp = new EmptyRpcContinuation(); + private IRpcContinuation _outstandingRpc = s_tmp; ///Enqueue a continuation, marking a pending RPC. /// diff --git a/projects/RabbitMQ.Client/client/impl/SessionManager.cs b/projects/RabbitMQ.Client/client/impl/SessionManager.cs index 05ded4d5ef..23e2ee1e1d 100644 --- a/projects/RabbitMQ.Client/client/impl/SessionManager.cs +++ b/projects/RabbitMQ.Client/client/impl/SessionManager.cs @@ -36,7 +36,7 @@ namespace RabbitMQ.Client.Impl { - class SessionManager + internal class SessionManager { public readonly ushort ChannelMax; private readonly IntAllocator _ints; diff --git a/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs b/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs index bf0ce9395f..ee77c878f1 100644 --- a/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs @@ -35,7 +35,7 @@ namespace RabbitMQ.Client.Impl { - class ShutdownContinuation + internal class ShutdownContinuation { public readonly BlockingCell m_cell = new BlockingCell(); diff --git a/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs b/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs index 19dccb40a5..5c45a8948b 100644 --- a/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs @@ -35,7 +35,7 @@ namespace RabbitMQ.Client.Impl { - class SimpleBlockingRpcContinuation : IRpcContinuation + internal class SimpleBlockingRpcContinuation : IRpcContinuation { public readonly BlockingCell> m_cell = new BlockingCell>(); diff --git a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs index 09151ceb4c..71f1ce070c 100644 --- a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs @@ -60,7 +60,7 @@ public static async Task TimeoutAfter(this Task task, TimeSpan timeout) } } - class SocketFrameHandler : IFrameHandler + internal class SocketFrameHandler : IFrameHandler { // Socket poll timeout in ms. If the socket does not // become writeable in this amount of time, we throw diff --git a/projects/RabbitMQ.Client/client/impl/SslHelper.cs b/projects/RabbitMQ.Client/client/impl/SslHelper.cs index ee1f0ae31d..7e8abb87fa 100644 --- a/projects/RabbitMQ.Client/client/impl/SslHelper.cs +++ b/projects/RabbitMQ.Client/client/impl/SslHelper.cs @@ -41,7 +41,7 @@ namespace RabbitMQ.Client.Impl /// Represents an which does the actual heavy lifting to set up an SSL connection, /// using the config options in an to make things cleaner. /// - class SslHelper + internal class SslHelper { private readonly SslOption _sslOption; diff --git a/projects/RabbitMQ.Client/client/impl/StreamProperties.cs b/projects/RabbitMQ.Client/client/impl/StreamProperties.cs index e37ae2d5b4..0109e00d99 100644 --- a/projects/RabbitMQ.Client/client/impl/StreamProperties.cs +++ b/projects/RabbitMQ.Client/client/impl/StreamProperties.cs @@ -33,7 +33,7 @@ namespace RabbitMQ.Client.Impl { - abstract class StreamProperties : ContentHeaderBase, IStreamProperties + internal abstract class StreamProperties : ContentHeaderBase, IStreamProperties { public abstract string ContentEncoding { get; set; } public abstract string ContentType { get; set; } diff --git a/projects/RabbitMQ.Client/client/impl/TcpClientAdapter.cs b/projects/RabbitMQ.Client/client/impl/TcpClientAdapter.cs index e0f99fd2f1..2db1e1d53c 100644 --- a/projects/RabbitMQ.Client/client/impl/TcpClientAdapter.cs +++ b/projects/RabbitMQ.Client/client/impl/TcpClientAdapter.cs @@ -8,7 +8,7 @@ namespace RabbitMQ.Client.Impl /// /// Simple wrapper around TcpClient. /// - class TcpClientAdapter : ITcpClient + internal class TcpClientAdapter : ITcpClient { private Socket _sock; @@ -42,10 +42,7 @@ public virtual async Task ConnectAsync(IPAddress ep, int port) public virtual void Close() { - if (_sock != null) - { - _sock.Dispose(); - } + _sock?.Dispose(); _sock = null; } @@ -84,7 +81,10 @@ public virtual bool Connected { get { - if(_sock == null) return false; + if (_sock is null) + { + return false; + } return _sock.Connected; } } @@ -105,7 +105,7 @@ public virtual TimeSpan ReceiveTimeout private void AssertSocket() { - if(_sock == null) + if (_sock is null) { throw new InvalidOperationException("Cannot perform operation as socket is null"); } diff --git a/projects/RabbitMQ.Client/client/impl/TcpClientAdapterHelper.cs b/projects/RabbitMQ.Client/client/impl/TcpClientAdapterHelper.cs index 4fc8b46697..4bb9ce0dfa 100644 --- a/projects/RabbitMQ.Client/client/impl/TcpClientAdapterHelper.cs +++ b/projects/RabbitMQ.Client/client/impl/TcpClientAdapterHelper.cs @@ -5,7 +5,7 @@ namespace RabbitMQ.Client.Impl { - static class TcpClientAdapterHelper + internal static class TcpClientAdapterHelper { public static IPAddress GetMatchingHost(IReadOnlyCollection addresses, AddressFamily addressFamily) { diff --git a/projects/RabbitMQ.Client/client/logging/ESLog.cs b/projects/RabbitMQ.Client/client/logging/ESLog.cs index 1e38ac0f07..dca4c15f4a 100644 --- a/projects/RabbitMQ.Client/client/logging/ESLog.cs +++ b/projects/RabbitMQ.Client/client/logging/ESLog.cs @@ -31,7 +31,7 @@ namespace RabbitMQ.Client.Logging { - static class ESLog + internal static class ESLog { public static void Info(string message) { diff --git a/projects/RabbitMQ.Client/util/BlockingCell.cs b/projects/RabbitMQ.Client/util/BlockingCell.cs index 78fa520aff..8f7c0d2736 100644 --- a/projects/RabbitMQ.Client/util/BlockingCell.cs +++ b/projects/RabbitMQ.Client/util/BlockingCell.cs @@ -44,7 +44,7 @@ namespace RabbitMQ.Util ///attempts to set Value result in a thrown ///InvalidOperationException. /// - class BlockingCell + internal class BlockingCell { private readonly ManualResetEventSlim _manualResetEventSlim = new ManualResetEventSlim(false); private T _value = default; diff --git a/projects/RabbitMQ.Client/util/DebugUtil.cs b/projects/RabbitMQ.Client/util/DebugUtil.cs index 3a6d50f57e..cb73a78111 100644 --- a/projects/RabbitMQ.Client/util/DebugUtil.cs +++ b/projects/RabbitMQ.Client/util/DebugUtil.cs @@ -40,7 +40,7 @@ namespace RabbitMQ.Util /// ///Not part of the public API. /// - static class DebugUtil + internal static class DebugUtil { ///Print a hex dump of the supplied bytes to stdout. public static void Dump(byte[] bytes) diff --git a/projects/RabbitMQ.Client/util/Either.cs b/projects/RabbitMQ.Client/util/Either.cs index b21efa6ce1..0fa8a33a89 100644 --- a/projects/RabbitMQ.Client/util/Either.cs +++ b/projects/RabbitMQ.Client/util/Either.cs @@ -32,7 +32,7 @@ namespace RabbitMQ.Util { ///Used internally by class Either. - enum EitherAlternative + internal enum EitherAlternative { Left, Right @@ -42,7 +42,7 @@ enum EitherAlternative ///Models the disjoint union of two alternatives, a ///"left" alternative and a "right" alternative. ///Borrowed from ML, Haskell etc. - class Either + internal class Either { ///Private constructor. Use the static methods Left, Right instead. private Either(EitherAlternative alternative, L valueL, R valueR) diff --git a/projects/RabbitMQ.Client/util/IntAllocator.cs b/projects/RabbitMQ.Client/util/IntAllocator.cs index 34d1947dd9..39dd8d58f6 100644 --- a/projects/RabbitMQ.Client/util/IntAllocator.cs +++ b/projects/RabbitMQ.Client/util/IntAllocator.cs @@ -37,9 +37,7 @@ namespace RabbitMQ.Util /** * A class for allocating integer IDs in a given range. */ - - - class IntAllocator + internal class IntAllocator { private readonly int[] _unsorted; private IntervalList _base; diff --git a/projects/RabbitMQ.Client/util/SetQueue.cs b/projects/RabbitMQ.Client/util/SetQueue.cs index 9ea7fc42e6..1da9e1713b 100644 --- a/projects/RabbitMQ.Client/util/SetQueue.cs +++ b/projects/RabbitMQ.Client/util/SetQueue.cs @@ -33,14 +33,14 @@ namespace RabbitMQ.Util { - class SetQueue + internal class SetQueue { private readonly HashSet _members = new HashSet(); private readonly LinkedList _queue = new LinkedList(); public bool Enqueue(T item) { - if(_members.Contains(item)) + if (_members.Contains(item)) { return false; } diff --git a/projects/RabbitMQ.Client/util/SharedQueue.cs b/projects/RabbitMQ.Client/util/SharedQueue.cs index 34b6d37b0c..36e53b8b4d 100644 --- a/projects/RabbitMQ.Client/util/SharedQueue.cs +++ b/projects/RabbitMQ.Client/util/SharedQueue.cs @@ -38,13 +38,13 @@ namespace RabbitMQ.Util { ///A thread-safe shared queue implementation. - class SharedQueue : SharedQueue + internal class SharedQueue : SharedQueue { } ///A thread-safe shared queue implementation. - class SharedQueue : IEnumerable + internal class SharedQueue : IEnumerable { ///Flag holding our current status. protected bool m_isOpen = true; @@ -240,7 +240,7 @@ private void EnsureIsOpen() ///Implementation of the IEnumerator interface, for ///permitting SharedQueue to be used in foreach loops. - struct SharedQueueEnumerator : IEnumerator + internal struct SharedQueueEnumerator : IEnumerator { private readonly SharedQueue _queue; private T _current;