public void onMsg(MamdaSubscription subscription,
                          MamaMsg msg,
                          mamaMsgType msgType)
        {
            if (!MamdaOrderBookFields.isSet())
            {
                return;
            }

            try
            {
                switch (msgType)
                {
                case mamaMsgType.MAMA_MSG_TYPE_BOOK_CLEAR:
                    handleClear(subscription, msg);
                    break;

                case mamaMsgType.MAMA_MSG_TYPE_BOOK_INITIAL:
                case mamaMsgType.MAMA_MSG_TYPE_BOOK_RECAP:
                case mamaMsgType.MAMA_MSG_TYPE_BOOK_SNAPSHOT:
                    handleRecap(subscription, msg);
                    break;

                case mamaMsgType.MAMA_MSG_TYPE_BOOK_UPDATE:
                    handleUpdate(subscription, msg);
                    break;
                }
            }
            catch (MamaException)
            {
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="subscription"></param>
        /// <param name="msg"></param>
        /// <param name="msgType"></param>
        public void onMsg(
            MamdaSubscription subscription,
            MamaMsg msg,
            mamaMsgType msgType)
        {
            if (!MamdaOrderBookFields.isSet())
            {
                return;
            }

            // If msg is a order book related message, invoke the
            // appropriate callback:
            switch (msgType)
            {
            case mamaMsgType.MAMA_MSG_TYPE_BOOK_CLEAR:
                handleClear(subscription, msg);
                break;

            case mamaMsgType.MAMA_MSG_TYPE_BOOK_INITIAL:
            case mamaMsgType.MAMA_MSG_TYPE_BOOK_RECAP:
            case mamaMsgType.MAMA_MSG_TYPE_BOOK_SNAPSHOT:
                handleRecap(subscription, msg);
                break;

            case mamaMsgType.MAMA_MSG_TYPE_BOOK_UPDATE:
                handleUpdate(subscription, msg);
                break;
            }
        }
        private void  createDeltaFromMamaMsgWithoutVectorFields(
            MamdaSubscription subscription,
            MamaMsg msg,
            bool isRecap)
        {
            NullableInt numLevelFields_ = new NullableInt();

            int numLevelFieldInMsg = 1;

            if (msg.tryI32(MamdaOrderBookFields.NUM_LEVELS, ref numLevelFields_))
            {
                numLevelFieldInMsg = numLevelFields_.Value;
            }

            int maxLevelFields = MamdaOrderBookFields.getNumLevelFields();

            // getNumLevelFields() defaults to 0 but we want to go into the
            // below loop at least once for flattened messages scenario
            if (maxLevelFields == 0)
            {
                maxLevelFields = 1;
            }

            if (numLevelFieldInMsg < maxLevelFields)
            {
                maxLevelFields = numLevelFieldInMsg;
            }
            mPriceLevels = maxLevelFields;

            for (int i = 1; i <= maxLevelFields; i++)
            {
                clearLevelFields();
                mPriceLevel = i;
                MamaMsg plMsg = null;

                if (MamdaOrderBookFields.PRICE_LEVEL.Length > 1)
                {
                    plMsg = msg.getMsg(MamdaOrderBookFields.PRICE_LEVEL[i], null);
                }

                if (plMsg == null)
                {
                    if (numLevelFieldInMsg == 1)
                    {
                        // Price level fields are probably be in the main message.
                        plMsg = msg;
                    }
                    else
                    {
                        throw new MamdaDataException(
                                  "cannot find price level fields in MamaMsg");
                    }
                }
                getLevelInfoAndEntries(subscription, msg, plMsg, isRecap);
            }
        }
        private void createDeltaFromMamaMsg(MamdaSubscription subscription,
                                            MamaMsg msg,
                                            bool isRecap)
        {
            if (mBookHandler != null)
            {
                mBookHandler.onBookAtomicBeginBook(subscription, this, isRecap);
            }

            // Note: the following test checks whether vector fields are part
            // of the data dictionary.  However, the vector fields may indeed
            // be part of the data dictionary, but the message may still
            // contain the non-vector style order book data.
            if (MamdaOrderBookFields.getHasVectorFields())
            {
                /* null is passed as default value otherwise
                 * getVectorMsg throws an exception if not found */
                MamaMsg[] msgLevels =
                    msg.getVectorMsg(MamdaOrderBookFields.PRICE_LEVELS, null);

                if (msgLevels != null)
                {
                    createDeltaFromMamaMsgWithVectorFields(subscription,
                                                           msg,
                                                           msgLevels,
                                                           isRecap);
                }
                else
                {
                    createDeltaFromMamaMsgWithoutVectorFields(subscription, msg, isRecap);
                }
            }
            else
            {
                createDeltaFromMamaMsgWithoutVectorFields(subscription, msg, isRecap);
            }

            if (mBookHandler != null)
            {
                mBookHandler.onBookAtomicEndBook(subscription, this);
            }
        }
 /// <summary>
 /// createDeltaFromMamaMsg processes a MamaMsg containing a partial
 /// or full order book and returns whether processing is complete
 /// </summary>
 /// <param name="delta"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 private bool createDeltaFromMamaMsg(
     MamdaOrderBook delta,
     MamaMsg msg)
 {
     // Note: the following test checks whether vector fields are part
     // of the data dictionary.  However, the vector fields may indeed
     // be part of the data dictionary, but the message may still
     // contain the non-vector style order book data.
     if (MamdaOrderBookFields.getHasVectorFields())
     {
         /* null is passed as default value otherwise
          *      getVectorMsg throws an exception if not found*/
         MamaMsg[] msgLevels =
             msg.getVectorMsg(MamdaOrderBookFields.PRICE_LEVELS, null);
         if (msgLevels != null)
         {
             createDeltaFromMamaMsgWithVectorFields(delta, msgLevels);
             return(true);
         }
     }
     return(createDeltaFromMamaMsgWithoutVectorFields(delta, msg));
 }
        private void getLevelInfoAndEntries(
            MamdaSubscription subscription,
            MamaMsg msg,
            MamaMsg plMsg,
            bool isRecap)
        {
            double  priceLevelSizeChange = 0.0;
            int     priceLevelActionInt  = 0;
            int     priceLevelSideInt    = 0;
            MamaMsg entMsg = null;

            plMsg.tryPrice(MamdaOrderBookFields.PL_PRICE, ref mPriceLevelPrice);

            plMsg.tryF64(MamdaOrderBookFields.PL_SIZE, ref mPriceLevelSize);

            plMsg.tryF64(MamdaOrderBookFields.PL_NUM_ENTRIES, ref mPriceLevelNumEntries);

            if (plMsg.tryI32(MamdaOrderBookFields.PL_ACTION, ref priceLevelActionInt))
            {
                mPriceLevelAction = (sbyte)priceLevelActionInt;
            }

            if (plMsg.tryI32(MamdaOrderBookFields.PL_SIDE, ref priceLevelSideInt))
            {
                mPriceLevelSide = (sbyte)priceLevelSideInt;
            }

            // Optional order book fields:

            mPriceLevelTime = plMsg.getDateTime(MamdaOrderBookFields.PL_TIME, mEventTime);

            if (plMsg.tryF64(MamdaOrderBookFields.PL_SIZE_CHANGE, ref priceLevelSizeChange))
            {
                mPriceLevelSizeChange = (long)priceLevelSizeChange;
            }

            // Call the Price Level Handler if set
            if (mLevelHandler != null)
            {
                if (isRecap)
                {
                    mLevelHandler.onBookAtomicLevelRecap(
                        subscription, this, msg, this);
                }
                else
                {
                    mLevelHandler.onBookAtomicLevelDelta(
                        subscription, this, msg, this);
                }
            }

            // Handle entries.
            //
            // Note: the number of entries actually present may well
            // not add up to the PL_NUM_ENTRIES; it may be more than,
            // less than or equal to PL_NUM_ENTRIES.  For example, if
            // the delta is a price level update then PL_NUM_ENTRIES
            // indicates the total number of remaining entries whereas
            // the array of entries in the message will only contain
            // those that are being added/deleted/updated. Only if the
            // price level action is an add should the number of
            // entries match.
            //

            if (mLevelEntryHandler != null)
            {
                // clear entry cache
                clearLevelEntryFields();

                // First try a single vector.
                int       numEntriesInMsg = 0;
                MamaMsg[] msgEntries      = null;

                /* We won't have PL_ENTRIES if FieldAttrsOrderBookWombatMsg
                 * is not specified in the data dictionary */
                if (MamdaOrderBookFields.PL_ENTRIES != null)
                {
                    /* null is passed as default value otherwise
                     * getVectorMsg throws an exception if not found */
                    msgEntries = plMsg.getVectorMsg(MamdaOrderBookFields.PL_ENTRIES, null);
                    if (msgEntries != null)
                    {
                        numEntriesInMsg = msgEntries.Length;
                    }
                }

                if (numEntriesInMsg > 0)
                {
                    mPriceLevelActNumEntries = numEntriesInMsg;

                    for (int j = 0; j < numEntriesInMsg; j++)
                    {
                        entMsg = msgEntries[j];

                        getEntriesInfo(entMsg);
                        if (isRecap)
                        {
                            mLevelEntryHandler.onBookAtomicLevelEntryRecap(
                                subscription, this, msg, this);
                        }
                        else
                        {
                            mLevelEntryHandler.onBookAtomicLevelEntryDelta(
                                subscription, this, msg, this);
                        }
                    }
                }
                else
                {
                    // Second, try the list of entries.
                    int maxEntryFields = MamdaOrderBookFields.getNumEntryFields();

                    // getNumEntryFields() defaults to 0 but we want to go into the
                    // below loop at least once for flattened messages scenario
                    if (maxEntryFields == 0)
                    {
                        maxEntryFields = 1;
                    }

                    int numEntryAttached = plMsg.getI32(MamdaOrderBookFields.PL_NUM_ATTACH, 1);
                    if (numEntryAttached < maxEntryFields)
                    {
                        maxEntryFields = numEntryAttached;
                    }
                    mPriceLevelActNumEntries = maxEntryFields;
                    for (int j = 1; j <= maxEntryFields; j++)
                    {
                        if (MamdaOrderBookFields.PL_ENTRY.Length > 1)
                        {
                            entMsg = plMsg.getMsg(MamdaOrderBookFields.PL_ENTRY[j], null);
                        }

                        if ((entMsg == null) && (numEntryAttached == 1))
                        {
                            // Price level fields are probably be in the main message.
                            entMsg = plMsg;
                        }
                        if (entMsg != null)
                        {
                            if (!getEntriesInfo(entMsg))
                            {
                                return;
                            }

                            if (isRecap)
                            {
                                mLevelEntryHandler.onBookAtomicLevelEntryRecap(
                                    subscription, this, msg, this);
                            }
                            else
                            {
                                mLevelEntryHandler.onBookAtomicLevelEntryDelta(
                                    subscription, this, msg, this);
                            }
                        }
                    }
                }
            }
        }