public void varWidthSizeChecks()
 {
     Assert.Equal(0, FudgeFieldPrefixCodec.GetFieldWidthByteCount(0x98));
     Assert.Equal(1, FudgeFieldPrefixCodec.GetFieldWidthByteCount(0x20));
     Assert.Equal(2, FudgeFieldPrefixCodec.GetFieldWidthByteCount(0x40));
     Assert.Equal(4, FudgeFieldPrefixCodec.GetFieldWidthByteCount(0x60));
 }
Example #2
0
        /**
         *
         */
        protected void ConsumeFieldData() //throws IOException
        {
            sbyte fieldPrefix = Reader.ReadSByte();
            int   typeId      = Reader.ReadByte();
            int   nRead       = 2;
            bool  fixedWidth  = FudgeFieldPrefixCodec.IsFixedWidth(fieldPrefix);
            bool  hasOrdinal  = FudgeFieldPrefixCodec.HasOrdinal(fieldPrefix);
            bool  hasName     = FudgeFieldPrefixCodec.HasName(fieldPrefix);

            int?ordinal = null;

            if (hasOrdinal)
            {
                ordinal = Reader.ReadInt16();
                nRead  += 2;
            }

            string name = null;

            if (hasName)
            {
                int nameSize = Reader.ReadByte();
                nRead++;
                name   = StringFieldType.ReadString(Reader, nameSize);
                nRead += nameSize;
            }
            else if (ordinal != null)
            {
                if (Taxonomy != null)
                {
                    name = Taxonomy.GetFieldName((short)ordinal.Value);
                }
            }

            FudgeFieldType type = FudgeContext.TypeDictionary.GetByTypeId(typeId);

            if (type == null)
            {
                if (fixedWidth)
                {
                    throw new FudgeRuntimeException("Unknown fixed width type " + typeId + " for field " + ordinal + ":" + name + " cannot be handled.");
                }
                type = FudgeContext.TypeDictionary.GetUnknownType(typeId);
            }

            int varSize = 0;

            if (!fixedWidth)
            {
                int varSizeBytes = FudgeFieldPrefixCodec.GetFieldWidthByteCount(fieldPrefix);
                switch (varSizeBytes)
                {
                case 0: varSize = 0; break;

                case 1: varSize = Reader.ReadByte(); nRead += 1; break;

                case 2: varSize = Reader.ReadInt16(); nRead += 2; break;

                case 4: varSize = Reader.ReadInt32(); nRead += 4; break;

                default:
                    throw new FudgeRuntimeException("Illegal number of bytes indicated for variable width encoding: " + varSizeBytes);
                }
            }

            FieldName    = name;
            FieldOrdinal = ordinal;
            FieldType    = type;
            MessageProcessingState currMsgProcessingState = processingStack.Peek();

            currMsgProcessingState.Consumed += nRead;
            if (typeId == FudgeTypeDictionary.FUDGE_MSG_TYPE_ID)
            {
                CurrentElement = FudgeStreamElement.SubmessageFieldStart;
                FieldValue     = null;
                MessageProcessingState subState = new MessageProcessingState();
                subState.MessageSize = varSize;
                subState.Consumed    = 0;
                processingStack.Push(subState);
            }
            else
            {
                CurrentElement = FudgeStreamElement.SimpleField;
                FieldValue     = ReadFieldValue(Reader, FieldType, varSize);
                if (fixedWidth)
                {
                    currMsgProcessingState.Consumed += type.FixedSize;
                }
                else
                {
                    currMsgProcessingState.Consumed += varSize;
                }
            }
        }