-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from iCsysAS/master
Add new types and make extensionobject encoding/decoding extendable
- Loading branch information
Showing
5 changed files
with
275 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using LibUA.Core; | ||
using System; | ||
|
||
namespace LibUA.ValueTypes; | ||
|
||
public class EUInformation | ||
{ | ||
public string NameSpaceUri { get; set; } = "http://www.opcfoundation.org/UA/units/un/cefact"; | ||
public int UnitId { get; set; } = -1; | ||
public LocalizedText DisplayName { get; set; } = new(""); | ||
public LocalizedText Description { get; set; } = new(""); | ||
} | ||
|
||
public static class EUInformationExtensions | ||
{ | ||
public static int CodingSize(this MemoryBuffer mem, EUInformation dv) | ||
{ | ||
int sum = 0; | ||
|
||
sum += mem.CodingSizeUAString(dv.NameSpaceUri); | ||
sum += mem.CodingSize(dv.UnitId); | ||
sum += mem.CodingSize(dv.DisplayName); | ||
sum += mem.CodingSize(dv.Description); | ||
|
||
return sum; | ||
} | ||
|
||
public static bool Encode(this MemoryBuffer mem, EUInformation item) | ||
{ | ||
if (!mem.EncodeUAString(item.NameSpaceUri)) { return false; } | ||
if (!mem.Encode(item.UnitId)) { return false; } | ||
if (!mem.Encode(item.DisplayName)) { return false; } | ||
if (!mem.Encode(item.Description)) { return false; } | ||
|
||
return true; | ||
} | ||
|
||
public static bool Decode(this MemoryBuffer mem, out EUInformation wv) | ||
{ | ||
wv = null; | ||
|
||
if (!mem.DecodeUAString(out string namespaceUri)) { return false; } | ||
if (!mem.Decode(out int unitId)) { return false; } | ||
if (!mem.Decode(out LocalizedText displayName)) { return false; } | ||
if (!mem.Decode(out LocalizedText description)) { return false; } | ||
|
||
try | ||
{ | ||
wv = new EUInformation() | ||
{ | ||
NameSpaceUri = namespaceUri, | ||
UnitId = unitId, | ||
DisplayName = displayName, | ||
Description = description | ||
}; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using LibUA.Core; | ||
|
||
namespace LibUA.ValueTypes; | ||
|
||
public class OpcRange | ||
{ | ||
public double High { get; set; } | ||
public double Low { get; set; } | ||
} | ||
|
||
public static class RangeExtensions | ||
{ | ||
public static int CodingSize(this MemoryBuffer mem, OpcRange dv) | ||
{ | ||
int sum = 0; | ||
|
||
sum += mem.CodingSize(dv.Low); | ||
sum += mem.CodingSize(dv.High); | ||
|
||
return sum; | ||
} | ||
|
||
public static bool Encode(this MemoryBuffer mem, OpcRange item) | ||
{ | ||
if (!mem.Encode(item.Low)) { return false; } | ||
if (!mem.Encode(item.High)) { return false; } | ||
|
||
return true; | ||
} | ||
|
||
public static bool Decode(this MemoryBuffer mem, out OpcRange wv) | ||
{ | ||
wv = null; | ||
|
||
if (!mem.Decode(out double low)) { return false; } | ||
if (!mem.Decode(out double high)) { return false; } | ||
|
||
try | ||
{ | ||
wv = new OpcRange() | ||
{ | ||
High = high, | ||
Low = low | ||
}; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |