Inheritance: IValueSink
コード例 #1
0
ファイル: Tags.cs プロジェクト: fanzcsoft/bacstack
        /// <summary>
        /// Encodes a value into a byte array
        /// </summary>
        /// <typeparam name="T">The type of value to encode</typeparam>
        /// <param name="value">The value to encode</param>
        /// <returns>The byte array</returns>
        public static byte[] EncodeBytes <T>(T value)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                TagWriter     writer = new TagWriter(ms);
                TagWriterSink sink   = new TagWriterSink(writer, Value <T> .Schema);
                Value <T> .Save(sink, value);

                return(ms.ToArray());
            }
        }
コード例 #2
0
ファイル: Tags.cs プロジェクト: fanzcsoft/bacstack
        /// <summary>
        /// Encodes a value into a byte array
        /// </summary>
        /// <typeparam name="T">The type of value to encode</typeparam>
        /// <param name="buffer">The buffer to encode into</param>
        /// <param name="offset">The offset to begin encoding</param>
        /// <param name="value">The value to encode</param>
        /// <returns>The next offset</returns>
        public static int Encode <T>(byte[] buffer, int offset, T value)
        {
            using (var ms = new MemoryStream(buffer, offset, buffer.Length, true))
            {
                TagWriter     writer = new TagWriter(ms);
                TagWriterSink sink   = new TagWriterSink(writer, Value <T> .Schema);
                Value <T> .Save(sink, value);

                offset = (int)ms.Position;
            }
            return(offset);
        }
コード例 #3
0
ファイル: Tags.cs プロジェクト: fanzcsoft/bacstack
        /// <summary>
        /// Encodes a value to a generic object
        /// </summary>
        /// <typeparam name="T">The type of the value</typeparam>
        /// <param name="value">The value to encode</param>
        /// <returns>The generic object</returns>
        public static GenericValue Encode <T>(T value)
        {
            byte[] tag;

            using (var ms = new MemoryStream())
            {
                TagWriter     writer = new TagWriter(ms);
                TagWriterSink sink   = new TagWriterSink(writer, Value <T> .Schema);
                Value <T> .Save(sink, value);

                tag = ms.ToArray();
            }

            return(new TaggedGenericValue(tag, 0, tag.Length));
        }