示例#1
0
        public MetaBuilderPointer AddString(string str)
        {
            str = str ?? "";
            MetaBuilderBlock block = EnsureBlock(MetaName.STRING);

            byte[] data    = Encoding.ASCII.GetBytes(str);
            int    datalen = data.Length;
            int    newlen  = datalen;
            int    lenrem  = newlen % 16;

            if (lenrem != 0)  //need to pad the data length up to multiple of 16.
            {
                newlen += (16 - lenrem);
            }
            byte[] newdata = new byte[newlen];
            Buffer.BlockCopy(data, 0, newdata, 0, datalen);
            int offs             = block.TotalSize;
            int idx              = block.AddItem(newdata);
            MetaBuilderPointer r = new MetaBuilderPointer();

            r.BlockID = block.Index + 1;
            r.Offset  = offs;    // (idx * data.Length);
            r.Length  = datalen; //actual length of string.
            return(r);
        }
示例#2
0
        public MetaBuilderPointer AddItem(MetaName type, byte[] data)
        {
            MetaBuilderBlock block = EnsureBlock(type);
            int brem = data.Length % 16;

            if (brem > 0)
            {
                int    newlen  = data.Length - brem + 16;
                byte[] newdata = new byte[newlen];
                Buffer.BlockCopy(data, 0, newdata, 0, data.Length);
                data = newdata; //make sure item size is multiple of 16... so pointers don't need sub offsets!
            }
            int idx = block.AddItem(data);
            MetaBuilderPointer r = new MetaBuilderPointer();

            r.BlockID = block.Index + 1;
            r.Offset  = (idx * data.Length);
            r.Length  = data.Length;
            return(r);
        }
示例#3
0
        public MetaBuilderPointer AddItemArray(MetaName type, byte[] data, int length)
        {
            MetaBuilderBlock block = EnsureBlock(type);
            int datalen            = data.Length;
            int newlen             = datalen;
            int lenrem             = newlen % 16;

            if (lenrem != 0)
            {
                newlen += (16 - lenrem);
            }
            byte[] newdata = new byte[newlen];
            Buffer.BlockCopy(data, 0, newdata, 0, datalen);
            int offs             = block.TotalSize;
            int idx              = block.AddItem(newdata);
            MetaBuilderPointer r = new MetaBuilderPointer();

            r.BlockID = block.Index + 1;
            r.Offset  = offs; //(idx * data.Length);;
            r.Length  = length;
            return(r);
        }