使用 TeaFiles.NET "The specified Type must be a struct containing no references"



我发现了这个引人注目的库TeaFiles.NET。

我正在写一个非常简单的控制台应用程序来测试它。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting....");
            string filename = String.Format("History_{0}.{1}.{2}.tea",
                                               DateTime.Now.Year,
                                               DateTime.Now.Month,
                                               DateTime.Now.Day);
            File.Delete(filename);
            using (var tf = TeaFile<HistoryRow>.Create(filename))
            {
                var items = new List<HistoryRow>();
                for (int i = 0; i < 1000; i++)
                {
                    for (int k = 0; k < 100000; k++)
                    {
                        items.Add(new HistoryRow()
                        {
                            Flags = 192,
                            Name = "Name_" + i.ToString(CultureInfo.InvariantCulture),
                            Value = k,
                            Timestamp = DateTime.Now.AddTicks((long)i)
                        });
                    }
                }
                var sw = Stopwatch.StartNew();
                Console.WriteLine("Initiate write...");
                tf.Write(items);
                sw.Stop();
                Console.WriteLine("...completed write in {0} ms.", sw.ElapsedMilliseconds);
            }
            Console.ReadLine();
        }
    }
    struct HistoryRow
    {
        public string Name;
        public dynamic Value;
        public Time Timestamp; 
        public int Flags;
    }

这应该非常简单。相反,它会在Create()调用时出现以下错误:

"The specified Type must be a struct containing no references".

我真的不知道从哪里开始排除故障....

TeaFiles提供对时间序列数据的快速读/写访问。考虑到库需要包含@dtb所描述的blittable类型的struct,这应该可以工作:

[StructLayout(LayoutKind.Sequential, Pack=1)]
struct HistoryRow
{
    public char[16] Name;
    public double Value;
    public Time Timestamp; 
    public int Flags;
}

请注意,在存储时间数据序列时,通常不会存储带有值的描述,该值是列中已经有名称的许多值中的一个。

最新更新