/// <summary>
        /// Serializes a static <see cref="StreamOutputElement"/>.
        /// </summary>
        /// <param name="value">The <see cref="StreamOutputElement"/> to serialize</param>
        /// <param name="serializeFlags">Type of serialization, see <see cref="SerializeFlags"/>.</param>
        /// <remarks>
        /// Note that depending on the serialization <see cref="Mode"/>, this method reads or writes the value.
        /// </remarks>
        public void Serialize(ref StreamOutputElement value, SerializeFlags serializeFlags = SerializeFlags.Normal)
        {
            int storeObjectRef;

            if (SerializeIsNull(ref value, out storeObjectRef, serializeFlags))
            {
                return;
            }

            if (Mode == SerializerMode.Read)
            {
                value = new StreamOutputElement();
            }

            // Store ObjectRef
            if (storeObjectRef >= 0)
            {
                StoreObjectRef(value, storeObjectRef);
            }

            Serialize(ref value.Stream);
            Serialize(ref value.SemanticName);
            Serialize(ref value.SemanticIndex);
            Serialize(ref value.StartComponent);
            Serialize(ref value.ComponentCount);
            Serialize(ref value.OutputSlot);
        }
 // Creates the serializer memory stream if it hasn't been already,
 // and initializes the serialization flags
 private void InitSerializer(SerializeFlags flags)
 {
     _AltSerializer.Stream = _MemStream;
     _AltSerializer.SerializePropertyNames = ((flags & SerializeFlags.SerializePropertyNames) != 0);
     _AltSerializer.CacheEnabled           = ((flags & SerializeFlags.SerializationCache) != 0);
     _AltSerializer.SerializeProperties    = ((flags & SerializeFlags.SerializeProperties) != 0);
 }
        /// <summary>
        /// Serializes an array of static <see cref="StreamOutputElement"/>s.
        /// </summary>
        /// <param name="valueArray">An array of <see cref="StreamOutputElement"/>s to serialize</param>
        /// <param name="serializeFlags">Type of serialization, see <see cref="SerializeFlags"/>.</param>
        /// <remarks>
        /// Note that depending on the serialization <see cref="Mode"/>, this method reads or writes the value.
        /// </remarks>
        public void Serialize(ref StreamOutputElement[] valueArray, SerializeFlags serializeFlags = SerializeFlags.Normal)
        {
            int storeObjectRef;
            if (SerializeIsNull(ref valueArray, out storeObjectRef, serializeFlags))
                return;

            if (Mode == SerializerMode.Write)
            {
                // Store ObjectRef
                if (storeObjectRef >= 0) StoreObjectRef(valueArray, storeObjectRef);

                WriteArrayLength(valueArray.Length);
                for (int i = 0; i < valueArray.Length; i++)
                    Serialize(ref valueArray[i], serializeFlags);
            }
            else
            {
                var count = ReadArrayLength();
                valueArray = new StreamOutputElement[count];

                // Store ObjectRef
                if (storeObjectRef >= 0) StoreObjectRef(valueArray, storeObjectRef);

                for (int index = 0; index < count; index++)
                    Serialize(ref valueArray[index], serializeFlags);
            }
        }
Beispiel #4
0
 public void PrintTo(object val, string entryName, string file, SerializeFlags DataFlags = SerializeFlags.None)
 {
     currentFlags = DataFlags;
     using (writter = new Writter(file))
     {
         Print(val, entryName);
     }
 }
Beispiel #5
0
 public string PrintToString(object val, string entryName, SerializeFlags DataFlags = SerializeFlags.None)
 {
     currentFlags = DataFlags;
     using (writter = new Writter())
     {
         Print(val, entryName);
         return(writter.GetString());
     }
 }
        /// <summary>
        /// Deserializes an object and returns the result.
        /// </summary>
        /// <param name="bytes">Array of bytes containing the serialized object.</param>
        /// <param name="objectType">The object type contained in the serialized byte array.</param>
        /// /// <param name="flags">Flags to control the deserialization.</param>
        /// <returns>Returns the deserialized object.</returns>
        public object Deserialize(byte[] bytes, Type objectType, SerializeFlags flags)
        {
            object returnValue;

            lock (_AltSerializer)
            {
                InitSerializer(flags);
                MemoryStream objectStream = new MemoryStream(bytes);
                _AltSerializer.Reset();
                _AltSerializer.Stream = objectStream;
                returnValue           = _AltSerializer.Deserialize(objectType);
                _AltSerializer.Stream = _MemStream;
                objectStream.Dispose();
            }
            return(returnValue);
        }
Beispiel #7
0
        /// <summary>
        ///     Serializes buffer into a textual representation of its glyph content, useful for showing the contents
        ///     of the buffer, for example during debugging. There are currently two supported serialization formats.
        /// </summary>
        /// <param name="start">the first item in buffer to serialize.</param>
        /// <param name="end">
        ///     thought the official manual says it's "the last item in buffer to serialize", it looks more like
        ///     "actual running length of items to serialize" to me.
        /// </param>
        /// <param name="bufferSize">the size of unmanaged buffer for receiving the serialized string.</param>
        /// <param name="format">the <see cref="SerializeFormat" /> to use for formatting the output.</param>
        /// <param name="flags">the <see cref="SerializeFlags" /> that control what glyph properties to serialize.</param>
        /// <param name="font">
        ///     the <see cref="Font" /> used to shape this buffer, needed to read glyph names and extents. If NULL,
        ///     and empty font will be used.
        /// </param>
        public string Serialize(uint start, uint end, uint bufferSize, Tag format,
                                SerializeFlags flags = SerializeFlags.Default, Font.Font font = null)
        {
            var buffer = Marshal.AllocHGlobal((int)bufferSize);

            try
            {
                Api.hb_buffer_serialize_glyphs(Handle, start, end, buffer, bufferSize, out var consumed,
                                               font?.Handle ?? IntPtr.Zero, format, flags);
                return(Marshal.PtrToStringAnsi(buffer, (int)consumed));
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
        /// <summary>
        /// Serializes a static <see cref="StreamOutputElement"/>.
        /// </summary>
        /// <param name="value">The <see cref="StreamOutputElement"/> to serialize</param>
        /// <param name="serializeFlags">Type of serialization, see <see cref="SerializeFlags"/>.</param>
        /// <remarks>
        /// Note that depending on the serialization <see cref="Mode"/>, this method reads or writes the value.
        /// </remarks>
        public void Serialize(ref StreamOutputElement value, SerializeFlags serializeFlags = SerializeFlags.Normal)
        {
            int storeObjectRef;
            if (SerializeIsNull(ref value, out storeObjectRef, serializeFlags))
                return;

            if (Mode == SerializerMode.Read)
                value = new StreamOutputElement();

            // Store ObjectRef
            if (storeObjectRef >= 0) StoreObjectRef(value, storeObjectRef);

            Serialize(ref value.Stream);
            Serialize(ref value.SemanticName);
            Serialize(ref value.SemanticIndex);
            Serialize(ref value.StartComponent);
            Serialize(ref value.ComponentCount);
            Serialize(ref value.OutputSlot);
        }
        /// <summary>
        /// Serializes an array of static <see cref="StreamOutputElement"/>s.
        /// </summary>
        /// <param name="valueArray">An array of <see cref="StreamOutputElement"/>s to serialize</param>
        /// <param name="serializeFlags">Type of serialization, see <see cref="SerializeFlags"/>.</param>
        /// <remarks>
        /// Note that depending on the serialization <see cref="Mode"/>, this method reads or writes the value.
        /// </remarks>
        public void Serialize(ref StreamOutputElement[] valueArray, SerializeFlags serializeFlags = SerializeFlags.Normal)
        {
            int storeObjectRef;

            if (SerializeIsNull(ref valueArray, out storeObjectRef, serializeFlags))
            {
                return;
            }

            if (Mode == SerializerMode.Write)
            {
                // Store ObjectRef
                if (storeObjectRef >= 0)
                {
                    StoreObjectRef(valueArray, storeObjectRef);
                }

                WriteArrayLength(valueArray.Length);
                for (int i = 0; i < valueArray.Length; i++)
                {
                    Serialize(ref valueArray[i], serializeFlags);
                }
            }
            else
            {
                var count = ReadArrayLength();
                valueArray = new StreamOutputElement[count];

                // Store ObjectRef
                if (storeObjectRef >= 0)
                {
                    StoreObjectRef(valueArray, storeObjectRef);
                }

                for (int index = 0; index < count; index++)
                {
                    Serialize(ref valueArray[index], serializeFlags);
                }
            }
        }
Beispiel #10
0
 public static extern uint hb_buffer_serialize_glyphs(IntPtr buffer, uint start, uint end, IntPtr buf,
                                                      uint buf_size, out uint buf_consumed, IntPtr font, Tag format, SerializeFlags flags);
Beispiel #11
0
 public void PrintTo(object val, string entryName, Stream stream, SerializeFlags DataFlags = SerializeFlags.None)
 {
     writter      = new Writter(stream);
     currentFlags = DataFlags;
     Print(val, entryName);
 }
Beispiel #12
0
 bool HasFlag(SerializeFlags flag)
 {
     return((currentFlags & flag) == flag);
 }
 public ExtendAttribute(SerializeFlags flags)
 {
     Flags = flags;
 }