// File: /workspace/github_cpp_makefile_star2_O3/oknenavin[P]cxon/examples/json-rpc.cxx
// Function: main
int main() {
    using namespace cxon;
    {   // params array
        auto const call = jsonrpc::make_request(1, "sub", 42, 23);
        std::string req; // serialize call to req
            auto const w = to_bytes(req, call);
        assert(w && req == R"({"jsonrpc":"2.0","id":1,"method":"sub","params":[42,23]})");
    }
    {   // params object
        auto const call = jsonrpc::make_request(1, "sub", jsonrpc::make_napa("x", 42), jsonrpc::make_napa("y", 23));
        std::string req; // serialize call to req
            auto const w = to_bytes(req, call);
        assert(w && req == R"({"jsonrpc":"2.0","id":1,"method":"sub","params":{"x":42,"y":23}})");
    }
    {   // round-trip: req -> res success
        char const res[] = R"({"jsonrpc": "2.0", "result": 19, "id": 1})";
        jsonrpc::response<int> ret; // serialize res to ret
            auto const r = from_bytes(ret, res);
        assert(r && ret.id == 1 && ret.result == 19);
    }
    {   // round-trip: req -> res failure
        char const res[] = R"({
            "jsonrpc": "2.0",
            "error": {"code": 42, "message": "divide by zero", "data": "a black hole has been created somewhere"},
            "id": 1
        })";
        {   // serialize res to ret, error's data will be skipped
            jsonrpc::response<int> ret;
                auto const r = from_bytes(ret, res);
            assert( r &&
                    ret.id == 1 &&
                    ret.error.code == 42 &&
                    ret.error.message == "divide by zero"
            );
        }
        {   // serialize res to ret, error's data is bound to std::string
            jsonrpc::response<int, std::string> ret;
                auto const r = from_bytes(ret, res);
            assert( r &&
                    ret.id == 1 &&
                    ret.error.code == 42 &&
                    ret.error.message == "divide by zero" &&
                    ret.error.data == "a black hole has been created somewhere"
            );
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rsp, %r14
movq $0x1, (%r14)
leaq 0x3c77(%rip), %r12      # 0x60a4
movq %r12, 0x8(%r14)
movabsq $0x2a00000017, %rax     # imm = 0x2A00000017
movq %rax, 0x10(%r14)
leaq 0x90(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x20(%rsp), %r15
movl $0x0, (%r15)
callq 0x2080
movq %rax, %rbx
movq %rax, 0x8(%r15)
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x295c
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x2865
testl %ecx, %ecx
jne 0x27ee
leaq 0x3c05(%rip), %rsi      # 0x60a8
leaq 0x80(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x27ee
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x24ca
callq 0x20f0
leaq 0x80(%rsp), %rsi
movq $0x1, (%rsi)
movq %r12, 0x8(%rsi)
leaq 0x3c5f(%rip), %rax      # 0x6143
movq %rax, 0x10(%rsi)
movl $0x17, 0x18(%rsi)
leaq 0x3c40(%rip), %rax      # 0x6136
movq %rax, 0x20(%rsi)
movl $0x2a, 0x28(%rsi)
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq %rsp, %rdx
movl $0x0, (%rdx)
movq %rbx, 0x8(%rdx)
leaq 0x20(%rsp), %rdi
callq 0x328a
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x287c
testl %ecx, %ecx
jne 0x280d
leaq 0x3bf9(%rip), %rsi      # 0x6145
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x2050
testl %eax, %eax
jne 0x280d
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2570
callq 0x20f0
movups 0x4843(%rip), %xmm0     # 0x6dba
leaq 0x4a(%rsp), %rcx
movups %xmm0, -0x10(%rcx)
movaps 0x4829(%rip), %xmm0     # 0x6db0
movaps %xmm0, -0x1a(%rcx)
movaps 0x480e(%rip), %xmm0     # 0x6da0
movaps %xmm0, -0x2a(%rcx)
xorps %xmm0, %xmm0
leaq 0xb0(%rsp), %r15
movups %xmm0, -0x18(%r15)
movups %xmm0, 0x8(%r15)
movups %xmm0, -0x8(%r15)
movaps %xmm0, -0x30(%r15)
xorl %eax, %eax
movl %eax, -0x20(%r15)
movq %r15, -0x10(%r15)
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x7630(%rip), %rsi      # 0x9c08
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x3704
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x282c
testl %ecx, %ecx
jne 0x289b
cmpq $0x1, 0x88(%rsp)
jne 0x289b
cmpl $0x13, 0x90(%rsp)
jne 0x289b
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x262f
callq 0x20f0
leaq 0x479a(%rip), %rsi      # 0x6dd0
movl $0xb1, %edx
movq %r14, %rdi
callq 0x20c0
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %r12
movups %xmm0, -0x18(%r12)
movups %xmm0, 0x8(%r12)
movups %xmm0, -0x8(%r12)
movaps %xmm0, -0x30(%r12)
xorl %eax, %eax
movl %eax, -0x20(%r12)
movq %r12, -0x10(%r12)
leaq 0x131(%rsp), %r15
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x7578(%rip), %rsi      # 0x9c08
leaq 0x20(%rsp), %rdi
movq %r15, %rcx
callq 0x3704
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x282c
testl %ecx, %ecx
jne 0x2846
cmpq $0x1, 0x28(%rsp)
jne 0x2846
cmpl $0x2a, 0x38(%rsp)
jne 0x2846
leaq 0x40(%rsp), %rdi
leaq 0x3b25(%rip), %rsi      # 0x61fd
callq 0x2050
testl %eax, %eax
jne 0x2846
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x26f4
callq 0x20f0
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %r13
movups %xmm0, -0x38(%r13)
movups %xmm0, -0x18(%r13)
movups %xmm0, -0x8(%r13)
movups %xmm0, -0x28(%r13)
movq $0x0, 0x8(%r13)
movaps %xmm0, -0x50(%r13)
xorl %eax, %eax
movl %eax, -0x40(%r13)
movq %r12, -0x30(%r13)
movq %r13, -0x10(%r13)
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x75d4(%rip), %rsi      # 0x9d18
leaq 0x20(%rsp), %rdi
movq %r15, %rcx
callq 0x4f5e
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x28ba
testl %ecx, %ecx
jne 0x27cf
cmpq $0x1, 0x28(%rsp)
jne 0x27cf
cmpl $0x2a, 0x38(%rsp)
jne 0x27cf
leaq 0x40(%rsp), %rdi
leaq 0x3a7d(%rip), %rsi      # 0x61fd
callq 0x2050
testl %eax, %eax
jne 0x27cf
leaq 0x60(%rsp), %rdi
leaq 0x3ac9(%rip), %rsi      # 0x625e
callq 0x2050
testl %eax, %eax
jne 0x27cf
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x27ad
callq 0x20f0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x27bc
callq 0x20f0
xorl %eax, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x3ab0(%rip), %rdi      # 0x6286
leaq 0x394e(%rip), %rsi      # 0x612b
leaq 0x3954(%rip), %rcx      # 0x6138
movl $0x98, %edx
callq 0x20a0
leaq 0x38ec(%rip), %rdi      # 0x60e1
leaq 0x392f(%rip), %rsi      # 0x612b
leaq 0x3935(%rip), %rcx      # 0x6138
movl $0x73, %edx
callq 0x20a0
leaq 0x3972(%rip), %rdi      # 0x6186
leaq 0x3910(%rip), %rsi      # 0x612b
leaq 0x3916(%rip), %rcx      # 0x6138
movl $0x79, %edx
callq 0x20a0
leaq 0x3ae4(%rip), %rdi      # 0x6317
leaq 0x3aea(%rip), %rsi      # 0x6324
leaq 0x418b(%rip), %rcx      # 0x69cc
jmp 0x28cf
leaq 0x39bf(%rip), %rdi      # 0x620c
leaq 0x38d7(%rip), %rsi      # 0x612b
leaq 0x38dd(%rip), %rcx      # 0x6138
movl $0x8e, %edx
callq 0x20a0
leaq 0x3aab(%rip), %rdi      # 0x6317
leaq 0x3ab1(%rip), %rsi      # 0x6324
leaq 0x3abf(%rip), %rcx      # 0x6339
jmp 0x2891
leaq 0x3a94(%rip), %rdi      # 0x6317
leaq 0x3a9a(%rip), %rsi      # 0x6324
leaq 0x3f27(%rip), %rcx      # 0x67b8
movl $0xe6, %edx
callq 0x20a0
leaq 0x3936(%rip), %rdi      # 0x61d8
leaq 0x3882(%rip), %rsi      # 0x612b
leaq 0x3888(%rip), %rcx      # 0x6138
movl $0x7f, %edx
callq 0x20a0
leaq 0x3a56(%rip), %rdi      # 0x6317
leaq 0x3a5c(%rip), %rsi      # 0x6324
leaq 0x441a(%rip), %rcx      # 0x6ce9
movl $0xbd, %edx
callq 0x20a0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2930
jmp 0x2916
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
jne 0x2911
jmp 0x2916
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
jmp 0x290c
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2916
callq 0x20f0
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
jne 0x2911
jmp 0x2916