Skip to content

Commit d3e5d28

Browse files
authored
Version 1.1.8 (#1)
* Added a MsgPack serializer to the repository.
1 parent 2cf995b commit d3e5d28

7 files changed

Lines changed: 163 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ An easy to use RabbitMQ Client for .Net.
88

99
## How to install
1010

11-
In the csproj add a PackageReference to the [RabbitExpress.JsonSerializer](RabbitExpress.JsonSerializer/README.md) package.
11+
In the csproj add a PackageReference to the [RabbitExpress.JsonSerializer](RabbitExpress.JsonSerializer/README.md) or the [RabbitExpress.MsgPackSerializer](RabbitExpress.MsgPackSerializer/README.md) package.
1212

1313
```xml
1414
<ItemGroup>
1515
<PackageReference Include="RabbitExpress.JsonSerializer" Version="*" />
1616
</ItemGroup>
1717
```
1818

19+
```xml
20+
<ItemGroup>
21+
<PackageReference Include="RabbitExpress.MsgPackSerializer" Version="*" />
22+
</ItemGroup>
23+
```
1924

2025
## Publisher usage
2126

RabbitExpress.ExamplePublisher/RabbitExpress.ExamplePublisher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
1111
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
13-
<PackageReference Include="RabbitExpress.JsonSerializer" Version="*" />
13+
<PackageReference Include="RabbitExpress.JsonSerializer" Version="1.*" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

RabbitExpress.ExampleWorker/RabbitExpress.ExampleWorker.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
1111
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
13-
<PackageReference Include="RabbitExpress.JsonSerializer" Version="*" />
13+
<PackageReference Include="RabbitExpress.JsonSerializer" Version="1.*" />
1414
</ItemGroup>
1515

1616
<ItemGroup>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ***********************************************************************
2+
// Assembly : RabbitExpress.MsgPackSerializer
3+
// Author : ReneWindegger
4+
// Created : 05-11-2019
5+
//
6+
// Last Modified By : ReneWindegger
7+
// Last Modified On : 05-11-2019
8+
// ***********************************************************************
9+
// <copyright file="MsgPackSerializer.cs" company="Rene Windegger">
10+
// Copyright (c) Rene Windegger. All rights reserved.
11+
// </copyright>
12+
// <summary>
13+
// This file is part of RabbitExpress.
14+
//
15+
// RabbitExpress is free software: you can redistribute it and/or modify
16+
// it under the terms of the GNU Lesser General Public License as published by
17+
// the Free Software Foundation, either version 3 of the License, or
18+
// (at your option) any later version.
19+
//
20+
// RabbitExpress is distributed in the hope that it will be useful,
21+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
// GNU Lesser General Public License for more details.
24+
//
25+
// You should have received a copy of the GNU Lesser General Public License
26+
// along with this RabbitExpress. If not, see <http://www.gnu.org/licenses/>.
27+
// </summary>
28+
// ***********************************************************************
29+
namespace RabbitExpress
30+
{
31+
using MsgPack.Serialization;
32+
using System;
33+
using System.Collections.Concurrent;
34+
35+
/// <summary>
36+
/// Class MsgPackSerializer.
37+
/// Implements the <see cref="RabbitExpress.IExpressSerializer" />
38+
/// </summary>
39+
/// <seealso cref="RabbitExpress.IExpressSerializer" />
40+
public class MsgPackSerializer : IExpressSerializer
41+
{
42+
/// <summary>
43+
/// The serializer cache
44+
/// </summary>
45+
private static readonly ConcurrentDictionary<Type, MessagePackSerializer> SerializerCache =
46+
new ConcurrentDictionary<Type, MessagePackSerializer>();
47+
48+
/// <summary>
49+
/// Deserializes the specified data.
50+
/// </summary>
51+
/// <typeparam name="TObject">The type of the object.</typeparam>
52+
/// <param name="data">The data.</param>
53+
/// <returns>TObject.</returns>
54+
public TObject Deserialize<TObject>(byte[] data)
55+
{
56+
var responseSerializer = SerializerCache.GetOrAdd(typeof(TObject), MessagePackSerializer.Get<TObject>()) as MessagePackSerializer<TObject>;
57+
if (responseSerializer != null)
58+
return responseSerializer.UnpackSingleObject(data);
59+
60+
return default(TObject);
61+
}
62+
63+
/// <summary>
64+
/// Serializes the specified value.
65+
/// </summary>
66+
/// <typeparam name="TObject">The type of the object.</typeparam>
67+
/// <param name="value">The value.</param>
68+
/// <returns>System.Byte[].</returns>
69+
public byte[] Serialize<TObject>(TObject value)
70+
{
71+
var responseSerializer = SerializerCache.GetOrAdd(typeof(TObject), MessagePackSerializer.Get<TObject>()) as MessagePackSerializer<TObject>;
72+
if (responseSerializer != null)
73+
return responseSerializer.PackSingleObject(value);
74+
75+
return new byte[0];
76+
}
77+
}
78+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# MsgPack Serializer
2+
3+
This library provides an implementation of a very simple serializer.
4+
5+
## Add the reference
6+
7+
In your csproj add a PackageReference to this package.
8+
9+
```xml
10+
<ItemGroup>
11+
<PackageReference Include="RabbitExpress.MsgPackSerializer" Version="*" />
12+
</ItemGroup>
13+
```
14+
15+
## The serializer
16+
17+
This is a very simple serializer to be used in the [RabbitExpress.QueueClient](../RabbitExpress/README.md). The implementation uses [MsgPack.Cli](https://msgpack.org/index.html) to serialize and deserialize the transfered messages.
18+
19+
```c-sharp
20+
public class MsgPackSerializer : IExpressSerializer
21+
{
22+
private static readonly ConcurrentDictionary<Type, MessagePackSerializer> SerializerCache =
23+
new ConcurrentDictionary<Type, MessagePackSerializer>();
24+
25+
public TObject Deserialize<TObject>(byte[] data)
26+
{
27+
var responseSerializer = SerializerCache.GetOrAdd(typeof(TObject), MessagePackSerializer.Get<TObject>()) as MessagePackSerializer<TObject>;
28+
if (responseSerializer != null)
29+
return responseSerializer.UnpackSingleObject(data);
30+
31+
return default(TObject);
32+
}
33+
34+
public byte[] Serialize<TObject>(TObject value)
35+
{
36+
var responseSerializer = SerializerCache.GetOrAdd(typeof(TObject), MessagePackSerializer.Get<TObject>()) as MessagePackSerializer<TObject>;
37+
if (responseSerializer != null)
38+
return responseSerializer.PackSingleObject(value);
39+
40+
return new byte[0];
41+
}
42+
}
43+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<Authors>Rene Windegger</Authors>
7+
<Company>Rene Windegger</Company>
8+
<Product>RabbitExpress</Product>
9+
<Description>A simple MsgPack serializer implementation for usage in RabbitExpress.</Description>
10+
<PackageLicenseUrl>https://github.com/rwindegger/RabbitExpress/blob/master/LICENSE</PackageLicenseUrl>
11+
<PackageProjectUrl>https://rwindegger.github.io/RabbitExpress/</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/rwindegger/RabbitExpress</RepositoryUrl>
13+
<PackageTags>rabbitmq rabbitmq-client</PackageTags>
14+
<Version>99.99.99.99</Version>
15+
<PackageVersion>99.99.99.99</PackageVersion>
16+
<AssemblyVersion>99.99.99.99</AssemblyVersion>
17+
<FileVersion>99.99.99.99</FileVersion>
18+
<InformationalVersion>99.99.99.99</InformationalVersion>
19+
<RootNamespace>RabbitExpress</RootNamespace>
20+
</PropertyGroup>
21+
<ItemGroup>
22+
<PackageReference Include="MsgPack.Cli" Version="1.0.1" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<ProjectReference Include="..\RabbitExpress\RabbitExpress.csproj" />
26+
</ItemGroup>
27+
</Project>

RabbitExpress.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitExpress.ExampleShared
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitExpress.ExamplePublisher", "RabbitExpress.ExamplePublisher\RabbitExpress.ExamplePublisher.csproj", "{C101FC21-3B09-420B-A683-FE94A547F2A6}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RabbitExpress.JsonSerializer", "RabbitExpress.JsonSerializer\RabbitExpress.JsonSerializer.csproj", "{BD13DBE4-F0B2-4B22-817F-C52DB1591991}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitExpress.JsonSerializer", "RabbitExpress.JsonSerializer\RabbitExpress.JsonSerializer.csproj", "{BD13DBE4-F0B2-4B22-817F-C52DB1591991}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RabbitExpress.MsgPackSerializer", "RabbitExpress.MsgPackSerializer\RabbitExpress.MsgPackSerializer.csproj", "{0662DB08-D603-4023-B9F2-D3E7A756130C}"
1517
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
3941
{BD13DBE4-F0B2-4B22-817F-C52DB1591991}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{BD13DBE4-F0B2-4B22-817F-C52DB1591991}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{BD13DBE4-F0B2-4B22-817F-C52DB1591991}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{0662DB08-D603-4023-B9F2-D3E7A756130C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{0662DB08-D603-4023-B9F2-D3E7A756130C}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{0662DB08-D603-4023-B9F2-D3E7A756130C}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{0662DB08-D603-4023-B9F2-D3E7A756130C}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)