Ejemplo n.º 1
0
        /// <summary>
        /// Write FBQE
        /// </summary>
        /// <param name="f"></param>
        private void SerializeFBQE(FBQE f)
        {
            VSLib.CopyBytes(buffer, VSLib.ConvertStringToByte(DEFS.FBQE_SIGNATURE), f.address + SG_POS, SG_LEN);
            VSLib.CopyBytes(buffer, VSLib.ConvertLongToByte(f.ADDRESS_START), f.address + ADDRESS_START_POS, ADDRESS_START_LEN);
            VSLib.CopyBytes(buffer, VSLib.ConvertLongToByte(f.ADDRESS_END), f.address + ADDRESS_END_POS, ADDRESS_END_LEN);
            VSLib.CopyBytes(buffer, VSLib.ConvertLongToByte(f.LENGTH), f.address + LENGTH_POS, LENGTH_LEN);
            VSLib.CopyBytes(buffer, VSLib.ConvertIntToByte(f.PREV), f.address + PREV_POS, PREV_LEN);
            VSLib.CopyBytes(buffer, VSLib.ConvertIntToByte(f.NEXT), f.address + NEXT_POS, NEXT_LEN);

            F_Object.Write(f.address, VSLib.GetByteArray(buffer, f.address, FBQE_LENGTH), FBQE_LENGTH);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Write data (int)
 /// </summary>
 /// <param name="address"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Write(long address, int data)
 {
     Write(address, VSLib.ConvertIntToByte(data), 4);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Set int value
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public void Set(string name, int value)
 {
     set_field(name, FIELD_TYPE_INT, VSLib.ConvertIntToByte(value));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Serialize all fields to object fields space
        /// Free excessive chunks if needed
        /// </summary>
        private void serialize()
        {
            // If no fields
            if (FCache.Count == 0)
            {
                set_alloc(ALLOC_RESET);
                FIELDS_SIZE = 0;
                FreeSpace   = -1;
                FCache      = null;
                return;
            }

            byte[] b        = null;
            int    old_size = (int)(FIELDS_SIZE);                  // Current used size (number of fields + all fields size)

            // 1. Calculate new size
            int new_size = FIRST_FIELD_OFFSET_REL;

            for (int i = 0; i < FCache.Count; i++)
            {
                new_size += FCache[i].FULL_LENGTH;
            }

            // 2. Check if space is availabe, extend if required
            if (new_size > (old_size + FreeSpace))
            {
                sp.Extend(this, (new_size - old_size));
            }

            // 3. Check if only value update is required

            List <FieldCache> afc = FCache;

            FCache = new List <FieldCache>(32);

            int array_size = (new_size > old_size) ? new_size : old_size;

            byte[] data = new byte[array_size];


            int data_pos = FIRST_FIELD_OFFSET_REL;

            VSLib.CopyBytes(data, VSLib.ConvertIntToByte(new_size), FIELDS_SIZE_POS, FIELDS_SIZE_LEN);                          // Size
            VSLib.CopyBytes(data, VSLib.ConvertShortToByte((short)afc.Count), FIELDS_NUMBER_POS, FIELDS_NUMBER_LEN);            // Fields number

            FCache.Clear();
            for (int i = 0; i < afc.Count; i++)
            {
                FieldCache fc_element = afc[i];
                if (!fc_element.DELETED)
                {
                    fc_element.OFFSET = data_pos;

                    // Type
                    data[data_pos] = fc_element.TYPE;
                    data_pos++;

                    // Name length
                    data[data_pos] = (byte)(fc_element.NAME.Length);
                    data_pos++;

                    // Name
                    b = VSLib.ConvertStringToByte(fc_element.NAME);
                    VSLib.CopyBytes(data, b, data_pos, b.Length);
                    data_pos += b.Length;

                    // Value
                    if (FIELD_COMPRESS[fc_element.TYPE])                                                              // int/long/decimal
                    {
                        data[data_pos] = (byte)(fc_element.LENGTH);
                        data_pos++;
                    }
                    else if ((fc_element.TYPE == FIELD_TYPE_BYTES) | (fc_element.TYPE == FIELD_TYPE_STRING))
                    {
                        b = compress(VSLib.ConvertLongToByte(fc_element.LENGTH), FIELD_TYPE_LONG);
                        data[data_pos] = (byte)b.Length;
                        data_pos++;

                        if (b.Length > 0)
                        {
                            VSLib.CopyBytes(data, b, data_pos, b.Length);
                            data_pos += b.Length;
                        }
                    }

                    // Write value
                    if (fc_element.VALUE.Length > 0)
                    {
                        VSLib.CopyBytes(data, fc_element.VALUE, data_pos, fc_element.VALUE.Length);
                        data_pos += afc[i].LENGTH;
                    }

                    // Shift offset and add to cache
                    fc_element.OLDLENGTH = afc[i].LENGTH;
                    fc_element.STATE     = STATE_LOADED;

                    FCacheTree.Insert(fc_element.NAME, FCache.Count);
                    FCache.Add(fc_element);
                }
            }

            base.Write(base.FIXED, data, data.Length);

            set_alloc(ALLOC_RENEW);

            // Fill the rest by zeros if le length < old length
            if (new_size < old_size)
            {
                long full_used_size = base.FIXED + new_size;
                b = new byte[old_size - new_size];
                base.Write(full_used_size, b, b.Length);                              // Fill be zeros unused space

                // Multiple chunks, chech if there are exessive
                if (base.Chunk > 0)
                {
                    sp.ShrinkObject(this, full_used_size);
                }
            }

            FreeSpace = (int)(this.Size - base.FIXED - new_size);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Write int
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="data"></param>
 public void Write(long offset, int data)
 {
     byte[] b = VSLib.ConvertIntToByte(data);
     this.Write(offset, ref b);
 }