コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public static List <float> Decompress(byte[] values)
        {
            var          memory = new MemorySpan(values);
            var          type   = memory.ReadByte();
            List <float> re     = new List <float>(300);
            var          dval   = (float)Math.Pow(10, type);

            if (type == byte.MaxValue)
            {
                while (memory.Position < memory.Length)
                {
                    re.Add(memory.ReadFloat());
                }
            }
            else
            {
                var val = memory.ReadFloat();
                re.Add(val);
                using (ProtoMemory vmemory = new ProtoMemory(values.AsSpan().Slice(9).ToArray()))
                {
                    while (vmemory.ReadPosition < vmemory.DataBuffer.Length)
                    {
                        val += (vmemory.ReadSInt32() / dval);
                        re.Add(val);
                    }
                }
            }
            return(re);
        }
コード例 #2
0
ファイル: ProtoMemoryTests.cs プロジェクト: cdy816/mars
        public void ProtoMemoryTest()
        {
            ProtoMemory memory = new ProtoMemory(100);

            memory.WriteInt32(10);
            memory.WriteInt32(1000);
            memory.WriteInt64(10);
            memory.WriteInt64(1000);
            memory.WriteDouble(1.0);

            Assert.IsTrue(memory.ReadInt32() == 10);
            Assert.IsTrue(memory.ReadInt32() == 1000);
            Assert.IsTrue(memory.ReadInt64() == 10);
            Assert.IsTrue(memory.ReadInt64() == 1000);
            Assert.IsTrue(Math.Round(memory.ReadDouble(), 2) == 1.0);
        }