예제 #1
0
 public FieldDefinition(Field field)
 {
     Num  = field.Num;
     Size = field.GetSize();
     Type = field.Type;
 }
예제 #2
0
        public void Write(Stream outStream, MesgDefinition mesgDef)
        {
            if (mesgDef == null)
            {
                mesgDef = new MesgDefinition(this);
            }

            EndianBinaryWriter bw = new EndianBinaryWriter(outStream, mesgDef.IsBigEndian);

            bw.Write(LocalNum);

            foreach (FieldDefinition fieldDef in mesgDef.GetFields())
            {
                Field field = GetField(fieldDef.Num);
                if (field == null)
                {
                    field = Profile.GetField(this.Num, fieldDef.Num);
                    fields.Add(field);
                }
                // The field could be blank, correctly formed or partially filled
                while (field.GetSize() < fieldDef.Size)
                {
                    field.AddValue(Fit.BaseType[fieldDef.Type & Fit.BaseTypeNumMask].invalidValue);
                }

                for (int i = 0; i < field.GetNumValues(); i++)
                {
                    object value = field.GetRawValue(i);
                    if (value == null)
                    {
                        value = Fit.BaseType[fieldDef.Type & Fit.BaseTypeNumMask].invalidValue;
                    }
                    switch (fieldDef.Type & Fit.BaseTypeNumMask)
                    {
                    case Fit.Enum:
                    case Fit.Byte:
                    case Fit.UInt8:
                    case Fit.UInt8z:
                        bw.Write((byte)value);
                        break;

                    case Fit.SInt8:
                        bw.Write((sbyte)value);
                        break;

                    case Fit.SInt16:
                        bw.Write((short)value);
                        break;

                    case Fit.UInt16:
                    case Fit.UInt16z:
                        bw.Write((ushort)value);
                        break;

                    case Fit.SInt32:
                        bw.Write((int)value);
                        break;

                    case Fit.UInt32:
                    case Fit.UInt32z:
                        bw.Write((uint)value);
                        break;

                    case Fit.Float32:
                        bw.Write((float)value);
                        break;

                    case Fit.Float64:
                        bw.Write((double)value);
                        break;

                    case Fit.String:
                        bw.Write((byte[])value);
                        // Write the null terminator
                        bw.Write((byte)0x00);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
 public FieldDefinition(Field field)
 {
     Num = field.Num;
      Size = field.GetSize();
      Type = field.Type;
 }