TopicFilters { get; set; }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs.Mqtt/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | using System.Reflection;
5 | using System.Resources;
6 |
7 | [assembly: NeutralResourcesLanguage("en-US")]
8 | [assembly: AssemblyMetadata("Serviceable", "True")]
--------------------------------------------------------------------------------
/src/DotNetty.Codecs.Mqtt/Properties/Friends.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | using System.Runtime.CompilerServices;
5 |
6 | #if !NOTEST
7 |
8 | //[assembly: InternalsVisibleTo("DotNetty.Codecs.Mqtt.Tests")]
9 |
10 | #endif
--------------------------------------------------------------------------------
/src/DotNetty.Codecs.Mqtt/Signatures.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs.Mqtt
5 | {
6 | using System.Runtime.CompilerServices;
7 | using DotNetty.Codecs.Mqtt.Packets;
8 |
9 | static class Signatures
10 | {
11 | const byte QoS1Signature = (int)QualityOfService.AtLeastOnce << 1;
12 |
13 | // most often used (anticipated) come first
14 |
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | public static bool IsPublish(int signature)
17 | {
18 | const byte TypeOnlyMask = 0xf << 4;
19 | return (signature & TypeOnlyMask) == ((int)PacketType.PUBLISH << 4);
20 | }
21 |
22 | public const byte PubAck = (int)PacketType.PUBACK << 4;
23 | public const byte PubRec = (int)PacketType.PUBREC << 4;
24 | public const byte PubRel = ((int)PacketType.PUBREL << 4) | QoS1Signature;
25 | public const byte PubComp = (int)PacketType.PUBCOMP << 4;
26 | public const byte Connect = (int)PacketType.CONNECT << 4;
27 | public const byte ConnAck = (int)PacketType.CONNACK << 4;
28 | public const byte Subscribe = ((int)PacketType.SUBSCRIBE << 4) | QoS1Signature;
29 | public const byte SubAck = (int)PacketType.SUBACK << 4;
30 | public const byte PingReq = (int)PacketType.PINGREQ << 4;
31 | public const byte PingResp = (int)PacketType.PINGRESP << 4;
32 | public const byte Disconnect = (int)PacketType.DISCONNECT << 4;
33 | public const byte Unsubscribe = ((int)PacketType.UNSUBSCRIBE << 4) | QoS1Signature;
34 | public const byte UnsubAck = (int)PacketType.UNSUBACK << 4;
35 | }
36 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs.Mqtt/Util.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs.Mqtt
5 | {
6 | static class Util
7 | {
8 | public const string ProtocolName = "MQTT";
9 | public const int ProtocolLevel = 4;
10 |
11 | static readonly char[] TopicWildcards = { '#', '+' };
12 |
13 | public static void ValidateTopicName(string topicName)
14 | {
15 | if (topicName.Length == 0)
16 | {
17 | throw new DecoderException("[MQTT-4.7.3-1]");
18 | }
19 |
20 | if (topicName.IndexOfAny(TopicWildcards) > 0)
21 | {
22 | throw new DecoderException(string.Format("Invalid PUBLISH topic name: {0}", topicName));
23 | }
24 | }
25 |
26 | public static void ValidatePacketId(int packetId)
27 | {
28 | if (packetId < 1)
29 | {
30 | throw new DecoderException("Invalid packet identifier: " + packetId);
31 | }
32 | }
33 |
34 | public static void ValidateClientId(string clientId)
35 | {
36 | if (clientId == null)
37 | {
38 | throw new DecoderException("Client identifier is required.");
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/CodecException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs
5 | {
6 | using System;
7 |
8 | ///
9 | /// An which is thrown by a codec.
10 | ///
11 | [Serializable]
12 | public class CodecException : Exception
13 | {
14 | public CodecException()
15 | {
16 | }
17 |
18 | public CodecException(string message, Exception innereException)
19 | : base(message, innereException)
20 | {
21 | }
22 |
23 | public CodecException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | public CodecException(Exception innerException)
29 | : base(null, innerException)
30 | {
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/CorruptedFrameException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 | namespace DotNetty.Codecs
4 | {
5 | using System;
6 |
7 | ///
8 | /// A which is thrown when the received frame data could not
9 | /// be decoded by an inbound handler.
10 | ///
11 | public class CorruptedFrameException : DecoderException
12 | {
13 | public CorruptedFrameException(string message)
14 | : base(message)
15 | {
16 | }
17 |
18 | public CorruptedFrameException(Exception cause)
19 | : base(cause)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/DecoderException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs
5 | {
6 | using System;
7 |
8 | public class DecoderException : Exception
9 | {
10 | public DecoderException(string message)
11 | : base(message)
12 | {
13 | }
14 |
15 | public DecoderException(Exception cause)
16 | : base(null, cause)
17 | {
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/DotNetty.Codecs.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @project@
5 | @project@@title@
6 | @build.number@
7 | @authors@
8 | @authors@
9 | Common wire format codecs DotNetty.
10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt
11 | https://github.com/Azure/DotNetty/
12 | false
13 | @releaseNotes@
14 | @copyright@
15 | @tags@ codecs encoding framing decoding
16 | @dependencies@
17 | @references@
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/EncoderException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs
5 | {
6 | using System;
7 |
8 | public class EncoderException : Exception
9 | {
10 | public EncoderException(string message)
11 | : base(message)
12 | {
13 | }
14 |
15 | public EncoderException(Exception innerException)
16 | : base(null, innerException)
17 | {
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | using System.Reflection;
5 | using System.Resources;
6 |
7 | [assembly: NeutralResourcesLanguage("en-US")]
8 | [assembly: AssemblyMetadata("Serviceable", "True")]
--------------------------------------------------------------------------------
/src/DotNetty.Codecs/Strings/StringEncoder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace DotNetty.Codecs
5 | {
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Text;
9 | using DotNetty.Buffers;
10 | using DotNetty.Transport.Channels;
11 |
12 | /**
13 | * Encodes the requested {@link String} into a {@link ByteBuf}.
14 | * A typical setup for a text-based line protocol in a TCP/IP socket would be:
15 | *
16 | * {@link ChannelPipeline} pipeline = ...;
17 | *
18 | * // Decoders
19 | * pipeline.addLast("frameDecoder", new {@link LineBasedFrameDecoder}(80));
20 | * pipeline.addLast("stringDecoder", new {@link StringDecoder}(CharsetUtil.UTF_8));
21 | *
22 | * // Encoder
23 | * pipeline.addLast("stringEncoder", new {@link StringEncoder}(CharsetUtil.UTF_8));
24 | *
25 | * and then you can use a {@link String} instead of a {@link ByteBuf}
26 | * as a message:
27 | *
28 | * void channelRead({@link ChannelHandlerContext} ctx, {@link String} msg) {
29 | * ch.write("Did you say '" + msg + "'?\n");
30 | * }
31 | *
32 | */
33 | public class StringEncoder : MessageToMessageEncoder
34 | {
35 | readonly Encoding encoding;
36 |
37 | ///
38 | /// Initializes a new instance of the class with the current system character set.
39 | ///
40 | public StringEncoder() : this(Encoding.Default)
41 | {
42 | }
43 |
44 | ///
45 | /// Initializes a new instance of the class with the specified character set..
46 | ///
47 | /// Encoding.
48 | public StringEncoder(Encoding encoding)
49 | {
50 | if (encoding == null)
51 | {
52 | throw new NullReferenceException("encoding");
53 | }
54 |
55 | this.encoding = encoding;
56 | }
57 |
58 | public override bool IsSharable
59 | {
60 | get { return true; }
61 | }
62 |
63 | protected override void Encode(IChannelHandlerContext context, string message, List