Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Utf8String.cs
1using System.IO;
2using System.Text;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Script;
6
8{
13 {
14 private StringAttribute value;
15
22 : base(Parent, Model)
23 {
24 }
25
29 public override string LocalName => nameof(Utf8String);
30
38 {
39 return new Utf8String(Parent, Model);
40 }
41
46 public override Task FromXml(XmlElement Definition)
47 {
48 this.value = new StringAttribute(Definition.InnerText);
49 return Task.CompletedTask;
50 }
51
57 public async Task Append(MemoryStream Output, Variables Variables)
58 {
59 string s = await this.value.GetValueAsync(Variables);
60 byte[] Bin = Encoding.UTF8.GetBytes(s);
61 int c = Bin.Length;
62 int i = c;
63 byte b;
64
65 do
66 {
67 b = (byte)(i & 127);
68 i >>= 7;
69 if (i != 0)
70 b |= 128;
71
72 Output.WriteByte(b);
73 }
74 while (i != 0);
75
76 Output.Write(Bin, 0, c);
77 }
78 }
79}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for simulation nodes
ISimulationNode Parent
Parent node in the simulation model.
Contains the value of a string attribute, possibly with embedded script.
async Task< string > GetValueAsync(Variables Variables)
Gets the value of the attribute.
override string LocalName
Local name of Binary element defining contents of class.
Definition: Utf8String.cs:29
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with Binary definition.
Definition: Utf8String.cs:46
async Task Append(MemoryStream Output, Variables Variables)
Appends the binary element to the output stream.
Definition: Utf8String.cs:57
Utf8String(ISimulationNode Parent, Model Model)
Utf8String value.
Definition: Utf8String.cs:21
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Utf8String.cs:37
Collection of variables.
Definition: Variables.cs:25
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...