private object ReadField(BinaryReader reader, MessageField field) { object o = null; switch (field.type) { case FieldType.Float: o = reader.ReadSingle(); break; case FieldType.Double: o = reader.ReadDouble(); break; case FieldType.Int8: o = reader.ReadSByte(); break; case FieldType.Bool: o = (reader.ReadByte() == 0) ? false : true; break; case FieldType.UInt8: o = reader.ReadByte(); break; case FieldType.Int16: o = reader.ReadInt16(); break; case FieldType.UInt16: o = reader.ReadUInt16(); break; case FieldType.Int32: o = reader.ReadInt32(); break; case FieldType.UInt32: o = reader.ReadUInt32(); break; case FieldType.Int64: o = reader.ReadInt64(); break; case FieldType.UInt64: o = reader.ReadUInt64(); break; case FieldType.Char: o = (char)reader.ReadByte(); break; case FieldType.Struct: { MessageFormat f = field.structType; if (f == null) { throw new Exception(string.Format("Unexpected FieldType.Struct in field {0}", field.name)); } MessageData s = new MessageData(this.msgId, null, this.subscription); s.format = f; s.ReadValues(reader); o = s; } break; } return(o); }
internal MessageData GetNestedData(string fieldName) { if (values == null) { ParseValues(); } foreach (var field in format.fields) { if (field.name == fieldName) { object value = values[fieldName]; if (field.arraySize > 0) { if (nestedFormats == null) { nestedFormats = new Dictionary <string, MessageFormat>(); } MessageFormat format = null; if (!nestedFormats.TryGetValue(fieldName, out format)) { List <MessageField> fields = new List <MessageField>(); object tv; // we need to copy the timestamp down so the data renders with time sync. if (this.values.TryGetValue("timestamp", out tv)) { fields.Add(new MessageField("double timestamp")); } for (int i = 0; i < field.arraySize; i++) { var name = i.ToString(); fields.Add(new MessageField(MessageField.GetFieldTypeName(field.type) + " " + name)); } format = new MessageFormat(fieldName, fields); nestedFormats[fieldName] = format; } MessageData array = new MessageData(this.msgId, null, this.subscription); array.format = format; var values = new Dictionary <string, object>(); object ts = null; int offset = 0; // we need to copy the timestamp down so the data renders with time sync. if (this.values.TryGetValue("timestamp", out ts)) { values["timestamp"] = ts; offset++; } Array data = (Array)value; for (int i = 0; i < field.arraySize; i++) { string name = format.fields[i + offset].name; values[name] = data.GetValue(i); } array.values = values; return(array); } else if (value is MessageData) { return((MessageData)value); } else { throw new Exception(string.Format("Field {0} is not a struct", fieldName)); } } } return(null); }