From 5262b420ea66d3da65741c22ef085a360f311fa4 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 7 Oct 2019 09:08:42 +0200 Subject: [PATCH] Add JSONIpv6Mapping --- ln.json.csproj | 1 + mapping/JSONIPv6Mapping.cs | 31 +++++++++++++++++++++++++++++++ mapping/JSONMapper.cs | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 mapping/JSONIPv6Mapping.cs diff --git a/ln.json.csproj b/ln.json.csproj index ce97897..dcec643 100644 --- a/ln.json.csproj +++ b/ln.json.csproj @@ -55,6 +55,7 @@ + diff --git a/mapping/JSONIPv6Mapping.cs b/mapping/JSONIPv6Mapping.cs new file mode 100644 index 0000000..c03d96f --- /dev/null +++ b/mapping/JSONIPv6Mapping.cs @@ -0,0 +1,31 @@ +// /** +// * File: JSONIPv6Mapping.cs +// * Author: haraldwolff +// * +// * This file and it's content is copyrighted by the Author and / or copyright holder. +// * Any use wihtout proper permission is illegal and may lead to legal actions. +// * +// * +// **/ +using System; +using ln.types; +namespace ln.json.mapping +{ + public class JSONIPv6Mapping : JSONMapping + { + public JSONIPv6Mapping() :base(typeof(IPv6)) + { + } + + public override object FromJson(JSONMapper mapper, JSONValue json) + { + return IPv6.Parse((json as JSONString).Value); + } + + public override JSONValue ToJson(JSONMapper mapper, object value) + { + return new JSONString((value as IPv6).ToCIDR()); + } + + } +} diff --git a/mapping/JSONMapper.cs b/mapping/JSONMapper.cs index e61cc5c..dd24e14 100644 --- a/mapping/JSONMapper.cs +++ b/mapping/JSONMapper.cs @@ -108,6 +108,8 @@ namespace ln.json.mapping Add(new JSONRPCCallMapping()); Add(new JSONRPCResultMapping()); + Add(new JSONIPv6Mapping()); + } public void Add(JSONMapping mapping)