Exemplo n.º 1
0
        /// <summary>
        /// Calculates the encoded size of this field in bytes. This is the encoded size of the
        /// underlying value as defined by the corresponding <c>FudgeFieldType</c>, the 2 byte
        /// field prefix, plus the ordinal index and field name if specified. If a taxonomy is
        /// specified and defines the field name, only the corresponding ordinal index would be
        /// written so the field name is not counted.
        /// </summary>
        /// <param name="taxonomy">taxonomy used to resolve field names, or null</param>
        /// <returns>the encoded size of this field in bytes</returns>
        public override int ComputeSize(IFudgeTaxonomy taxonomy)
        {
            int size = 0;

            // Field prefix
            size += 2;
            bool hasOrdinal = ordinal != null;
            bool hasName    = name != null;

            if ((name != null) && (taxonomy != null))
            {
                if (taxonomy.GetFieldOrdinal(name) != null)
                {
                    hasOrdinal = true;
                    hasName    = false;
                }
            }
            if (hasOrdinal)
            {
                size += 2;
            }
            if (hasName)
            {
                // One for the size prefix
                size++;
                // Then for the UTF Encoding
                size += StringFieldType.Encoding.GetByteCount(name);
            }
            if (type.IsVariableSize)
            {
                int valueSize = type.GetVariableSize(value, taxonomy);
                if (valueSize <= 255)
                {
                    size += valueSize + 1;
                }
                else if (valueSize <= short.MaxValue)
                {
                    size += valueSize + 2;
                }
                else
                {
                    size += valueSize + 4;
                }
            }
            else
            {
                size += type.FixedSize;
            }
            return(size);
        }
Exemplo n.º 2
0
 private static void NormalizeNameAndOrdinal(ref string name, ref short?ordinal, IFudgeTaxonomy taxonomy)
 {
     if ((taxonomy != null) && (name != null))
     {
         short?ordinalFromTaxonomy = taxonomy.GetFieldOrdinal(name);
         if (ordinalFromTaxonomy != null)
         {
             if ((ordinal != null) && !object.Equals(ordinalFromTaxonomy, ordinal))
             {
                 // In this case, we've been provided an ordinal, but it doesn't match the
                 // one from the taxonomy. We have to assume the user meant what they were doing,
                 // and not do anything.
             }
             else
             {
                 ordinal = ordinalFromTaxonomy;
                 name    = null;
             }
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Calculates the encoded size of this field in bytes. This is the encoded size of the
 /// underlying value as defined by the corresponding <c>FudgeFieldType</c>, the 2 byte
 /// field prefix, plus the ordinal index and field name if specified. If a taxonomy is
 /// specified and defines the field name, only the corresponding ordinal index would be
 /// written so the field name is not counted.
 /// </summary>
 /// <param name="taxonomy">taxonomy used to resolve field names, or null</param>
 /// <returns>the encoded size of this field in bytes</returns>
 public override int ComputeSize(IFudgeTaxonomy taxonomy)
 {
     int size = 0;
     // Field prefix
     size += 2;
     bool hasOrdinal = ordinal != null;
     bool hasName = name != null;
     if ((name != null) && (taxonomy != null))
     {
         if (taxonomy.GetFieldOrdinal(name) != null)
         {
             hasOrdinal = true;
             hasName = false;
         }
     }
     if (hasOrdinal)
     {
         size += 2;
     }
     if (hasName)
     {
         // One for the size prefix
         size++;
         // Then for the UTF Encoding
         size += StringFieldType.Encoding.GetByteCount(name);
     }
     if (type.IsVariableSize)
     {
         int valueSize = type.GetVariableSize(value, taxonomy);
         if (valueSize <= 255)
         {
             size += valueSize + 1;
         }
         else if (valueSize <= short.MaxValue)
         {
             size += valueSize + 2;
         }
         else
         {
             size += valueSize + 4;
         }
     }
     else
     {
         size += type.FixedSize;
     }
     return size;
 }
 private static void NormalizeNameAndOrdinal(ref string name, ref short? ordinal, IFudgeTaxonomy taxonomy)
 {
     if ((taxonomy != null) && (name != null))
     {
         short? ordinalFromTaxonomy = taxonomy.GetFieldOrdinal(name);
         if (ordinalFromTaxonomy != null)
         {
             if ((ordinal != null) && !object.Equals(ordinalFromTaxonomy, ordinal))
             {
                 // In this case, we've been provided an ordinal, but it doesn't match the
                 // one from the taxonomy. We have to assume the user meant what they were doing,
                 // and not do anything.
             }
             else
             {
                 ordinal = ordinalFromTaxonomy;
                 name = null;
             }
         }
     }
 }