public static Body read()

in accord-maelstrom/src/main/java/accord/maelstrom/Body.java [103:180]


    public static Body read(JsonReader in, Id from) throws IOException
    {
        Type type = null;
        long msg_id = 0, in_reply_to = 0;
        int code = -1;
        String text = null;
        Txn txn = null;
        MaelstromResult txn_ok = null;
        Object body = null;
        Id node_id = null;
        List<Id> node_ids = null;
        String deferredTxn = null;

        in.beginObject();
        while (in.hasNext())
        {
            String field = in.nextName();
            switch (field)
            {
                case "type":
                    String v = in.nextString();
                    type = Type.valueOf(v);
                    break;
                case "msg_id":
                    msg_id = in.nextLong();
                    break;
                case "in_reply_to":
                    in_reply_to = in.nextLong();
                    break;
                case "code":
                    code = in.nextInt();
                    break;
                case "text":
                    text = in.nextString();
                    break;
                case "body":
                    body = Json.GSON.fromJson(in, type.type);
                    break;
                case "txn":
                    if (from == null)
                        throw new IllegalStateException();
                    if (msg_id == 0 || type == null) deferredTxn = Json.GSON.fromJson(in, JsonArray.class).toString();
                    else if (type == Type.txn) txn = MaelstromRequest.readTxnExternal(in, from, msg_id);
                    else txn_ok = MaelstromReply.readResultExternal(in, from, msg_id);
                    break;
                case "node_id":
                    node_id = Json.ID_ADAPTER.read(in);
                    break;
                case "node_ids":
                    node_ids = new ArrayList<>();
                    in.beginArray();
                    while (in.hasNext())
                        node_ids.add(Json.ID_ADAPTER.read(in));
                    in.endArray();
                    break;
                default:
                    throw illegalState("Unexpected field " + field);
            }
        }
        in.endObject();

        if (deferredTxn != null)
        {
            JsonReader in2 = new JsonReader(new StringReader(deferredTxn));
            if (type == Type.txn) txn = MaelstromRequest.readTxnExternal(in2, from, msg_id);
            else txn_ok = MaelstromReply.readResultExternal(in2, from, msg_id);
        }

        switch (type)
        {
            case init: return new MaelstromInit(msg_id, node_id, toArray(node_ids, Id[]::new));
            case init_ok: return new Body(Type.init_ok, msg_id, in_reply_to);
            case txn: return new MaelstromRequest(msg_id, txn);
            case txn_ok: return new MaelstromReply(in_reply_to, txn_ok);
            case error: return new Error(in_reply_to, code, text);
            default: return new Wrapper(type, msg_id, in_reply_to, body);
        }
    }