예제 #1
0
 private ObjectWriter(Context ctx, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller)
 {
     Debug.Assert(ctx != null);
     _ctx           = ctx;
     _encodeOptions = encodeOptions;
     _caller        = caller;
 }
예제 #2
0
                public static PhpString Serialize(Context ctx, PhpValue variable, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller)
                {
                    ObjectWriter writer;

                    variable.Accept(writer = new ObjectWriter(ctx, encodeOptions, caller));
                    return(new PhpString(writer._result));
                }
예제 #3
0
        /// <summary>
        /// Returns the JSON representation of a value.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="value">The value being encoded. Can be any type except a <see cref="PhpResource"/>.
        /// All string data must be UTF-8 encoded.</param>
        /// <param name="options"></param>
        /// <param name="depth">Set the maximum depth. Must be greater than zero.</param>
        public static string json_encode(Context ctx, PhpValue value, JsonEncodeOptions options = JsonEncodeOptions.Default, int depth = 512)
        {
            // TODO: depth

            //return new PhpSerialization.JsonSerializer(encodeOptions: options).Serialize(ctx, value, default);
            return(PhpSerialization.JsonSerializer.ObjectWriter.Serialize(ctx, value, options, default));
        }
예제 #4
0
                public static string Serialize(Context ctx, PhpValue variable, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller)
                {
                    var str = StringBuilderUtilities.Pool.Get();

                    variable.Accept(new ObjectWriter(ctx, str, encodeOptions, caller));

                    return(StringBuilderUtilities.GetStringAndReturn(str)); // note: str is cleared
                }
 private ObjectWriter(Context ctx, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller)
 {
     Debug.Assert(ctx != null);
     _ctx           = ctx;
     _encodeOptions = encodeOptions;
     _caller        = caller;
     _pretty        = HasPrettyPrint ? (IPrettyPrinter) new PrettyPrintOn(_result) : new PrettyPrintOff();
 }
예제 #6
0
 private ObjectWriter(Context ctx, StringBuilder result, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller)
 {
     Debug.Assert(ctx != null);
     _ctx           = ctx;
     _encodeOptions = encodeOptions;
     _result        = result ?? throw new ArgumentNullException(nameof(result));
     //_caller = caller;
     _pretty = HasPrettyPrint ? (IPrettyPrinter) new PrettyPrintOn(_result) : PrettyPrintOff.Instance;
 }
예제 #7
0
파일: PhpJson.cs 프로젝트: jiahao42/weverca
 public static PhpBytes Serialize(object value, JsonEncodeOptions options)
 {
     return(new PhpJsonSerializer(
                new JsonFormatter.EncodeOptions()
     {
         ForceObject = (options & JsonEncodeOptions.JSON_FORCE_OBJECT) != 0,
         HexAmp = (options & JsonEncodeOptions.JSON_HEX_AMP) != 0,
         HexApos = (options & JsonEncodeOptions.JSON_HEX_APOS) != 0,
         HexQuot = (options & JsonEncodeOptions.JSON_HEX_QUOT) != 0,
         HexTag = (options & JsonEncodeOptions.JSON_HEX_TAG) != 0,
         NumericCheck = (options & JsonEncodeOptions.JSON_NUMERIC_CHECK) != 0,
     },
                new JsonFormatter.DecodeOptions()
                ).Serialize(value, UnknownTypeDesc.Singleton));
 }
예제 #8
0
 public static PhpString json_encode(Context ctx, PhpValue value, JsonEncodeOptions options = JsonEncodeOptions.Default)
 {
     return(new PhpSerialization.JsonSerializer(encodeOptions: options).Serialize(ctx, value, default));
 }
예제 #9
0
 public JsonSerializer(DecodeOptions decodeOptions = null, JsonEncodeOptions encodeOptions = JsonEncodeOptions.Default)
 {
     _decodeOptions = decodeOptions;
     _encodeOptions = encodeOptions;
 }