Beispiel #1
0
        KeyValuePair <BlobChunkHeader, byte[]> WriteChunksProcessObject(BlobObject obj)
        {
            byte[] data;

            var byte_order = UnderlyingStream.ByteOrder;

            if (obj.SystemGroupVersionInfo.ForceLittleEndian)
            {
                byte_order = Shell.EndianFormat.Little;
            }

            var sys_group = obj.SystemGroup;

            // #TODO_IMPLEMENT: support non-fixed length blobs like film streams
            using (var ms = new System.IO.MemoryStream(obj.CalculateFixedBinarySize(this.GameTarget)))
                using (var es = new IO.EndianStream(ms, byte_order, this, sys_group.GroupTag.Name, FileAccess.Write))
                {
                    es.StreamMode = FileAccess.Write;

                    obj.Serialize(es);

                    data = ms.ToArray();
                }

            var header = new BlobChunkHeader(sys_group.GroupTag, obj.Version, data.Length, obj.BlobFlags);

            return(new KeyValuePair <BlobChunkHeader, byte[]>(header, data));
        }
Beispiel #2
0
        static byte[] GetEnumerateStreamResultBytes(BlobTransportStream @this, BlobChunkHeader header)
        {
            byte[] bytes = new byte[header.DataSize];
            @this.UnderlyingStream.Stream(bytes);

            return(bytes);
        }
Beispiel #3
0
        /*public*/ bool TryAndFind(BlobChunkHeader signature, long findStartPosition = TypeExtensions.kNone)
        {
            Contract.Requires <ArgumentOutOfRangeException>(findStartPosition.IsNone() ||
                                                            findStartPosition < AssumedBlobSize);

            Util.MarkUnusedVariable(ref signature);

            bool blob_found = false;
            long orig_pos   = TypeExtensions.kNone;

            if (findStartPosition.IsNotNone())
            {
                orig_pos = UnderlyingStream.BaseStream.Position;
                UnderlyingStream.Seek(findStartPosition + StartPosition, System.IO.SeekOrigin.Begin);
            }

            // #TODO_IMPLEMENT
            Contract.Assert(false, "TODO");

            if (orig_pos.IsNotNone())
            {
                UnderlyingStream.Seek(orig_pos, System.IO.SeekOrigin.Begin);
            }

            return(blob_found);
        }
            public StreamFooter(BlobTransportStreamAuthentication authentication, long blobSize)
            {
                BlobSize           = (uint)blobSize;
                Authentication     = authentication;
                AuthenticationData = null;

                Header = new BlobChunkHeader(kSignature, kVersion, kSizeOfDataSansAuthData + Authentication.GetDataSize());
                InitializeData();
            }
Beispiel #5
0
 void EnumerateChunksReadObjectFoundBuildIncompatibility(BlobSystem blobSystem,
                                                         BlobChunkHeader header, BlobGroup blobGroup,
                                                         Engine.EngineBuildHandle buildForBlobVersion, Engine.EngineBuildHandle actualBuild)
 {
     throw new InvalidOperationException(string.Format(
                                             "Build incompatibility for chunk {0} v{1} sizeof({2}) which uses build={3} " +
                                             "but we're using build={4} for {5}",
                                             blobGroup.GroupTag.TagString, header.Version, header.DataSize, buildForBlobVersion.ToDisplayString(),
                                             actualBuild.ToDisplayString(), UnderlyingStream.StreamName));
 }
Beispiel #6
0
        void EnumerateChunksReadObjectFoundUnknownChunk(BlobSystem blobSystem,
                                                        BlobChunkHeader header, bool throwOnUnhandledChunk)
        {
            const string kUnhandledChunkMessageFormat = " chunk {0} v{1} sizeof({2}) for target={3}";

            string tag_string = new string(Values.GroupTagData32.FromUInt(header.Signature));

            if (throwOnUnhandledChunk)
            {
                throw new InvalidDataException(string.Format("Unhandled" + kUnhandledChunkMessageFormat,
                                                             tag_string, header.Version, header.DataSize, GameTarget.ToDisplayString()));
            }

            Debug.Trace.Blob.TraceInformation("Ignoring" + kUnhandledChunkMessageFormat,
                                              tag_string, header.Version, header.DataSize, GameTarget.ToDisplayString());
        }
Beispiel #7
0
        BlobChunkVerificationResultInfo EnumerateOneChunk <T>(
            out BlobChunkHeader header, ref T resultValue,
            Func <BlobTransportStream, BlobChunkHeader, T> getResultValue, bool getResultValueConsumesChunk,
            out bool isEof)
        {
            header = BlobChunkHeader.Null;
            isEof  = false;
            var result = VerifyEnoughBytesForChunkOrData(BlobChunkHeader.kSizeOf);

            if (result.IsValid)
            {
                UnderlyingStream.Stream(ref header);
                result = header.VerifyVersionIsPositive()
                         .And(header, h => h.VerifyDataSize(0))
                         .And(header, h => h.VerifyFlagsIsPostive())
                         .And(header, this, (h, s) => s.VerifyEnoughBytesForChunkOrData(h.DataSize));

                isEof = header.Signature == StreamFooter.kSignature.ID;

                if (result.IsValid)
                {
                    if (isEof)
                    {
                        mFooterPosition = BaseStream.Position - BlobChunkHeader.kSizeOf;
                        mFooter.SerializeSansHeader(UnderlyingStream, header);
                        mFooter.SerializeAuthenticationData(UnderlyingStream);
                    }
                    else
                    {
                        resultValue = getResultValue(this, header);

                        if (!getResultValueConsumesChunk)
                        {
                            header.StreamSkipData(BaseStream);
                        }
                    }
                }
                else
                {
                    if (isEof)
                    {
                        result.Context = BlobChunkVerificationResultContext.Footer;
                    }
                }
            }
            return(result);
        }
Beispiel #8
0
        BlobObject EnumerateChunksReadObject(BlobSystem blobSystem, BlobGroup blobGroup, BlobGroupVersionAndBuildInfo infoForVersion,
                                             BlobChunkHeader header, byte[] data)
        {
            Contract.Requires <InvalidOperationException>(!GameTarget.IsNone);

            var obj = blobSystem.CreateObject(GameTarget, blobGroup, header.Version, header.Size);

            var byte_order = UnderlyingStream.ByteOrder;

            if (infoForVersion.ForceLittleEndian)
            {
                byte_order = Shell.EndianFormat.Little;
            }

            using (var ms = new System.IO.MemoryStream(data))
                using (var es = new IO.EndianStream(ms, byte_order, this, blobGroup.GroupTag.Name, FileAccess.Read))
                {
                    es.StreamMode = FileAccess.Read;

                    obj.Serialize(es);
                }

            return(obj);
        }
 public void SerializeSansHeader(IO.EndianStream s, BlobChunkHeader providedHeader)
 {
     Header = providedHeader;
     s.Stream(ref BlobSize);
     s.Stream(ref Authentication, AuthenticationTypeStreamer.Instance);
 }
Beispiel #10
0
        static long GetEnumerateStreamResultDataPosition(BlobTransportStream @this, BlobChunkHeader header)
        {
            Util.MarkUnusedVariable(ref header);

            return(@this.BaseStream.Position);            // position at this point will be right after [header]
        }