Beispiel #1
0
        public static GroupListOverlay <T> Factory(
            IBinaryReadStream stream,
            ReadOnlyMemorySlice <byte> data,
            BinaryOverlayFactoryPackage package,
            ObjectType objectType,
            int offset)
        {
            List <int> locations = new List <int>();

            stream.Position -= package.MetaData.Constants.GroupConstants.HeaderLength;
            var groupMeta = stream.GetGroup(package);
            var finalPos  = stream.Position + groupMeta.TotalLength;

            stream.Position += package.MetaData.Constants.GroupConstants.HeaderLength;
            // Parse locations
            while (stream.Position < finalPos)
            {
                VariableHeader meta = package.MetaData.Constants.Constants(objectType).VariableMeta(stream.RemainingMemory);
                locations.Add(checked ((int)stream.Position - offset));
                stream.Position += checked ((int)meta.TotalLength);
            }

            return(new GroupListOverlay <T>(
                       locations,
                       data,
                       package));
        }
Beispiel #2
0
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(base.ToString());
            sb.AppendLine(VariableHeader.ToString());
            sb.AppendLine(Payload.ToString());

            return(sb.ToString());
        }
Beispiel #3
0
        public override void Encode(IByteBuffer buffer)
        {
            var buf = Unpooled.Buffer();

            try
            {
                VariableHeader.Encode(buf, FixedHeader);
                Payload.Encode(buf);
                FixedHeader.Encode(buffer, buf.ReadableBytes);
                buffer.WriteBytes(buf);
            }
            finally
            {
                buf?.Release();
            }
        }
Beispiel #4
0
            public static GroupMajorRecordCacheWrapper <T> Factory(
                IBinaryReadStream stream,
                ReadOnlyMemorySlice <byte> data,
                BinaryOverlayFactoryPackage package,
                int offset)
            {
                Dictionary <FormKey, int> locationDict = new Dictionary <FormKey, int>();

                stream.Position -= package.MetaData.Constants.GroupConstants.HeaderLength;
                var groupMeta = stream.GetGroup(package.MetaData);
                var finalPos  = stream.Position + groupMeta.TotalLength;

                stream.Position += package.MetaData.Constants.GroupConstants.HeaderLength;
                // Parse MajorRecord locations
                ObjectType?lastParsed = default;

                while (stream.Position < finalPos)
                {
                    VariableHeader varMeta = package.MetaData.Constants.NextRecordVariableMeta(stream.RemainingMemory);
                    if (varMeta.IsGroup)
                    {
                        if (lastParsed != ObjectType.Record)
                        {
                            throw new DataMisalignedException("Unexpected Group encountered which was not after a major record: " + GroupRecordTypeGetter <T> .GRUP_RECORD_TYPE);
                        }
                        stream.Position += checked ((int)varMeta.TotalLength);
                        lastParsed       = ObjectType.Group;
                    }
                    else
                    {
                        MajorRecordHeader majorMeta = package.MetaData.Constants.MajorRecord(stream.RemainingMemory);
                        if (majorMeta.RecordType != GroupRecordTypeGetter <T> .GRUP_RECORD_TYPE)
                        {
                            throw new DataMisalignedException("Unexpected type encountered when parsing MajorRecord locations: " + majorMeta.RecordType);
                        }
                        var formKey = FormKey.Factory(package.MetaData.MasterReferences !, majorMeta.FormID.Raw);
                        locationDict.Add(formKey, checked ((int)(stream.Position - offset)));
                        stream.Position += checked ((int)majorMeta.TotalLength);
                        lastParsed       = ObjectType.Record;
                    }
                }

                return(new GroupMajorRecordCacheWrapper <T>(
                           locationDict,
                           data,
                           package));
            }
Beispiel #5
0
 /// <summary>
 /// ss the message to the supplied stream.
 /// </summary>
 /// <param name="messageStream">The stream to write the message to.</param>
 public override void WriteTo(Stream messageStream)
 {
     this.Header.WriteTo(VariableHeader.GetWriteLength() + Payload.GetWriteLength(), messageStream);
     this.VariableHeader.WriteTo(messageStream);
     this.Payload.WriteTo(messageStream);
 }