Exemplo n.º 1
0
        public void testEncodeInt16()
        {
            var @out = new byte[16];

            PrepareOutput(@out);
            NB.encodeInt16(@out, 0, 0);
            AssertOutput(b(0, 0), @out, 0);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 3, 0);
            AssertOutput(b(0, 0), @out, 3);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 0, 3);
            AssertOutput(b(0, 3), @out, 0);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 3, 3);
            AssertOutput(b(0, 3), @out, 3);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 0, 0xdeac);
            AssertOutput(b(0xde, 0xac), @out, 0);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 3, 0xdeac);
            AssertOutput(b(0xde, 0xac), @out, 3);

            PrepareOutput(@out);
            NB.encodeInt16(@out, 3, -1);
            AssertOutput(b(0xff, 0xff), @out, 3);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an empty entry at the specified stage.
        /// </summary>
        /// <param name="newPath">
        /// Name of the cache entry, in the standard encoding.
        /// </param>
        /// <param name="stage">The stage index of the new entry.</param>
        public DirCacheEntry(byte[] newPath, int stage)
        {
            if (!isValidPath(newPath))
            {
                throw new ArgumentException("Invalid path: "
                                            + toString(newPath));
            }
            if (stage < 0 || 3 < stage)
            {
                throw new ArgumentException("Invalid stage " + stage
                                            + " for path " + toString(newPath));
            }

            _info       = new byte[INFO_LEN];
            _infoOffset = 0;
            _path       = newPath;

            int flags = ((stage & 0x3) << 12);

            if (_path.Length < NameMask)
            {
                flags |= _path.Length;
            }
            else
            {
                flags |= NameMask;
            }

            NB.encodeInt16(_info, _infoOffset + PFlags, flags);
        }
Exemplo n.º 3
0
        ///	<summary>
        /// Copy the ObjectId and other meta fields from an existing entry.
        ///	<para />
        ///	This method copies everything except the path from one entry to another,
        ///	supporting renaming.
        ///	</summary>
        ///	<param name="src">
        /// The entry to copy ObjectId and meta fields from.
        /// </param>
        public void copyMetaData(DirCacheEntry src)
        {
            int pLen = NB.decodeUInt16(_info, _infoOffset + PFlags) & NameMask;

            Array.Copy(src._info, src._infoOffset, _info, _infoOffset, INFO_LEN);

            NB.encodeInt16(_info, _infoOffset + PFlags, pLen
                           | NB.decodeUInt16(_info, _infoOffset + PFlags) & ~NameMask);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create an empty entry at the specified stage.
        /// </summary>
        /// <param name="newPath">
        /// Name of the cache entry, in the standard encoding.
        /// </param>
        /// <param name="stage">The stage index of the new entry.</param>
        public DirCacheEntry(byte[] newPath, int stage)
        {
            _info       = new byte[INFO_LEN];
            _infoOffset = 0;
            _path       = newPath;

            int flags = ((stage & 0x3) << 12);

            if (_path.Length < NameMask)
            {
                flags |= _path.Length;
            }
            else
            {
                flags |= NameMask;
            }

            NB.encodeInt16(_info, _infoOffset + PFlags, flags);
        }