Exemple #1
0
        /// <summary>
        /// Writes the given data encoded using the specified Encoding Algorithm.
        /// </summary>
        /// <param name="data">Data to encode.</param>
        /// <param name="encodingAlgorithmURI">Encoding Algorithm Unique Identifier</param>
        /// <exception cref="ArgumentNullException">encodingAlgorithmURI is null.</exception>
        /// <exception cref="InvalidOperationException">The <see cref="WriteState"/> is invalid for this operation.</exception>
        /// <exception cref="LtFastInfosetException">Cannot find EncodingAlgorithm for specified URI.</exception>
        public void WriteEncodedData(byte[] data, Uri encodingAlgorithmURI)
        {
            try
            {
                if ((data == null) || data.Length == 0)
                {
                    return;
                }

                if (encodingAlgorithmURI == null)
                {
                    throw new ArgumentNullException("encodingAlgorithmURI");
                }

                ValidateState(FIItemType.Content);

                FIEncoding algorithm = _internalWriter.Vocabulary.EncodingAlgorithm(encodingAlgorithmURI.ToString());
                if (algorithm == null)
                {
                    throw new LtFastInfosetException("Cannot find EncodingAlgorithm for specified URI.");
                }

                _internalWriter.WriteEncodedData(algorithm, data);

                UpdateState(FIItemType.Content);
            }
            catch (Exception ex)
            {
                _state = FIState.Error;
                throw ex;
            }
        }
Exemple #2
0
        internal void WriteEncodedData(FIEncoding encoding, object data)
        {
            // data assumed to be of correct type for chosen encoding

            if (data == null)
            {
                throw new LtFastInfosetException("Invalid Data");
            }

            if (_hasAttribute)
            {
                if (_isNamespaceAttribute)
                {
                    throw new LtFastInfosetException("Namespace Attribute value cannot be encoded");
                }

                // save attribute value until we know if its a namespace (see WriteEndAttribute)
                _attribute.encoding = encoding;
                _attribute.data     = data;
            }
            else
            {
                FlushElement();
                _encoder.WriteCharacterChunk(encoding, data);
            }
        }
Exemple #3
0
        private void EncodedCharacterStringBit5(byte byCurrent, FIEncoding encoding, object data)
        {
            int tableIndex = encoding.TableIndex;

            if (tableIndex < FIConsts.ENCODING_TABLE_MIN || tableIndex > FIConsts.ENCODING_TABLE_MAX)
            {
                throw new LtFastInfosetException("Invalid Encoded Character table index [" + tableIndex + "]");
            }

            byte byVal = (byte)(tableIndex - 1);

            byte[] buffer = encoding.Encode(data);

            if (encoding is FIRestrictedAlphabet)
            {
                // restricted-alphabet, so xxxx10xx
                _output.WriteByte((byte)(byCurrent | 0x08 | byVal >> 6));
            }
            else if ((encoding is FIEncodingAlgorithm) || (encoding is InternalEncodingAlgorithm))
            {
                // encoding-algorithm, so xxxx11xx
                _output.WriteByte((byte)(byCurrent | 0x0C | byVal >> 6));
            }
            else
            {
                throw new LtFastInfosetException("Internal Error in EncodedCharacterStringBit3. Unknown encoding type.");
            }

            NonEmptyOctetStringBit7((byte)(byVal << 2), buffer, buffer.Length);
        }
Exemple #4
0
        internal void WriteCharacterChunk(FIEncoding encoding, object data)
        {
            AlignmentOnBit1();

            // append 10xxxxxx
            NonIdentifyingStringOrIndexBit3(0x80, encoding, data);
        }
        internal FIEncoding Encoding(int fiTableIndex)
        {
            FIEncoding encoding = null;

            if (fiTableIndex > 0)
            {
                if (fiTableIndex < EXTENDED_ENCODING_ALGORITHM_START)
                {
                    if (fiTableIndex <= ENCODING_ALGORITHM_COUNT)
                    {
                        if (_internalEncodingAlgorithm == null)
                        {
                            _internalEncodingAlgorithm = new InternalEncodingAlgorithm();
                        }

                        _internalEncodingAlgorithm.Encoding = (InternalEncodingAlgorithm.EncodingType)fiTableIndex;
                        encoding = _internalEncodingAlgorithm;
                    }
                }
                else if ((_uriToEncodingMap != null) && (fiTableIndex < EXTENDED_ENCODING_ALGORITHM_MAX))
                {
                    // index - 1 to move from FI table index to list index
                    int realIndex = fiTableIndex - 1;
                    if (realIndex < _uriToEncodingMap.Count)
                    {
                        Dictionary <string, FIEncodingAlgorithm> .Enumerator e = _uriToEncodingMap.GetEnumerator();
                        while (e.MoveNext())
                        {
                            if (e.Current.Value.TableIndex == fiTableIndex)
                            {
                                encoding = e.Current.Value;
                                break;
                            }
                        }
                    }
                }
            }

            return(encoding);
        }
Exemple #6
0
 private void NonIdentifyingStringOrIndexBit3(byte byCurrent, FIEncoding encoding, object data)
 {
     // literal-character-string, no add-to-table xx00xxxx
     EncodedCharacterStringBit5(byCurrent, encoding, data);
 }
Exemple #7
0
 private void NonIdentifyingStringOrIndexBit1(FIEncoding encoding, object data)
 {
     // literal-character-string, no add-to-table so add 00xxxxxx
     EncodedCharacterStringBit3(0, encoding, data);
 }