Giter Club home page Giter Club logo

asdf's People

Contributors

0xeab avatar 9il avatar ahmetsait avatar andrewlalis avatar atilaneves avatar bausshf avatar drug007 avatar john-colvin avatar lunathefoxgirl avatar n8sh avatar notspooky avatar simdnyan avatar yannick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asdf's Issues

Error location in JSON

How could I determine the position in the JSON string where ASDF deserialisation fails?

asdf has compatible JSONValue?

#include "simdjson.h"

int main(void) {
  simdjson::dom::parser parser;
  simdjson::dom::element tweets = parser.load("twitter.json");
  std::cout << tweets["search_metadata"]["count"] << " results." << std::endl;
}

So asdf code:

tweets["search_metadata", "count"];

JSONValue code:

tweets["search_metadata"]["count"].get!uint;

How to implement a proxy for array of SumType

I tried to write the following code, but I could not figure out how to implement the Proxy.
Does anyone have any good ideas?

code:

import sumtype;

struct ObjectA {
    string name;
}
struct ObjectB {
    double value;
}
alias MyObject = SumType!(ObjectA, ObjectB);

struct SomeObject {
    @serdeProxy!MyObjectArrayProxy MyObject[] objects;
}

struct MyObjectArrayProxy {
    // ?
}

data:

{
  "objects": [
    { "name": "test" },
    { "value": 1.5 }
  ]
}

I am trying to implement a configuration file with a strict type.

How to implement a "before/after" diff of a json file

I want to find the difference between two json files of unknown structure, showing which entries have been added, changed and removed.

asdf.transform.AsdfNode has added and removed and that's part of the way to doing this, but actually not very convenient. Obviously I can write code to walk the AsdfNode tree by hand, but it seems like AsdfNode should be more helpful here as it's a common class of tasks

fails to build

    Building asdf 0.7.17: building configuration [library]
../../../.dub/packages/asdf/0.7.17/asdf/source/asdf/asdf.d(76,37): Error: function `const pure nothrow @nogc @trusted AsdfSerdeException asdf.asdf.AsdfSerdeException.toMutable()` does not override any function, did you mean to override `const pure nothrow @nogc scope @trusted mir.serde.SerdeException mir.serde.SerdeException.toMutable() return`?
Error /usr/bin/dmd failed with exit code 1.

[feature request] serde(rename_all) for enums

In Rust the serde macro can rename all enum members, for example:

#[serde(rename_all = "UPPERCASE")]
pub enum LoginType {
    Web = 0,
    Mobile = 1,
}

The D workaround for this is to use serdeKeys:

enum LoginType {
    @serdeKeys("WEB") Web,
    @serdeKeys("MOBILE") Mobile,
}

But would it be possible to add something similar in D that affects all the enum members? E.g.:

@serdeRenamed(Uppercase)
enum LoginType {
    Web,
    Mobile,
}

The exact syntax isn't that important to me.

0.5 => 0.6 is a breaking change, can you add to doc & some explanation?

Hi,

Just noted the change from 0.5.x serializedXxx => 0.6.x serdeXxx, e.g.

@serializedAs => @serdeProxy

What's the reason for this kind of change? IMO, serialized is much readable English than serde.

I googled a bit, and only find: https://github.com/serde-rs/serde

But I suppose this code base is a clean D implementation, and has nothing to do with that Rust package.

So why? If it's really needed, can you also add to the doc, e.g. also the release tag for the explanation.

Thanks.

Problems with building in '--combined' mode

If I add asdf to the empty dub project and run 'dub build' - it builds fine. But when I use 'dub build --combined' it gives me errors:

.dub/packages/mir-core-1.3.15/mir-core/source/mir/algebraic.d(1473,36): Error: pure function mir.algebraic.Algebraic!opEquals!().opEquals cannot call impure function mir.annotated.U!(Algebraic!(Ion_)).Annotated.opEquals
.dub/packages/mir-core-1.3.15/mir-core/source/mir/algebraic.d(1473,36): Error: @nogc function mir.algebraic.Algebraic!opEquals!().opEquals cannot call non-@nogc function mir.annotated.U!(Algebraic!(Ion_)).Annotated.opEquals
.dub/packages/mir-core-1.3.15/mir-core/source/mir/algebraic.d(1473,36): Error: function mir.annotated.U!(Algebraic!.opEquals is not nothrow
.dub/packages/mir-core-1.3.15/mir-core/source/mir/algebraic.d(1428,10): Error: function mir.algebraic.Algebraic!(Ion_).s!().opEquals may throw but is marked as nothrow
.dub/packages/mir-algorithm-3.18.4/mir-algorithm/source/mir/annotated.d(69,54): Error: template instance mir.algebraic.Algebraic.opEquals!() error instantiating
.dub/packages/mir-core-1.3.15/mir-core/source/mir/internal/meta.d(411,39): instantiated from here: U!(Algebraic!.dub/packages/mir-core-1.3.15/mir-core/source/mir/algebraic.d(857,36): 12 recursive instantiations from here: s!(isVariant, This, Algebraic!(Ion_), typeof(null), bool, long, double, string, Blob, Clob, Timestamp, This[], StringMap!!(This))
.dub/packages/mir-algorithm-3.18.4/mir-algorithm/source/mir/algebraic_alias/ion.d(60,22): instantiated from here: Algebraic!(Ion_)

Is it possible to fix that? So we can use asdf in '--combined' build?

Deserealizing struct with immutable members using proxy yields default values

Problem: the following code produces default values on deserialization in Name structure
Expected: actual values from json in Name structure

Could be a compiler bug, no idea.
Compilers: DMD 2.098, LDC 1.28.0-beta1 (2.098 backend)

@serdeProxy!string
struct Name
{
        // immutable causes asdf to silently swallow error "can't assign 'this' in struct with immutable members"
        // comment out 'immutable' to make it work as expected
        immutable string godot;
        immutable string d;

        this(string godotName)
        {
                godot = godotName;
                d = godotName.dTypeName;
        }
}
struct Constant
{
        Name name; // <- BUG: will be default initialized instead of expected values
        int value;
}
struct Enum
{
        string name;
        Constant[] values;
}

Enum e = json.deserialize!(Enum);

test.json:

{
  "name": "Mode",
  "values": [
      {
        "name": "MODE_ECB_ENCRYPT",
        "value": 0
      },
  ]
}

Now however if I use this Constant instead I got compile error

struct Constant
{
        Name name; // case
        int value;

        SerdeException deserializeFromAsdf(Asdf data)
        {
            string val;
            if (auto exc = deserializeScopedString(data, val))
                return exc;
            // Error: cannot modify struct instance `this` of type `Constant` because it contains `const` or `immutable` members
            this = Constant(Name(val), 0 );
            return null;
        }
}

Deserialize an array with different element types

I have the following json node (jvm):

{
    "jvm":[
        {
            "rules":[
               {
                    "action":"allow",
                    "os":{
                        "arch":"x86"
                    }
               }
            ],
            "value":"-Xss1M"
        },
         "-Djava.library.path=${natives_directory}"
    ]
}

Here the node elements can be either a string or an object.
How do I deserialize this node?
I tried something like:

import std.sumtype;
import asdf;

struct Jvm { 
    SumType!(JvmArgument, string) data;
    alias data this;

    SerdeException deserializeFromAsdf(Asdf data) { 
        string val;
        if (auto exc = deserializeScopedString(data, val))
            return exc;

        this = ???

        return null; 
    }
}

struct JvmArgument {
    @serdeKeys("rules")
    Rule[] rule;
    @serdeKeys("value")
    string[] value;
}

struct Rule{
    @serdeKeys("action") 
    string action;
    @serdeKeys("os")
    @serdeOptional
    Os os;
}

I don't understand how to fill in "this" in this case.
Do you have any ideas?

Cannot serialize Duration

Hi,
asdf fails to serialize a struct with phobos Duration in it:

/+dub.sdl:
dependency "asdf" version="~>0.5.7"
+/
import std.stdio;
import std.datetime;
import asdf;
void main()
{
    A a;
    string json = serializeToJsonPretty(a); // never ends
    writeln("json length ", json.length);
}

struct A
{
    Duration dur;
}

This errors with an OOM exception in the appender. Somehow in writes never-ending zero": { strings to it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.