Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
asdf.asdf
ASDF Representation
Authors:
Ilya Yaroshenko
License:
MIT
The structure for ASDF manipulation.
Returns ASDF Kind
Creates ASDF using already allocated data
Creates ASDF from a string
Examples:
assert(Asdf("string") == "string"); assert(Asdf("string") != "String");
Sets deleted bit on
Examples:
import std.conv: to; import asdf.jsonparser; auto asdfData = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`.parseJson; asdfData["inner", "d"].remove; assert(asdfData.to!string == `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","e":{}}}`);
== operator overloads for null
Examples:
import asdf.jsonparser; auto asdfData = `null`.parseJson; assert(asdfData == asdfData);
== operator overloads for null
Examples:
import asdf.jsonparser; auto asdfData = `null`.parseJson; assert(asdfData == null);
== operator overloads for bool
Examples:
import asdf.jsonparser; auto asdfData = `true`.parseJson; assert(asdfData == true); assert(asdfData != false);
== operator overloads for string
Examples:
import asdf.jsonparser; auto asdfData = `"str"`.parseJson; assert(asdfData == "str"); assert(asdfData != "stR");
Returns:
input range composed of elements of an array.
Returns:
Input range composed of key-value pairs of an object.
Elements are type of Tuple!(const(char)[], "key", Asdf, "value").
Searches a value recursively in an ASDF object.
Parameters:
char[][] keys | list of keys keys Returns ASDF value if it was found (first win) or ASDF with empty plain data. |
Examples:
import asdf.jsonparser; auto asdfData = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`.parseJson; assert(asdfData["inner", "a"] == true); assert(asdfData["inner", "b"] == false); assert(asdfData["inner", "c"] == "32323"); assert(asdfData["inner", "d"] == null); assert(asdfData["no", "such", "keys"] == Asdf.init);
Parameters:
T def | default value. It is used when ASDF value equals to Asdf.init. |
Returns:
cast(T) this if this != Asdf.init and def otherwise.
Examples:
import asdf.jsonparser; auto asdfData = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`.parseJson; assert(asdfData["inner", "a"].get(false) == true); assert(asdfData["inner", "b"].get(true) == false); assert(asdfData["inner", "c"].get(100) == 32323); assert(asdfData["no", "such", "keys"].get(100) == 100);
cast operator overloading.
Examples:
null
import std.math; import asdf.serialization; auto null_ = serializeToAsdf(null); interface I {} class C {} assert(cast(uint[]) null_ is null); assert(cast(uint[uint]) null_ is null); assert(cast(I) null_ is null); assert(cast(C) null_ is null); assert(isNaN(cast(double) null_)); assert(! cast(bool) null_);
Examples:
boolean
import std.math; import asdf.serialization; auto true_ = serializeToAsdf(true); auto false_ = serializeToAsdf(false); static struct C { this(bool){} } auto a = cast(C) true_; auto b = cast(C) false_; assert(cast(bool) true_ == true); assert(cast(bool) false_ == false); assert(cast(uint) true_ == 1); assert(cast(uint) false_ == 0); assert(cast(double) true_ == 1); assert(cast(double) false_ == 0);
Examples:
numbers
import std.bigint; import asdf.serialization; auto number = serializeToAsdf(1234); auto zero = serializeToAsdf(0); static struct C { this(in char[] numberString) { assert(numberString == "1234"); } } auto a = cast(C) number; assert(cast(bool) number == true); assert(cast(bool) zero == false); assert(cast(uint) number == 1234); assert(cast(double) number == 1234); assert(cast(BigInt) number == 1234); assert(cast(uint) zero == 0); assert(cast(double) zero == 0); assert(cast(BigInt) zero == 0);
Examples:
string
import std.bigint; import asdf.serialization; auto number = serializeToAsdf("1234"); auto false_ = serializeToAsdf("false"); auto bar = serializeToAsdf("bar"); auto zero = serializeToAsdf("0"); static struct C { this(in char[] str) { assert(str == "1234"); } } auto a = cast(C) number; assert(cast(string) number == "1234"); assert(cast(bool) number == true); assert(cast(bool) bar == true); assert(cast(bool) zero == false); assert(cast(bool) false_ == false); assert(cast(uint) number == 1234); assert(cast(double) number == 1234); assert(cast(BigInt) number == 1234); assert(cast(uint) zero == 0); assert(cast(double) zero == 0); assert(cast(BigInt) zero == 0);
Examples:
For ASDF arrays and objects cast(T) just returns this.deserialize!T.
import std.bigint; import asdf.serialization; assert(cast(int[]) serializeToAsdf([100, 20]) == [100, 20]);
Examples:
UNIX Time
import std.datetime; import asdf.serialization; auto num = serializeToAsdf(0.123456789); // rounding up to usecs assert(cast(DateTime) num == DateTime(1970, 1, 1)); assert(cast(SysTime) num == SysTime(DateTime(1970, 1, 1), usecs(123457), UTC())); // UTC time zone is used.
Tamedia Digital, 2016
| Page generated by
Ddoc on Sat Apr 7 16:50:38 2018