Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hhblaze committed Aug 22, 2018
1 parent c800833 commit 66ecf05
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Biser/Json/JsonEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public JsonEncoder(JsonSettings settings=null)
sb.Append("{"); //Always start as an object
}

public JsonEncoder(IJsonEncoder obj, JsonSettings settings = null)
: this(settings)
{
if(obj != null)
obj.BiserJsonEncode(this);
}

void AddProp(string str)
{
Expand Down Expand Up @@ -52,6 +58,12 @@ void AddNull()
sb.Append("null");
}

public string GetJSON(JsonSettings.JsonStringStyle style)
{
this.jsonSettings.JsonStringFormat = style;
return GetJSON();
}

public string GetJSON()
{
if (finished == null)
Expand Down
Binary file modified Biser/bin/Debug/Biser.dll
Binary file not shown.
Binary file modified Biser/bin/Release-NET47/Biser.dll
Binary file not shown.
Binary file modified Biser/bin/Release/Biser.dll
Binary file not shown.
129 changes: 126 additions & 3 deletions BiserTest_Net/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ static void Main(string[] args)
// DateFormat = NetJSON.NetJSONDateFormat.ISO
//});

JsonEncoder jenc = new JsonEncoder(new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default,
JsonEncoder jenc = new JsonEncoder(null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default,
JsonStringFormat = JsonSettings.JsonStringStyle.Prettify });
jsts1.BiserJsonEncode(jenc);
// jsts1.BiserJsonEncode(jenc);


string wow1 = jenc.GetJSON();

var jsts1d1 = TS1.BiserJsonDecode(wow1, null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default });

//StreamReader sr=new StreamReader("",Encoding.UTF8)
//StreamWriter sw=new StreamWriter()
Console.WriteLine("Press to start test");
Expand Down Expand Up @@ -516,6 +516,129 @@ static void Main(string[] args)
//var d4 = decoder.GetFloat();
}

#region "test JSONv1"
public class t1 : Biser.IJsonEncoder
{
public int p1 { get; set; }
public string p2 { get; set; }
public t2 p3 { get; set; }

public void BiserJsonEncode(Biser.JsonEncoder encoder)
{
encoder.Add("p1", this.p1);
encoder.Add("p2", this.p2);
encoder.Add("p3", this.p3);

}

public static t1 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type
{
Biser.JsonDecoder decoder = null;

if (extDecoder == null)
{
if (enc == null || String.IsNullOrEmpty(enc))
return null;
decoder = new Biser.JsonDecoder(enc, settings);
if (decoder.CheckNull())
return null;
}
else
{
//JSONSettings of the existing decoder will be used
decoder = extDecoder;
}

t1 m = new t1(); //!!!!!!!!!!!!!! change return type
foreach (var props in decoder.GetDictionary<string>())
{
switch (props)
{
case "p1":
m.p1 = decoder.GetInt();
break;
case "p2":
m.p2 = decoder.GetString();
break;
case "p3":
m.p3 = t2.BiserJsonDecode(null, decoder);
break;
default:
decoder.SkipValue();
break;
}
}
return m;
}
}

public class t2 : Biser.IJsonEncoder
{
public DateTime p1 { get; set; }
public string p2 { get; set; }

public void BiserJsonEncode(Biser.JsonEncoder encoder)
{
encoder.Add("p1", this.p1);
encoder.Add("p2", this.p2);
}

public static t2 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type
{
Biser.JsonDecoder decoder = null;

if (extDecoder == null)
{
if (enc == null || String.IsNullOrEmpty(enc))
return null;
decoder = new Biser.JsonDecoder(enc, settings);
if (decoder.CheckNull())
return null;
}
else
{
//JSONSettings of the existing decoder will be used
decoder = extDecoder;
}

t2 m = new t2(); //!!!!!!!!!!!!!! change return type
foreach (var props in decoder.GetDictionary<string>())
{
switch (props)
{
case "p1":
m.p1 = decoder.GetDateTime();
break;
case "p2":
m.p2 = decoder.GetString();
break;
default:
decoder.SkipValue();
break;
}
}
return m;
}


}

static void TestJSONv1()
{
t1 ot1 = new t1()
{
p1 = 12,
p2 = "dsfg",
p3 = new t2 { p1 = DateTime.UtcNow, p2 = "uioziuz" }
};

var jsonSet = new Biser.JsonSettings { DateFormat = Biser.JsonSettings.DateTimeStyle.ISO };
Biser.JsonEncoder enc = new Biser.JsonEncoder(ot1, jsonSet);
string es = enc.GetJSON(Biser.JsonSettings.JsonStringStyle.Prettify);
var ot2 = t1.BiserJsonDecode(es, settings: jsonSet);
}
#endregion

static void TestBE1()
{
//Testing slower biser extensions
Expand Down
Binary file modified Biser_Standard/bin/Release/netstandard2.0/Biser.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Deployment/!!!Biser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Biser</id>
<version>1.6.0</version>
<version>1.6.1</version>
<title>Biser.NET dotnet binary and JSON serializer</title>
<authors>Alex Solovyov</authors>
<owners>tiesky.com / Alex Solovyov</owners>
Expand Down
Binary file modified Deployment/Biser.1.6.0.nupkg
Binary file not shown.
Binary file added Deployment/Biser.1.6.1.nupkg
Binary file not shown.

0 comments on commit 66ecf05

Please sign in to comment.