/// <summary>
            /// Writes the specified 64-bit signed integer value to the buffer with the correct formatting.
            /// </summary>
            /// <param name="value">The value to write.</param>
            public void WriteValue(long value)
            {
                FixedString128 f = default;

                f.Append(value);
                WriteValue(f);
            }
        /// <summary>
        /// Writes the string representation of a specified 32-bit unsigned integer to the buffer.
        /// </summary>
        /// <param name="value">The value to write.</param>
        public void Write(uint value)
        {
            FixedString128 f = default;

            f.Append(value);
            Write(f);
        }
        /// <summary>
        /// Writes the string representation of a specified 64-bit floating-point number to the buffer.
        /// </summary>
        /// <param name="value">The value to write.</param>
        public void Write(double value)
        {
            FixedString128 f = default;

            f.Append((float)value);
            Write(f);
        }
        public unsafe void PushObjectField(FixedString128 key)
        {
            AddCommaIfRequired();
            ValidateInObject();
            FixedString128 str = $"\"{key}\": ";

            str.Append((FixedString32)"{ ");
            m_Buffer.Append(str.GetUnsafePtr(), str.Length);
            m_Stack.Push(k_EmptyObject);
        }
            /// <summary>
            /// Writes the specified 32-bit floating-point value to the buffer with the correct formatting.
            /// </summary>
            /// <param name="value">The value to write.</param>
            public void WriteValue(float value)
            {
                if (float.IsInfinity(value))
                {
                    if (float.IsNegativeInfinity(value))
                    {
                        WriteNegativeInfinity();
                    }
                    else
                    {
                        WritePositiveInfinity();
                    }
                }

                FixedString128 f = default;

                f.Append(value);
                WriteValue(f);
            }
Beispiel #6
0
        internal static FixedString128 MessageObjectToString(object message)
        {
            FixedString128 result = default;

            if (message == null)
            {
                result.Append("(null)");
            }
            else if (message is string stringMessage)
            {
                result.Append(stringMessage);
            }
            else if (message is byte byteMessage)
            {
                result.Append(byteMessage);
            }
            else if (message is int intMessage)
            {
                result.Append(intMessage);
            }
            else if (message is short shortMessage)
            {
                result.Append(shortMessage);
            }
            else if (message is float floatMessage)
            {
                result.Append(floatMessage);
            }
            else if (message is double doubleMessage)
            {
                // TODO need double formatting
                result.Append((float)doubleMessage);
            }
            else if (message is bool boolMessage)
            {
                result.Append(boolMessage ? "true" : "false");
            }
            else if (message is char charMessage)
            {
                result.Append(charMessage);
            }
            else if (message is float2 f2Message)
            {
                result.Append("(");
                result.Append(f2Message.x);
                result.Append(", ");
                result.Append(f2Message.y);
                result.Append(")");
            }
            else if (message is float3 f3Message)
            {
                result.Append("(");
                result.Append(f3Message.x);
                result.Append(", ");
                result.Append(f3Message.y);
                result.Append(", ");
                result.Append(f3Message.z);
                result.Append(")");
            }
            else if (message is float4 f4Message)
            {
                result.Append("(");
                result.Append(f4Message.x);
                result.Append(", ");
                result.Append(f4Message.y);
                result.Append(", ");
                result.Append(f4Message.z);
                result.Append(", ");
                result.Append(f4Message.w);
                result.Append(")");
            }
            else if (message is Exception exc)
            {
                result.Append(exc.Message);
                result.Append("\n");
                result.Append(exc.StackTrace);
            }
            else if (message is IUTF8Bytes utf8BytesMessage)
            {
                INativeList <byte> nlb = (INativeList <byte>)utf8BytesMessage;
                unsafe
                {
                    result.Append(utf8BytesMessage.GetUnsafePtr(), nlb.Length);
                }
            }
            else
            {
                result.Append("[type not supported]");
            }

            return(result);
        }