Ejemplo n.º 1
0
        // CAT I have not checked for the semantic correctness of this code.
        //
        public static unsafe bool SerializeVarLength(NativeSA target, int source)
        {
            uint uSource = (uint)source;

            if (target.EnsureAvailable(sizeof(int)))
            {
                uint  offset = 0;
                byte *ptr    = (byte *)(target.ArrayBegin + target.CurPos);

                do
                {
                    ptr[offset] = (byte)(uSource & 0x7f);
                    uSource   >>= 7;
                    if (uSource > 0)
                    {
                        ptr[offset] |= 0x80;
                    }
                    ++offset;
                } while (uSource != 0);
                target.CurPos += (int)offset;

                return(true);
                //Console.WriteLine("Wrote {0} bytes\t{1:x8}", offset, Convert.ToString(source, 2).PadLeft(32, '0'));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static unsafe NativeSA Serialize(NativeSA target, string source)
        {
            int stringLength = source.Length;

            if (target.EnsureAvailable(stringLength * sizeof(char) + sizeof(int)))
            {
                target = Serialize(target, stringLength);
                if (stringLength > 0)
                {
                    char *targetCharPtr = (char *)(target.ArrayBegin + target.CurPos);
                    fixed(char *strPtr = source)
                    {
                        char *sourceCharPtr = strPtr;

                        for (int i = 0; i < stringLength; ++i)
                        {
                            *targetCharPtr++ = *sourceCharPtr++;
                        }
                    }

                    target.CurPos += stringLength * sizeof(char);
                }
            }
            return(target);
        }
Ejemplo n.º 3
0
        public static unsafe NativeSA Serialize(NativeSA target, float source)
        {
            if (target.EnsureAvailable(sizeof(float)))
            {
                float *dest = (float *)(target.ArrayBegin + target.CurPos);
                *      dest = source;

                target.CurPos += sizeof(float);
            }
            return(target);
        }
Ejemplo n.º 4
0
        public static unsafe NativeSA Serialize(NativeSA target, double source)
        {
            if (target.EnsureAvailable(sizeof(double)))
            {
                double *dest = (double *)(target.ArrayBegin + target.CurPos);
                *       dest = source;

                target.CurPos += sizeof(double);
            }
            return(target);
        }
Ejemplo n.º 5
0
        public static unsafe NativeSA Serialize(NativeSA target, ulong source)
        {
            if (target.EnsureAvailable(sizeof(ulong)))
            {
                ulong *dest = (ulong *)(target.ArrayBegin + target.CurPos);

                *dest = source;
                target.CurPos += sizeof(ulong);
            }
            return(target);
        }
Ejemplo n.º 6
0
        public static unsafe NativeSA Serialize(NativeSA target, float[] array)
        {
            int arrayLength = array.Length;

            if (target.EnsureAvailable(arrayLength * sizeof(float) + sizeof(int)))
            {
                target = Serialize(target, arrayLength);

                float *dest = (float *)(target.ArrayBegin + target.CurPos);
                for (int i = 0; i < arrayLength; i++)
                {
                    *dest++ = array[i];
                }
                target.CurPos += arrayLength * sizeof(float);
            }
            return(target);
        }
Ejemplo n.º 7
0
 public static unsafe NativeSA Serialize(NativeSA target, bool source)
 {
     return(Serialize(target, (int)(source ? 1 : 0)));
 }