// File: /workspace/github_cpp_makefile_star2_O1/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 0x3c97(%rip), %r12      # 0x60c4
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 0x2982
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x288b
testl %ecx, %ecx
jne 0x2814
leaq 0x3c25(%rip), %rsi      # 0x60c8
leaq 0x80(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x2814
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x24ca
callq 0x20f0
leaq 0x80(%rsp), %rsi
movq $0x1, (%rsi)
movq %r12, 0x8(%rsi)
leaq 0x3c7f(%rip), %rax      # 0x6163
movq %rax, 0x10(%rsi)
movl $0x17, 0x18(%rsi)
leaq 0x3c60(%rip), %rax      # 0x6156
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 0x3306
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x28a2
testl %ecx, %ecx
jne 0x2833
leaq 0x3c19(%rip), %rsi      # 0x6165
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x2050
testl %eax, %eax
jne 0x2833
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2570
callq 0x20f0
movups 0x4863(%rip), %xmm0     # 0x6dda
leaq 0x4a(%rsp), %rcx
movups %xmm0, -0x10(%rcx)
movaps 0x4849(%rip), %xmm0     # 0x6dd0
movaps %xmm0, -0x1a(%rcx)
movaps 0x482e(%rip), %xmm0     # 0x6dc0
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)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x7624(%rip), %rsi      # 0x9c08
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x3776
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x2852
testl %ecx, %ecx
jne 0x28c1
cmpq $0x1, 0x88(%rsp)
jne 0x28c1
cmpl $0x13, 0x90(%rsp)
jne 0x28c1
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x263b
callq 0x20f0
leaq 0x47ae(%rip), %rsi      # 0x6df0
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)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x131(%rsp), %r15
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x755e(%rip), %rsi      # 0x9c08
leaq 0x20(%rsp), %rdi
movq %r15, %rcx
callq 0x3776
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x2852
testl %ecx, %ecx
jne 0x286c
cmpq $0x1, 0x28(%rsp)
jne 0x286c
cmpl $0x2a, 0x38(%rsp)
jne 0x286c
leaq 0x40(%rsp), %rdi
leaq 0x3b2b(%rip), %rsi      # 0x621d
callq 0x2050
testl %eax, %eax
jne 0x286c
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x270e
callq 0x20f0
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %r13
movups %xmm0, -0x38(%r13)
movups %xmm0, -0x28(%r13)
movups %xmm0, -0x18(%r13)
movups %xmm0, -0x8(%r13)
xorl %eax, %eax
movq %rax, 0x8(%r13)
movaps %xmm0, -0x50(%r13)
movl %eax, -0x40(%r13)
movq %r12, -0x30(%r13)
movq %rax, -0x28(%r13)
movb %al, -0x20(%r13)
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x18(%rsp), %rdx
movq %r14, (%rdx)
movq %rsp, %r8
movl %eax, (%r8)
movq %rbx, 0x8(%r8)
leaq 0x75ae(%rip), %rsi      # 0x9d18
leaq 0x20(%rsp), %rdi
movq %r15, %rcx
callq 0x5290
movl (%rsp), %ecx
testl %ecx, %ecx
setne %dl
xorb %dl, %al
je 0x28e0
testl %ecx, %ecx
jne 0x27f5
cmpq $0x1, 0x28(%rsp)
jne 0x27f5
cmpl $0x2a, 0x38(%rsp)
jne 0x27f5
leaq 0x40(%rsp), %rdi
leaq 0x3a77(%rip), %rsi      # 0x621d
callq 0x2050
testl %eax, %eax
jne 0x27f5
leaq 0x60(%rsp), %rdi
leaq 0x3ac3(%rip), %rsi      # 0x627e
callq 0x2050
testl %eax, %eax
jne 0x27f5
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x27d3
callq 0x20f0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x27e2
callq 0x20f0
xorl %eax, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x3aaa(%rip), %rdi      # 0x62a6
leaq 0x3948(%rip), %rsi      # 0x614b
leaq 0x394e(%rip), %rcx      # 0x6158
movl $0x98, %edx
callq 0x20a0
leaq 0x38e6(%rip), %rdi      # 0x6101
leaq 0x3929(%rip), %rsi      # 0x614b
leaq 0x392f(%rip), %rcx      # 0x6158
movl $0x73, %edx
callq 0x20a0
leaq 0x396c(%rip), %rdi      # 0x61a6
leaq 0x390a(%rip), %rsi      # 0x614b
leaq 0x3910(%rip), %rcx      # 0x6158
movl $0x79, %edx
callq 0x20a0
leaq 0x3ade(%rip), %rdi      # 0x6337
leaq 0x3ae4(%rip), %rsi      # 0x6344
leaq 0x4185(%rip), %rcx      # 0x69ec
jmp 0x28f5
leaq 0x39b9(%rip), %rdi      # 0x622c
leaq 0x38d1(%rip), %rsi      # 0x614b
leaq 0x38d7(%rip), %rcx      # 0x6158
movl $0x8e, %edx
callq 0x20a0
leaq 0x3aa5(%rip), %rdi      # 0x6337
leaq 0x3aab(%rip), %rsi      # 0x6344
leaq 0x3ab9(%rip), %rcx      # 0x6359
jmp 0x28b7
leaq 0x3a8e(%rip), %rdi      # 0x6337
leaq 0x3a94(%rip), %rsi      # 0x6344
leaq 0x3f21(%rip), %rcx      # 0x67d8
movl $0xe6, %edx
callq 0x20a0
leaq 0x3930(%rip), %rdi      # 0x61f8
leaq 0x387c(%rip), %rsi      # 0x614b
leaq 0x3882(%rip), %rcx      # 0x6158
movl $0x7f, %edx
callq 0x20a0
leaq 0x3a50(%rip), %rdi      # 0x6337
leaq 0x3a56(%rip), %rsi      # 0x6344
leaq 0x4414(%rip), %rcx      # 0x6d09
movl $0xbd, %edx
callq 0x20a0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2956
jmp 0x293c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
jne 0x2937
jmp 0x293c
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
jmp 0x2932
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x293c
callq 0x20f0
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
jne 0x2937
jmp 0x293c