예제 #1
0
 // max obj size
 /// <exception cref="System.IO.IOException"></exception>
 private void PackHeader(TemporaryBuffer.Heap tinyPack, int cnt)
 {
     byte[] hdr = new byte[8];
     NB.EncodeInt32(hdr, 0, 2);
     NB.EncodeInt32(hdr, 4, cnt);
     tinyPack.Write(Constants.PACK_SIGNATURE);
     tinyPack.Write(hdr, 0, 8);
 }
예제 #2
0
 /// <exception cref="System.IO.IOException"></exception>
 private void Digest(TemporaryBuffer.Heap buf)
 {
     MessageDigest md = Constants.NewMessageDigest();
     md.Update(buf.ToByteArray());
     buf.Write(md.Digest());
 }
예제 #3
0
 /// <exception cref="System.IO.IOException"></exception>
 private void ObjectHeader(TemporaryBuffer.Heap pack, int type, int sz)
 {
     byte[] buf = new byte[8];
     int nextLength = (int)(((uint)sz) >> 4);
     buf[0] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked((int
         )(0x00))) | (type << 4) | (sz & unchecked((int)(0x0F)))));
     sz = nextLength;
     int n = 1;
     while (sz > 0)
     {
         nextLength = (int)(((uint)nextLength) >> 7);
         buf[n++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
             (int)(0x00))) | (sz & unchecked((int)(0x7F)))));
         sz = nextLength;
     }
     pack.Write(buf, 0, n);
 }
예제 #4
0
 /// <exception cref="System.IO.IOException"></exception>
 private void Deflate(TemporaryBuffer.Heap tinyPack, byte[] content)
 {
     Deflater deflater = new Deflater();
     byte[] buf = new byte[128];
     deflater.SetInput(content, 0, content.Length);
     deflater.Finish();
     do
     {
         int n = deflater.Deflate(buf, 0, buf.Length);
         if (n > 0)
         {
             tinyPack.Write(buf, 0, n);
         }
     }
     while (!deflater.IsFinished);
 }
		/// <exception cref="System.IO.IOException"></exception>
		private void Copy(TemporaryBuffer.Heap tinyPack, ObjectLoader ldr)
		{
			byte[] buf = new byte[64];
			byte[] content = ldr.GetCachedBytes();
			int dataLength = content.Length;
			int nextLength = (int)(((uint)dataLength) >> 4);
			int size = 0;
			buf[size++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
				(int)(0x00))) | (ldr.GetType() << 4) | (dataLength & unchecked((int)(0x0F)))));
			dataLength = nextLength;
			while (dataLength > 0)
			{
				nextLength = (int)(((uint)nextLength) >> 7);
				buf[size++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
					(int)(0x00))) | (dataLength & unchecked((int)(0x7F)))));
				dataLength = nextLength;
			}
			tinyPack.Write(buf, 0, size);
			Deflate(tinyPack, content);
		}