Example #1
0
 internal FIElement()
 {
     _defaultNamespace = null; // must be null as empty string has meaning
     _nsAttributesTop  = -1;
     _nsAttributes     = new FIAttribute[GROW_SIZE];
     _attributesTop    = -1;
     _attributes       = new FIAttribute[GROW_SIZE];
 }
Example #2
0
            internal void AddNamespaceAttribute(FIAttribute nsAttribute)
            {
                if (_nsAttributesTop == (_nsAttributes.Length - 1))
                {
                    FIAttribute[] destinationArray = new FIAttribute[_nsAttributes.Length + GROW_SIZE];
                    if (_nsAttributesTop > 0)
                    {
                        Array.Copy(_nsAttributes, destinationArray, _nsAttributesTop + 1);
                    }

                    _nsAttributes = destinationArray;
                }

                _nsAttributesTop++;
                _nsAttributes[_nsAttributesTop] = nsAttribute;
            }
Example #3
0
            internal void AddAttribute(FIAttribute attribute)
            {
                if (_attributesTop == (_attributes.Length - 1))
                {
                    FIAttribute[] destinationArray = new FIAttribute[_attributes.Length + GROW_SIZE];
                    if (_attributesTop > 0)
                    {
                        Array.Copy(_attributes, destinationArray, _attributesTop + 1);
                    }

                    _attributes = destinationArray;
                }

                _attributesTop++;
                _attributes[_attributesTop] = attribute;
            }
Example #4
0
        internal void WriteElement(FIElement element)
        {
            AlignmentOnBit1();

            // write element starting on bit 2 (bit 1 is padding)...

            byte byCurrent = 0;

            // bit 2 is set if has Attributes
            if (element.AttributeCount != 0)
            {
                byCurrent = 0x40;
            }

            string defaultNamespace = element.DefaultNamespace;

            if ((defaultNamespace != null) || (element.NamespaceAttributeCount != 0))
            {
                // we have namespace-attributes so append xx1110 and 00 padding
                _output.WriteByte((byte)(byCurrent | 0x38));
                byCurrent = 0;

                // for each NamespaceAttribute append 110011 identifier
                // append 1 if has prefix else 0
                // append 1 if has namespace-name else 0

                if (defaultNamespace != null)
                {
                    // no prefix, so append 11001101
                    _output.WriteByte((byte)0xCD);
                    IdentifyingStringOrIndexBit1(defaultNamespace, _vocabulary.NamespaceNamesMap);
                }

                // add Namespace Attributes
                for (int n = 0; n < element.NamespaceAttributeCount; n++)
                {
                    FIAttribute attr = element.NamespaceAttributes[n];

                    // must have prefix, so append 11001111
                    _output.WriteByte((byte)0xCF);
                    IdentifyingStringOrIndexBit1(attr.qnameIndex.Qname.LocalName, _vocabulary.PrefixNamesMap);
                    IdentifyingStringOrIndexBit1((string)(attr.data), _vocabulary.NamespaceNamesMap);
                }

                // add terminator after all namespace-attributes
                _output.WriteByte(FIConsts.FI_TERMINATOR);

                // 2 bits padding are required
            }

            // always on bit 3...

            // add Qualified Name
            QualifiedNameOrIndexBit3(byCurrent, element.QNameIndex, _vocabulary.ElementNamesMap);

            // add Attributes
            for (int n = 0; n < element.AttributeCount; n++)
            {
                FIAttribute attr = element.Attributes[n];

                QualifiedNameOrIndexBit2(0, attr.qnameIndex, _vocabulary.AttributeNamesMap);

                if (attr.data != null)
                {
                    if (attr.encoding != null)
                    {
                        // write attribute text as encoded characters
                        NonIdentifyingStringOrIndexBit1(attr.encoding, attr.data);
                    }
                    else if (attr.data is string)
                    {
                        // write attribute text as string
                        NonIdentifyingStringOrIndexBit1((string)attr.data, _vocabulary.AttributeValuesMap);
                    }
                    else
                    {
                        throw new LtFastInfosetException("Internal Error. Invalid data in WriteEndAttribute");
                    }
                }
            }

            // terminate attributes
            _terminateAttributes = (element.AttributeCount > 0);
        }