Inheritance: IValueStream
Exemplo n.º 1
0
 /// <summary>
 /// Attempts to interpret a TaggedGenericType instance as
 /// a specific type
 /// </summary>
 /// <param name="value">The value to interpet</param>
 /// <param name="schema">The type to interpret as</param>
 /// <param name="output">The output type</param>
 /// <returns>True if the interpretation succeeds, false otherwise</returns>
 public IValueStream CreateStream(GenericValue value, ISchema schema)
 {
     var tagged = (TaggedGenericValue)value;
     MemoryStream ms = new MemoryStream(tagged.tag, tagged.offset, tagged.end - tagged.offset);
     TagReader reader = new TagReader(ms);
     TagReaderStream stream = new TagReaderStream(reader, schema);
     return stream;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to interpret a TaggedGenericType instance as
        /// a specific type
        /// </summary>
        /// <param name="value">The value to interpet</param>
        /// <param name="schema">The type to interpret as</param>
        /// <param name="output">The output type</param>
        /// <returns>True if the interpretation succeeds, false otherwise</returns>
        public IValueStream CreateStream(GenericValue value, ISchema schema)
        {
            var             tagged = (TaggedGenericValue)value;
            MemoryStream    ms     = new MemoryStream(tagged.tag, tagged.offset, tagged.end - tagged.offset);
            TagReader       reader = new TagReader(ms);
            TagReaderStream stream = new TagReaderStream(reader, schema);

            return(stream);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decodes a value from a byte array
        /// </summary>
        /// <typeparam name="T">The type of value to decode</typeparam>
        /// <param name="buffer">The buffer to decode from</param>
        /// <param name="offset">The offset to decode at</param>
        /// <param name="end">The last offset</param>
        /// <param name="value">The decoded value</param>
        /// <returns>The next offset</returns>
        public static int Decode <T>(byte[] buffer, int offset, int end, out T value)
        {
            using (var ms = new MemoryStream(buffer, offset, end - offset, false))
            {
                TagReader       reader = new TagReader(ms);
                TagReaderStream stream = new TagReaderStream(reader, Value <T> .Schema);
                value = Value <T> .Load(stream);

                offset = (int)ms.Position;
            }
            return(offset);
        }
Exemplo n.º 4
0
        public void ReadTest1()
        {
            var reader = fromHexString("00-19-01-29-40-3E-44-00-00-00-00-3F-4E-21-00-21-01-21-02-4F");
            var stream = new TagReaderStream(reader, Schema);
            var test = TestType.Load(stream);

            Assert.AreEqual(test.BooleanValue, true);
            Assert.IsTrue(test.OptionalValue.HasValue);
            Assert.AreEqual(test.OptionalValue.Value, 64);
            Assert.AreEqual(test.ChoiceValue.Choice, TestChoice.Float);
            Assert.AreEqual(((FloatChoice)test.ChoiceValue).Value, 0.00);
            Assert.AreEqual(test.ArrayValue.Length, 3);
            for(int i = 0; i < test.ArrayValue.Length; i++)
            {
                Assert.AreEqual(test.ArrayValue[i], (ushort)i);
            }
        }