private ObjectWriter(Context ctx, JsonEncodeOptions encodeOptions, RuntimeTypeHandle caller) { Debug.Assert(ctx != null); _ctx = ctx; _encodeOptions = encodeOptions; _caller = caller; }
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)); }
/// <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)); }
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(); }
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; }
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)); }
public static PhpString json_encode(Context ctx, PhpValue value, JsonEncodeOptions options = JsonEncodeOptions.Default) { return(new PhpSerialization.JsonSerializer(encodeOptions: options).Serialize(ctx, value, default)); }
public JsonSerializer(DecodeOptions decodeOptions = null, JsonEncodeOptions encodeOptions = JsonEncodeOptions.Default) { _decodeOptions = decodeOptions; _encodeOptions = encodeOptions; }