示例#1
0
        private static Metric ConvertToParsedMetric(GOPGMET.Metric metric, GENESTRT strt)
        {
            if (metric is GOPGMET.StringMetric str)
            {
                StringMetric parsed = new StringMetric();
                parsed.Name = strt.Strings[str.NameIndex];
                foreach (ushort index in str.ValueIndices)
                {
                    parsed.Values.Add(strt.Strings[index]);
                }

                return(parsed);
            }
            else if (metric is GOPGMET.ReferenceMetric reference)
            {
                ReferenceMetric parsed = new ReferenceMetric();
                parsed.Name = strt.Strings[reference.NameIndex];
                foreach (GOPGMET.Metric referenced in reference.ReferencedMetrics)
                {
                    parsed.ReferencedMetrics.Add(ConvertToParsedMetric(referenced, strt));
                }

                return(parsed);
            }
            else
            {
                throw new Exception("Unknown raw metric type \"" + metric.GetType() + "\".");
            }
        }
示例#2
0
        private static Metric ReadMetric(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            ushort nameIndex = reader.ReadUInt16();
            ushort length    = reader.ReadUInt16();

            ushort knownType = 0;
            Metric metric    = null;

            for (ushort i = 0; i < length; i++)
            {
                ushort type  = reader.ReadUInt16();
                ushort value = reader.ReadUInt16();

                if (metric == null)
                {
                    knownType = type;
                    switch (type)
                    {
                    case 0:
                        metric = new StringMetric();
                        break;

                    case 1:
                        metric = new ReferenceMetric();
                        break;

                    default:
                        throw new Exception("Unknown metric type " + type + ".");
                    }

                    metric.NameIndex = nameIndex;
                }
                else if (knownType != type)
                {
                    throw new Exception("Encountered metric with mixed data types.");
                }

                switch (type)
                {
                case 0:
                    ((StringMetric)metric).ValueIndices.Add(value);
                    break;

                case 1:
                    long pos = stream.Position;
                    stream.Seek(value, SeekOrigin.Begin);

                    Metric m = ReadMetric(stream);
                    ((ReferenceMetric)metric).ReferencedMetrics.Add(m);

                    stream.Seek(pos, SeekOrigin.Begin);
                    break;

                default:
                    throw new Exception("Unknown datum type \"" + type + "\".");
                }
            }

            return(metric);
        }