コード例 #1
0
 public object DecodeObject(FudgeMsgEnvelope fudgeMsgEnvelope)
 {
     if (_checkSeqNumber)
     {
         long? seqNumber = fudgeMsgEnvelope.Message.GetLong("#");
         if (!seqNumber.HasValue)
         {
             throw new ArgumentException("Couldn't find sequence number");
         }
         long expectedSeqNumber = Interlocked.Increment(ref _lastSequenceNumber);
         if (expectedSeqNumber != seqNumber.Value)
         {
             throw new ArgumentException(string.Format("Unexpected SEQ number {0} expected {1}", seqNumber,
                                                       expectedSeqNumber));
         }
     }
     return _fudgeContext.DeFudgeSerialize(fudgeMsgEnvelope.Message);
 }
コード例 #2
0
        /// <summary>
        /// Parses data from a given <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="binaryReader"></param>
        /// <returns></returns>
        public FudgeMsgEnvelope Parse(BinaryReader binaryReader)
        {
            FudgeEncodedStreamReader reader = new FudgeEncodedStreamReader(FudgeContext);

            reader.Reset(binaryReader);
            FudgeStreamElement element = reader.MoveNext();

            if (element == FudgeStreamElement.NoElement)
            {
                return(null);
            }
            if (element != FudgeStreamElement.MessageStart)
            {
                throw new ArgumentException("First element in encoding stream wasn't a message element.");
            }
            int              version  = reader.SchemaVersion;
            FudgeMsg         msg      = FudgeContext.NewMessage();
            FudgeMsgEnvelope envelope = new FudgeMsgEnvelope(msg, version);

            ProcessFields(reader, msg);
            return(envelope);
        }
コード例 #3
0
ファイル: FudgeMsg.cs プロジェクト: quantsegu/Fudge-CSharp
        /// <summary>
        /// Populates the message fields from the encoded data. If the array is larger than the Fudge envelope, any additional data is ignored.
        /// </summary>
        /// <param name="byteArray">the encoded data to populate this message with</param>
        protected void InitializeFromByteArray(byte[] byteArray)
        {
            FudgeMsgEnvelope other = context.Deserialize(byteArray);

            fields.AddRange(other.Message.fields);
        }
コード例 #4
0
 /// <summary>
 /// Parses data from a given <see cref="BinaryReader"/>.
 /// </summary>
 /// <param name="binaryReader"></param>
 /// <returns></returns>
 public FudgeMsgEnvelope Parse(BinaryReader binaryReader)
 {
     FudgeEncodedStreamReader reader = new FudgeEncodedStreamReader(FudgeContext, binaryReader);
     FudgeStreamElement element = reader.MoveNext();
     if (element == FudgeStreamElement.NoElement)
     {
         return null;
     }
     if (element != FudgeStreamElement.MessageStart)
     {
         throw new ArgumentException("First element in encoding stream wasn't a message element.");
     }
     int version = reader.SchemaVersion;
     FudgeMsg msg = FudgeContext.NewMessage();
     FudgeMsgEnvelope envelope = new FudgeMsgEnvelope(msg, version);
     ProcessFields(reader, msg);
     return envelope;
 }