예제 #1
0
        // ICU4N specific - de-nested IValueMapper

        /// <summary>
        /// Serialize a <see cref="Trie2"/> Header and Index onto a <see cref="J2N.IO.DataOutputStream"/>.  This is
        /// common code used for both the <see cref="Trie2_16"/> and <see cref="Trie2_32"/> serialize functions.
        /// </summary>
        /// <param name="dos">The stream to which the serialized <see cref="Trie2"/> data will be written.</param>
        /// <returns>The number of bytes written.</returns>
        protected virtual int SerializeHeader(J2N.IO.DataOutputStream dos) // ICU4N TODO: API Can this be converted to BinaryWriter or Stream (as was Trie2_16)?
        {
            // Write the header.  It is already set and ready to use, having been
            //  created when the Trie2 was unserialized or when it was frozen.
            int bytesWritten = 0;

            dos.WriteInt32(header.signature);
            dos.WriteInt16(header.options);
            dos.WriteInt16(header.indexLength);
            dos.WriteInt16(header.shiftedDataLength);
            dos.WriteInt16(header.index2NullOffset);
            dos.WriteInt16(header.dataNullOffset);
            dos.WriteInt16(header.shiftedHighStart);
            bytesWritten += 16;

            // Write the index
            int i;

            for (i = 0; i < header.indexLength; i++)
            {
                dos.WriteChar(index[i]);
            }
            bytesWritten += header.indexLength;
            return(bytesWritten);
        }
예제 #2
0
 /// <summary>
 /// Writes an ICU data header.
 /// Does not write a copyright string.
 /// </summary>
 /// <param name="dataFormat"></param>
 /// <param name="formatVersion"></param>
 /// <param name="dataVersion"></param>
 /// <param name="dos"></param>
 /// <returns>The length of the header (number of bytes written).</returns>
 /// <exception cref="IOException">From the <see cref="J2N.IO.DataOutputStream"/>.</exception>
 public static int WriteHeader(int dataFormat, int formatVersion, int dataVersion,
                               J2N.IO.DataOutputStream dos)
 {
     // ucmndata.h MappedData
     dos.WriteChar(32);  // headerSize
     dos.WriteByte(MAGIC1);
     dos.WriteByte(MAGIC2);
     // unicode/udata.h UDataInfo
     dos.WriteChar(20);         // sizeof(UDataInfo)
     dos.WriteChar(0);          // reservedWord
     dos.WriteByte(1);          // isBigEndian
     dos.WriteByte(CHAR_SET_);  // charsetFamily
     dos.WriteByte(CHAR_SIZE_); // sizeofUChar
     dos.WriteByte(0);          // reservedByte
     dos.WriteInt32(dataFormat);
     dos.WriteInt32(formatVersion);
     dos.WriteInt32(dataVersion);
     // 8 bytes padding for 32 bytes headerSize (multiple of 16).
     dos.WriteInt64(0);
     Debug.Assert(dos.Length == 32);
     return(32);
 }
예제 #3
0
        /// <summary>
        /// Serialize a <see cref="Trie2_16"/> onto an <see cref="Stream"/>.
        /// </summary>
        /// <remarks>
        /// A <see cref="Trie2"/> can be serialized multiple times.
        /// The serialized data is compatible with ICU4C UTrie2 serialization.
        /// <see cref="Trie2"/> serialization is unrelated to .NET object serialization.
        /// </remarks>
        /// <param name="os">The stream to which the serialized Trie2 data will be written.</param>
        /// <returns>The number of bytes written.</returns>
        /// <exception cref="IOException">On an error writing to the <see cref="Stream"/>.</exception>
        public int Serialize(Stream os)
        {
            J2N.IO.DataOutputStream dos = new J2N.IO.DataOutputStream(os);
            int bytesWritten            = 0;

            bytesWritten += SerializeHeader(dos);
            for (int i = 0; i < dataLength; i++)
            {
                dos.WriteChar(index[data16 + i]);
            }
            bytesWritten += dataLength * 2;
            return(bytesWritten);
        }