/// <summary> /// Checks to see if we're at the end of a sub-message (or message), and if so pops the processing stack /// </summary> /// <returns>True if we were at the end of a sub-message.</returns> protected bool IsEndOfSubMessage() { Debug.Assert(processingStack.Count > 0); MessageProcessingState processingState = processingStack.Peek(); if (processingState.Consumed >= processingState.MessageSize) { processingStack.Pop(); if (processingStack.Count > 0) { processingStack.Peek().Consumed += processingState.Consumed; } return(true); } return(false); }
/** * */ protected void ConsumeMessageEnvelope() //throws IOException { Debug.Assert(!eof); CurrentElement = FudgeStreamElement.MessageStart; if (bufferedByte.HasValue) { processingDirectives = bufferedByte.Value; bufferedByte = null; } else { byte?nextByte = SafelyReadOneByte(); if (nextByte.HasValue) { processingDirectives = nextByte.Value; } else { // Hit the end of the stream CurrentElement = FudgeStreamElement.NoElement; eof = true; return; } } schemaVersion = Reader.ReadByte(); taxonomyId = Reader.ReadInt16(); envelopeSize = Reader.ReadInt32(); if (FudgeContext.TaxonomyResolver != null) { IFudgeTaxonomy taxonomy = FudgeContext.TaxonomyResolver.ResolveTaxonomy(taxonomyId); this.taxonomy = taxonomy; } MessageProcessingState processingState = new MessageProcessingState(); processingState.Consumed = 8; processingState.MessageSize = envelopeSize; processingStack.Push(processingState); }
/** * */ 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; } } }
//throws IOException /** * */ protected void ConsumeMessageEnvelope() { Debug.Assert(!eof); CurrentElement = FudgeStreamElement.MessageStart; if (bufferedByte.HasValue) { processingDirectives = bufferedByte.Value; bufferedByte = null; } else { byte? nextByte = SafelyReadOneByte(); if (nextByte.HasValue) processingDirectives = nextByte.Value; else { // Hit the end of the stream CurrentElement = FudgeStreamElement.NoElement; eof = true; return; } } schemaVersion = Reader.ReadByte(); taxonomyId = Reader.ReadInt16(); envelopeSize = Reader.ReadInt32(); if (FudgeContext.TaxonomyResolver != null) { IFudgeTaxonomy taxonomy = FudgeContext.TaxonomyResolver.ResolveTaxonomy(taxonomyId); this.taxonomy = taxonomy; } MessageProcessingState processingState = new MessageProcessingState(); processingState.Consumed = 8; processingState.MessageSize = envelopeSize; processingStack.Push(processingState); }
//throws IOException /** * */ protected void ConsumeFieldData() { 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; } } }