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
class AsdfSerdeException: mir.serde.SerdeException;
Serde Exception
size_t location;
zero based faulty location
pure nothrow @nogc @safe this(string msg, size_t location, string file = __FILE__, size_t line = __LINE__);
pure nothrow @nogc @safe this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null);
pure nothrow @nogc @safe this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__);
class InvalidAsdfException: mir.serde.SerdeException;
pure nothrow @safe this(uint kind, string file = __FILE__, size_t line = __LINE__, Throwable next = null);
pure nothrow @safe this(uint kind, Throwable next, string file = __FILE__, size_t line = __LINE__);
class EmptyAsdfException: mir.serde.SerdeException;
pure nothrow @nogc @safe this(string msg = "ASDF value is empty", string file = __FILE__, size_t line = __LINE__, Throwable next = null);
struct Asdf;
The structure for ASDF manipulation.
enum Kind: ubyte;
null_
true_
false_
number
string
array
object
const pure @nogc @safe ubyte kind();
Returns ASDF Kind
ubyte[] data;
Plain ASDF data.
pure nothrow @nogc @safe this(ubyte[] data);
Creates ASDF using already allocated data
pure @safe this(in char[] str);
Creates ASDF from a string
Examples:
assert(Asdf("string") == "string");
assert(Asdf("string") != "String");
pure nothrow @nogc @safe void remove();
Sets deleted bit on
Examples:
import mir.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":{}}}`);
const void toString(Dg)(scope Dg sink);
const pure nothrow @nogc @safe bool opEquals(in Asdf rhs);
== operator overloads for null
Examples:
import asdf.jsonparser;
auto asdfData = `null`.parseJson;
assert(asdfData == asdfData);
const pure nothrow @safe bool opEquals(typeof(null));
== operator overloads for null
Examples:
import asdf.jsonparser;
auto asdfData = `null`.parseJson;
assert(asdfData == null);
const pure nothrow @safe bool opEquals(bool boolean);
== operator overloads for bool
Examples:
import asdf.jsonparser;
auto asdfData = `true`.parseJson;
assert(asdfData == true);
assert(asdfData != false);
const pure nothrow @trusted bool opEquals(in char[] str);
== operator overloads for string
Examples:
import asdf.jsonparser;
auto asdfData = `"str"`.parseJson;
assert(asdfData == "str");
assert(asdfData != "stR");
pure auto byElement();
Returns:
input range composed of elements of an array.
pure auto byKeyValue();
Returns:
Input range composed of key-value pairs of an object. Elements are type of Tuple!(const(char)[], "key", Asdf, "value").
pure Asdf opIndex(in char[][] keys...);
Searches for 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);
T get(T)(T def);
Parameters:
T def default value. It is used when ASDF value equals 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);
T opCast(T)();
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(123456), UTC())); // UTC time zone is used.