/// <summary> /// Gets the integer value of the child leaf with the specified tag. /// Throws an exception if this EmberNode is not derived from EmberContainer. /// </summary> /// <param name="tag">The tag of the leaf whose value to return.</param> /// <param name="value">Received the value of the child node with the specified tag /// if a child leaf of type int or long exists.</param> /// <returns>True if a fitting child leaf exists and <paramref name="value"/> /// has received its value.</returns> public static bool GetInteger(this EmberNode node, BerTag tag, out long value) { var child = node[tag]; if (child != null && child.BerTypeNumber == BerType.Integer) { var integerLeaf = child as EmberLeaf <int>; if (integerLeaf != null) { value = integerLeaf.Value; return(true); } var longLeaf = child as EmberLeaf <long>; if (longLeaf != null) { value = longLeaf.Value; return(true); } } value = 0; return(false); }
GlowStreamDescription ConvertStreamDescription(BerTag tag, XElement xml) { return(new GlowStreamDescription( tag, XmlConvert.ToInt32(xml.Element("format").Value), XmlConvert.ToInt32(xml.Element("offset").Value))); }
/// <summary> /// Asserts that no node with the specified tag is already present in this container. /// </summary> protected void AssertNotPresent(BerTag tag) { if (this[tag] != null) { throw new InvalidOperationException("Node with specified tag is already present"); } }
internal override int Update() { var output = new BerMemoryOutput(); var implicitTag = new BerTag(BerClass.Universal, BerTypeNumber, true); var childrenLength = 0; foreach (var child in this) { childrenLength += child.IsDirty ? child.Update() : child.EncodedLength; } BerEncoding.EncodeTag(output, Tag.ToContainer()); BerEncoding.EncodeLength(output, BerDefinitions.IndefiniteLength); BerEncoding.EncodeTag(output, implicitTag); BerEncoding.EncodeLength(output, BerDefinitions.IndefiniteLength); _encodedFrameHeader = output.ToArray(); EncodedLength = childrenLength + _encodedFrameHeader.Length + BerEncoding.IndefiniteLengthTerminator.Length; return(EncodedLength); }
public AsyncContainer(BerTag tag, uint type, int length) { Tag = tag; Type = type; Length = length; BytesRead = 0; }
public override EmberNode CreateNodeFromXml(uint type, BerTag tag, XmlReader reader) { switch(type) { case GlowType.Parameter: return new GlowParameter(tag); case GlowType.Command: return new GlowCommand(tag); case GlowType.Node: return new GlowNode(tag); case GlowType.ElementCollection: return new GlowElementCollection(tag); case GlowType.StreamEntry: return new GlowStreamEntry(tag); case GlowType.StreamCollection: return new GlowStreamCollection(tag); case GlowType.StringIntegerPair: return new GlowStringIntegerPair(tag); case GlowType.StringIntegerCollection: return new GlowStringIntegerCollection(tag); case GlowType.QualifiedNode: return new GlowQualifiedNode(tag); case GlowType.QualifiedParameter: return new GlowQualifiedParameter(tag); case GlowType.RootElementCollection: return new GlowRootElementCollection(tag); case GlowType.StreamDescription: return new GlowStreamDescription(tag); case GlowType.Matrix: return new GlowMatrix(tag); case GlowType.Target: return new GlowTarget(tag); case GlowType.Source: return new GlowSource(tag); case GlowType.Connection: return new GlowConnection(tag); case GlowType.QualifiedMatrix: return new GlowQualifiedMatrix(tag); case GlowType.Label: return new GlowLabel(tag); case GlowType.Function: return new GlowFunction(tag); case GlowType.QualifiedFunction: return new GlowQualifiedFunction(tag); case GlowType.TupleItemDescription: return new GlowTupleItemDescription(tag); case GlowType.Invocation: return new GlowInvocation(tag); case GlowType.InvocationResult: return new GlowInvocationResult(tag); case GlowType.Template: return new GlowTemplate(tag); } return base.CreateNodeFromXml(type, tag, reader); }
public void Write(BerTag tag, bool value) { WriteOuterHeader(tag, 3); BerEncoding.EncodeTag(_output, new BerTag(BerType.Boolean)); BerEncoding.EncodeLength(_output, 1); BerEncoding.EncodeBoolean(_output, value); }
EmberSequence ConvertTupleDescription(BerTag tag, XElement xml) { var ember = new EmberSequence(tag); foreach (var itemsXml in xml.Elements("TupleItemDescription")) { var glowItem = new GlowTupleItemDescription(0, GlowTags.CollectionItem); var typeXml = itemsXml.Element("type"); if (typeXml != null) { var type = ConvertParameterType(typeXml.Value); if (type != null) { glowItem.Type = type.Value; } } itemsXml.Element("name").Do(value => glowItem.Name = value); ember.Insert(glowItem); } return(ember); }
/// <summary> /// Initializes a new instance of the <see cref="DataElement"/> struct. /// </summary> /// <param name="class">The class.</param> /// <param name="pc">The PC.</param> /// <param name="tag">The tag.</param> /// <param name="content">The content.</param> public DataElement(BerClass @class, BerPC pc, BerTag tag, byte[] content) : this() { this.Class = @class; this.PC = pc; this.Tag = tag; this.Content = content; }
public static GlowValue GetValue(EmberContainer container, BerTag tag) { var node = container[tag]; return(node != null ? GetValue(node) : null); }
/// <summary> /// Creates a container of an application-defined type with Set semantics /// </summary> /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param> public static EmberSet CreateApplicationDefinedSet(BerTag tag, uint type, EmberContainer parent) { var set = new EmberSet(tag, parent) { BerTypeNumber = type | BerType.ApplicationFlag }; return set; }
/// <summary> /// Creates an EmberSequence object with the passed BerType. Convenience method /// to be called from an overridden CreateNodeFromXml method. /// </summary> protected EmberNode CreateSequence(uint type, BerTag tag, XmlReader reader) { var node = new EmberSequence(tag, null) { BerTypeNumber = type }; return(node); }
/// <summary> /// Creates a new instance of EmberSequence with the IsOrdered flag /// set to true. /// </summary> /// <param name="tag">The tag of the new EmberSequence.</param> /// <returns>A new instance of EmberSequence with the IsOrdered flag /// set to true.</returns> public static EmberSequence CreateOrderedSequence(BerTag tag) { var sequence = new EmberSequence(tag) { IsOrdered = true, }; return(sequence); }
public void Write(BerTag tag, long value) { var valueLength = BerEncoding.GetLongLength(value); WriteOuterHeader(tag, valueLength + 2); BerEncoding.EncodeTag(_output, new BerTag(BerType.Integer)); BerEncoding.EncodeLength(_output, valueLength); BerEncoding.EncodeLong(_output, value, (int)valueLength); }
public override EmberNode CreateNodeFromXml(uint type, BerTag tag, XmlReader reader) { switch (type) { case GlowType.Parameter: return(new GlowParameter(tag)); case GlowType.Command: return(new GlowCommand(tag)); case GlowType.Node: return(new GlowNode(tag)); case GlowType.ElementCollection: return(new GlowElementCollection(tag)); case GlowType.StreamEntry: return(new GlowStreamEntry(tag)); case GlowType.StreamCollection: return(new GlowStreamCollection(tag)); case GlowType.StringIntegerPair: return(new GlowStringIntegerPair(tag)); case GlowType.StringIntegerCollection: return(new GlowStringIntegerCollection(tag)); case GlowType.QualifiedNode: return(new GlowQualifiedNode(tag)); case GlowType.QualifiedParameter: return(new GlowQualifiedParameter(tag)); case GlowType.RootElementCollection: return(new GlowRootElementCollection(tag)); case GlowType.StreamDescription: return(new GlowStreamDescription(tag)); case GlowType.Matrix: return(new GlowMatrix(tag)); case GlowType.Target: return(new GlowTarget(tag)); case GlowType.Source: return(new GlowSource(tag)); case GlowType.Connection: return(new GlowConnection(tag)); case GlowType.QualifiedMatrix: return(new GlowQualifiedMatrix(tag)); case GlowType.Label: return(new GlowLabel(tag)); case GlowType.Function: return(new GlowFunction(tag)); case GlowType.QualifiedFunction: return(new GlowQualifiedFunction(tag)); case GlowType.TupleItemDescription: return(new GlowTupleItemDescription(tag)); case GlowType.Invocation: return(new GlowInvocation(tag)); case GlowType.InvocationResult: return(new GlowInvocationResult(tag)); case GlowType.Template: return(new GlowTemplate(tag)); case GlowType.QualifiedTemplate: return(new GlowQualifiedTemplate(tag)); } return(base.CreateNodeFromXml(type, tag, reader)); }
/// <summary> /// Creates a new instance containing the passed <paramref name="value"/> /// </summary> /// <param name="tag">The tag of the newly created node.</param> /// <param name="value">The primitive value to hold.</param> public ObjectIdentifierEmberLeaf(BerTag tag, int[] value) : base(tag) { Value = (value != null && value.Length > 1) ? value : new int[] { 0, 0 }; BerTypeNumber = BerType.ObjectIdentifier; }
/// <summary> /// Creates a container of an application-defined type with Set semantics /// </summary> /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param> public static EmberSet CreateApplicationDefinedSet(BerTag tag, uint type, EmberContainer parent) { var set = new EmberSet(tag, parent) { BerTypeNumber = type | BerType.ApplicationFlag }; return(set); }
public void Write(BerTag tag, double value) { var valueOutput = new BerMemoryOutput(); var valueLength = BerEncoding.EncodeReal(valueOutput, value); WriteOuterHeader(tag, valueLength + 2); BerEncoding.EncodeTag(_output, new BerTag(BerType.Real)); BerEncoding.EncodeLength(_output, valueLength); _output.WriteBytes(valueOutput.Memory); }
public void WriteRelativeOid(BerTag tag, int[] value) { var innerTag = new BerTag(BerType.RelativeOid); var valueLength = BerEncoding.GetRelativeOidLength(value); WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength)); BerEncoding.EncodeTag(_output, innerTag); BerEncoding.EncodeLength(_output, valueLength); BerEncoding.EncodeRelativeOid(_output, value); }
public void Write(BerTag tag, byte[] value) { var valueLength = value.Length; var innerTag = new BerTag(BerType.OctetString); WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength)); BerEncoding.EncodeTag(_output, innerTag); BerEncoding.EncodeLength(_output, valueLength); _output.WriteBytes(value); }
/// <summary> /// Creates a new instance of EmberContainer. /// </summary> /// <param name="tag">The tag of the new node.</param> /// <param name="parent">The parent to insert the new node into.</param> /// <param name="type">The BerType of the new node.</param> public EmberContainer(BerTag tag, EmberContainer parent, uint type) : base(tag) { BerTypeNumber = type; if (parent != null) { parent.InsertChildNode(this); } }
/// <summary> /// Creates a container of an application-defined type with Sequence semantics /// </summary> /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param> public static EmberSequence CreateApplicationDefinedSequence(BerTag tag, uint type, EmberContainer parent, bool isOrdered = false) { var sequence = new EmberSequence(tag, parent) { BerTypeNumber = type | BerType.ApplicationFlag, IsOrdered = isOrdered, }; return(sequence); }
/// <summary> /// Creates a container of an application-defined type with Sequence semantics /// </summary> /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param> public static EmberSequence CreateApplicationDefinedSequence(BerTag tag, uint type, EmberContainer parent, bool isOrdered = false) { var sequence = new EmberSequence(tag, parent) { BerTypeNumber = type | BerType.ApplicationFlag, IsOrdered = isOrdered, }; return sequence; }
/// <summary> /// Gets the value of the child leaf with the specified tag. /// Throws an exception if this EmberNode is not derived from EmberContainer or /// if no child node of type EmberLeaf<TValue> with the specified tag exists. /// It is strongly recommended to use type specific methods such as GetInteger(), /// GetDateTime() etc. Only use this method if there is no specialized /// method for the type you want to get. /// </summary> /// <typeparam name="TValue">The type of the leaf value to get.</typeparam> /// <param name="tag">The tag of the leaf whose value to return.</param> /// <returns>The value of the child node with the specified tag.</returns> public static TValue Get <TValue>(this EmberNode node, BerTag tag) { var leaf = node[tag] as EmberLeaf <TValue>; if (leaf != null) { return(leaf.Value); } throw new BerException(5, "Leaf not found or type mismatch"); }
public static void InsertValue(EmberContainer container, BerTag tag, GlowValue value) { var leaf = ValueToLeaf(tag, value); if (leaf == null) { throw new ArgumentException("Type not supported"); } container.Insert(leaf); }
/// <summary> /// Creates a new instance containing the passed <paramref name="value"/> /// </summary> /// <param name="tag">The tag of the newly created node.</param> /// <param name="value">The primitive value to hold.</param> public OctetStringEmberLeaf(BerTag tag, byte[] value) : base(tag) { if (value == null) { throw new ArgumentNullException("value"); } Value = value; BerTypeNumber = BerType.OctetString; }
protected EmberSet EnsureContentsAndRemove(BerTag tag) { var contents = EnsureContents(); if (contents != null) { contents.Remove(tag); } return(contents); }
/// <summary> /// Gets the RELATIVE OBJECT value of the child leaf with the specified tag. /// Throws an exception if this EmberNode is not derived from EmberContainer or /// if no child node of type EmberLeaf<int[]> with the specified tag exists. /// </summary> /// <param name="tag">The tag of the leaf whose value to return.</param> /// <returns>The value of the child node with the specified tag.</returns> public static int[] GetRelativeOid(this EmberNode node, BerTag tag) { int[] value; if (GetRelativeOid(node, tag, out value)) { return(value); } throw new BerException(5, "leaf not found or leaf type mismatch"); }
GlowValue GetValue(BerTag tag) { var contents = EnsureContents(); if (contents != null) { return(InternalTools.GetValue(contents, tag)); } return(null); }
GlowMinMax GetMinMax(BerTag tag) { var contents = EnsureContents(); if (contents != null) { return(InternalTools.GetMinMax(contents, tag)); } return(null); }
public void Write(BerTag tag, string value) { var valueOutput = new BerMemoryOutput(); var valueLength = BerEncoding.EncodeUtf8String(valueOutput, value); var innerTag = new BerTag(BerType.UTF8String); WriteOuterHeader(tag, valueLength + BerEncoding.GetHeaderLength(innerTag, valueLength)); BerEncoding.EncodeTag(_output, innerTag); BerEncoding.EncodeLength(_output, valueLength); _output.WriteBytes(valueOutput.Memory); }
/// <summary> /// Removes the child node with the specified tag. /// </summary> /// <param name="tag">The tag of the child node to remove.</param> /// <returns>True if the child node was found and removed, otherwise false.</returns> public override sealed bool Remove(BerTag tag) { var result = base.Remove(tag); if (IsMapUsed) { _nodesMap.Remove(tag); } return(result); }
/// <summary> /// Gets the integer value of the child leaf with the specified tag. /// Throws an exception if this EmberNode is not derived from EmberContainer or /// if no child node of type EmberLeaf<int> or EmberLeaf<long> with the specified tag exists. /// </summary> /// <param name="tag">The tag of the leaf whose value to return.</param> /// <returns>The value of the child node with the specified tag.</returns> public static long GetInteger(this EmberNode node, BerTag tag) { long value; if (GetInteger(node, tag, out value)) { return(value); } throw new BerException(5, "Leaf not found or type mismatch"); }
public override EmberNode CreateNodeFromXml(uint type, BerTag tag, XmlReader reader) { switch(type & ~BerType.ApplicationFlag) { case 1: return CreateSet(type, tag, reader); case 2: return CreateSequence(type, tag, reader); } return null; }
/// <summary> /// Creates a new instance of GlowStringIntegerPair. /// </summary> protected internal GlowStringIntegerPair(BerTag tag) : base(tag, GlowType.StringIntegerPair) { }
/// <summary> /// Creates a new instance of GlowFunctionBase. /// </summary> protected GlowFunctionBase(BerTag? tag, uint type) : base(tag, type) { }
public static int GetHeaderLength(BerTag tag, int length) { int result = GetTagLength(tag); if(length <= 0x7F || length == BerDefinitions.IndefiniteLength) return result + 1; return result + 1 + GetIntegerLength(length); }
public static int GetTagLength(BerTag tag) { var number = tag.Number; if(number < 0x1F) return 1; return 1 + GetMultiByteLongLength(number); }
void InsertMinMax(BerTag tag, GlowMinMax value) { InternalTools.InsertMinMax(EnsureContentsAndRemove(tag), tag, value); }
EmberSequence ConvertTupleDescription(BerTag tag, XElement xml) { var ember = new EmberSequence(tag); foreach(var itemsXml in xml.Elements("TupleItemDescription")) { var glowItem = new GlowTupleItemDescription(0, GlowTags.CollectionItem); var typeXml = itemsXml.Element("type"); if(typeXml != null) { var type = ConvertParameterType(typeXml.Value); if(type != null) glowItem.Type = type.Value; } itemsXml.Element("name").Do(value => glowItem.Name = value); ember.Insert(glowItem); } return ember; }
/// <summary> /// Creates a new instance of GlowParameterBase. /// </summary> protected GlowParameterBase(BerTag? tag, uint type) : base(tag, type) { }
void InsertValue(BerTag tag, GlowValue value) { InternalTools.InsertValue(EnsureContentsAndRemove(tag), tag, value); }
/// <summary> /// Creates a new instance of GlowTarget. /// </summary> /// <param name="tag">Either a specific tag or null when the node /// is to be inserted into a matrix signal collection. The tag will be /// set to GlowTags.CollectionItem if the passed tag is null.</param> protected internal GlowTarget(BerTag? tag) : base(tag, GlowType.Target) { }
/// <summary> /// Creates a new instance of GlowTarget. /// </summary> /// <param name="number">Value of the "number" field.</param> /// <param name="tag">Either a specific tag or null when the node /// is to be inserted into a matrix signal collection. The tag will be /// set to GlowTags.CollectionItem if the passed tag is null.</param> public GlowTarget(int number, BerTag? tag = null) : base(number, tag, GlowType.Target) { }
/// <summary> /// Creates a new instance of GlowStreamEntry. /// <param name="tag">Tag of the new GlowStreamEntry or /// GlowTags.StreamCollection.StreamEntry if null.</param> /// </summary> public GlowStreamEntry(BerTag? tag = null) : base(tag ?? GlowTags.StreamCollection.StreamEntry, GlowType.StreamEntry) { }
GlowStreamDescription ConvertStreamDescription(BerTag tag, XElement xml) { return new GlowStreamDescription( tag, XmlConvert.ToInt32(xml.Element("format").Value), XmlConvert.ToInt32(xml.Element("offset").Value)); }
/// <summary> /// Initializes a new instance of the <see cref="GlowTemplateBase"/> class. /// </summary> /// <param name="tag"></param> /// <param name="type"></param> protected GlowTemplateBase(BerTag tag, uint type) : base(tag, type) { }
/// <summary> /// Creates an encodable instance of GlowEnumEntry with /// the specified name/value pair. /// </summary> /// <param name="tag">The field tag of the enum entry.</param> /// <param name="name">The name of the enum entry.</param> /// <param name="value">The value of the enum entry.</param> public GlowStringIntegerPair(BerTag tag, string name, int value) : this(tag) { EntryName = name; EntryInteger = value; }
public EmberDynamicContainer(BerTag tag, EmberContainer parent) : base(tag, parent, true) { }
/// <summary> /// Creates a new instance of GlowElementCollectionBase. /// </summary> protected GlowElementCollectionBase(BerTag tag, uint type) : base(tag, type, isOrdered: false) { }
// ==================================================================== // // Decode functions // // ==================================================================== public static BerTag DecodeTag(IBerInput input) { var tagByte = input.ReadByte(); var tag = new BerTag((byte)(tagByte & 0xE0), (uint)(tagByte & 0x1F)); if(tag.Number == 0x1F) tag.Number = DecodeMultiByteInteger(input); return tag; }
/// <summary> /// Creates a new instance of GlowMatrix. /// </summary> /// <param name="tag">Either a specific tag or null when the node /// is to be inserted into a GlowElementCollection. The tag will be /// set to GlowTags.CollectionItem if the passed tag is null.</param> /// <param name="type">ber type of the represented glow type</param> protected GlowMatrixBase(BerTag? tag, uint type) : base(tag, type) { }
// ==================================================================== // // Encode functions // all return the number of bytes in the // encoded result. // // ==================================================================== public static int EncodeTag(IBerOutput output, BerTag tag) { var number = tag.Number; var size = 1; tag.Preamble &= 0xE0; if(number < 0x1F) { output.WriteByte((byte)(tag.Preamble | (number & 0x1F))); } else { output.WriteByte((byte)(tag.Preamble | 0x1F)); size += EncodeMultiByteInteger(output, number); } return size; }
/// <summary> /// Creates a new instance of GlowSource. /// </summary> /// <param name="number">Value of the "number" field.</param> /// <param name="tag">Either a specific tag or null when the node /// is to be inserted into a matrix signal collection. The tag will be /// set to GlowTags.CollectionItem if the passed tag is null.</param> public GlowSource(int number, BerTag? tag = null) : base(number, tag, GlowType.Source) { }
GlowStringIntegerCollection ConvertStringIntegerCollection(BerTag tag, XElement xml) { var glow = new GlowStringIntegerCollection(tag); var glowEntries = from xmlChild in xml.Elements("StringIntegerPair") let name = xmlChild.Attribute("entryString").Value let value = XmlConvert.ToInt32(xmlChild.Attribute("entryInteger").Value) select new GlowStringIntegerPair(GlowTags.StringIntegerCollection.StringIntegerPair, name, value); foreach(var glowEntry in glowEntries) glow.Insert(glowEntry); return glow; }
/// <summary> /// Creates a new instance of GlowStringIntegerCollection. /// </summary> public GlowStringIntegerCollection(BerTag tag) : base(tag, GlowType.StringIntegerCollection, isOrdered: false) { }
/// <summary> /// Creates a new instance of GlowSource. /// </summary> /// <param name="tag">Either a specific tag or null when the node /// is to be inserted into a matrix signal collection. The tag will be /// set to GlowTags.CollectionItem if the passed tag is null.</param> protected internal GlowSource(BerTag? tag) : base(tag, GlowType.Source) { }