Exemplo n.º 1
0
            public static void Initialize()
            {
                _getCharsDelegate = BurstCompiler.
                                    CompileFunctionPointer <GetCharsDelegate>(GetCharsBurst).Invoke;

                _terminateDelegate = BurstCompiler.
                                     CompileFunctionPointer <TerminateDelegate>(TerminateBurst).Invoke;

                _getBytesDelegate = BurstCompiler.
                                    CompileFunctionPointer <GetBytesDelegate>(GetBytesBurst).Invoke;
            }
Exemplo n.º 2
0
        /// <summary>
        /// Encodes a value to <paramref name="buffer"/> starting at <paramref name="offset"/>.
        /// </summary>
        /// <typeparam name="T">The type of the value to encode.</typeparam>
        /// <param name="value">The value to encode.</param>
        /// <param name="buffer">The buffer to encode to.</param>
        /// <param name="offset">The offset within the <paramref name="buffer"/> to encode to.</param>
        /// <exception cref="ArgumentException">Thrown when the specified <paramref name="T"/> has no associated mapping.</exception>
        public static void GetBytes <T>(T value, byte[] buffer, int offset)
        {
            Type type = typeof(T);

            if (!GET_BYTES_DELEGATE_MAPPING.ContainsKey(type))
            {
                throw new ArgumentException("Could not find delegate mapping for generic type");
            }

            GetBytesDelegate <T> getBytesDelegate = (GetBytesDelegate <T>)GET_BYTES_DELEGATE_MAPPING[type];

            getBytesDelegate(value, buffer, offset);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Registers a <see cref="GetBytesDelegate{T}"/> for the <paramref name="T"/> type.
        /// </summary>
        /// <typeparam name="T">The value type.</typeparam>
        /// <param name="getBytesDelegate">The delegate that encodes the <paramref name="T"/> type.</param>
        /// /// <exception cref="ArgumentNullException">Thrown when the specified <paramref name="getBytesDelegate"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when the specified <paramref name="T"/> is already registered.</exception>
        public static void RegisterGetBytesDelegate <T>(GetBytesDelegate <T> getBytesDelegate)
        {
            if (getBytesDelegate == null)
            {
                throw new ArgumentNullException("getBytesDelegate");
            }

            Type type = typeof(T);

            if (GET_BYTES_DELEGATE_MAPPING.ContainsKey(type))
            {
                throw new ArgumentException("Duplicate delegate registration for generic type");
            }

            GET_BYTES_DELEGATE_MAPPING.Add(type, getBytesDelegate);
        }
Exemplo n.º 4
0
 public SimpleTypeBitConverter(GetBytesDelegate getBytes, GetTypeDelegate fromBytes, int length)
 {
     this.getBytes  = getBytes;
     this.fromBytes = fromBytes;
     this.Length    = length;
 }