GetCompressedUInt32Size() public static method

public static GetCompressedUInt32Size ( uint value ) : int
value uint
return int
コード例 #1
0
        //internal override void Reconstruct()
        //{
        //    MemoryStream newStream = new MemoryStream();
        //    BinaryWriter writer = new BinaryWriter(newStream);
        //    writer.Write((byte)0);
        //    ReadAllStrings();
        //    foreach (var readString in readStrings)
        //    {
        //        byte[] bytes = Encoding.Unicode.GetBytes(readString.Value);
        //        NETGlobals.WriteCompressedUInt32(writer, (uint)bytes.Length + 1); // length + terminator length
        //        writer.Write(bytes); // data
        //        writer.Write((byte)0); // terminator
        //    }
        //    binaryreader.Dispose();
        //    stream.Dispose();
        //    stream = newStream;
        //    binaryreader = new BinaryReader(newStream);
        //    this.streamHeader.Size = (uint)newStream.Length;
        //    this.contents = newStream.ToArray();
        //}

        internal void ReadAllStrings()
        {
            mainStream.Seek(0, SeekOrigin.Begin);

            uint lastPosition = (uint)mainStream.Position;

            while (mainStream.Position + 1 < mainStream.Length)
            {
                // TODO: write string.empty strings..

                bool   alreadyExisted = readStrings.ContainsKey((uint)mainStream.Position + 1);
                string value          = GetStringByOffset((uint)mainStream.Position + 1);


                int length = value.Length * 2;
                if (length == 0 && lastPosition == (uint)mainStream.Position)
                {
                    mainStream.Seek(1, SeekOrigin.Current);
                }
                if (alreadyExisted)
                {
                    mainStream.Seek(length + NETGlobals.GetCompressedUInt32Size((uint)length) + 1, SeekOrigin.Current);
                }

                lastPosition = (uint)mainStream.Position;
            }

            hasReadAllStrings = true;
            newEntryOffset    = (uint)mainStream.Length;
        }
コード例 #2
0
        internal void ReadAllBlobs()
        {
            mainStream.Seek(1, SeekOrigin.Begin);
            while (mainStream.Position < mainStream.Length)
            {
                bool   alreadyExisted = readBlobs.ContainsKey((uint)mainStream.Position);
                byte[] value          = GetBlob((uint)mainStream.Position);

                int length = value.Length;
                if (length == 0)
                {
                    break;
                }
                if (alreadyExisted)
                {
                    mainStream.Seek(length + NETGlobals.GetCompressedUInt32Size((uint)length), SeekOrigin.Current);
                }
            }
        }