using json as serializer
This commit is contained in:
1 parent
80b54cad25
commit
eb9e17d2e6
6 files changed
+12
-9
No files matched your search
@@ -31,6 +31,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>bin\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Vocaluxe.Base.Server
|
||||
{
|
||||
public static class CCommands
|
||||
{
|
||||
private static UTF8Encoding encoder = new UTF8Encoding();
|
||||
|
||||
public static SHA256Managed SHA256 = new SHA256Managed();
|
||||
|
||||
public const int ResponseOK = 1;
|
||||
@@ -75,9 +76,8 @@ namespace Vocaluxe.Base.Server
|
||||
byte[] data;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
formatter.Serialize(ms, obj);
|
||||
data = ms.ToArray();
|
||||
string json = JsonConvert.SerializeObject(obj);
|
||||
data = encoder.GetBytes(json);
|
||||
}
|
||||
stream.Write(data, 0, data.Length);
|
||||
return stream.ToArray();
|
||||
@@ -99,11 +99,10 @@ namespace Vocaluxe.Base.Server
|
||||
{
|
||||
try
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
obj = (T)formatter.Deserialize(ms);
|
||||
obj = JsonConvert.DeserializeObject<T>(encoder.GetString(data));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Vocaluxe.Base.Server
|
||||
{
|
||||
[Serializable]
|
||||
public struct SLoginData
|
||||
{
|
||||
public byte[] SHA256;
|
||||
|
||||
Reference in new issue
Block a user