// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x140, %rsp            # imm = 0x140
leaq 0x20(%rsp), %rdx
movq $0x1, (%rdx)
leaq 0x3f3d(%rip), %r14      # 0x61f8
movq %r14, 0x8(%rdx)
movabsq $0x2a00000017, %rax     # imm = 0x2A00000017
movq %rax, 0x10(%rdx)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x26a8
cmpl $0x0, 0x8(%rsp)
jne 0x2598
leaq 0x3ef7(%rip), %rsi      # 0x61fc
leaq 0x80(%rsp), %rdi
callq 0x2676
testb %al, %al
je 0x2598
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x20c0
movq $0x1, (%rbx)
movq %r14, 0x8(%rbx)
leaq 0x3f5b(%rip), %rax      # 0x6297
movq %rax, 0x10(%rbx)
movl $0x17, 0x18(%rbx)
leaq 0x3f3c(%rip), %rax      # 0x628a
movq %rax, 0x20(%rbx)
movl $0x2a, 0x28(%rbx)
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x33b4
cmpl $0x0, 0x8(%rsp)
jne 0x25b1
leaq 0x3f06(%rip), %rsi      # 0x6299
leaq 0x20(%rsp), %rdi
callq 0x2676
testb %al, %al
je 0x25b1
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x20c0
movups 0x5121(%rip), %xmm0     # 0x74da
movups %xmm0, 0x1a(%rbx)
movaps 0x510c(%rip), %xmm0     # 0x74d0
movaps %xmm0, 0x10(%rbx)
movaps 0x50f1(%rip), %xmm0     # 0x74c0
movaps %xmm0, (%rbx)
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rbx
movups %xmm0, -0x8(%rbx)
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
leaq 0xb0(%rsp), %rax
movaps %xmm0, -0x30(%rax)
andl $0x0, -0x20(%rax)
movq %rax, -0x10(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3a1d
cmpl $0x0, 0x8(%rsp)
jne 0x25e9
cmpq $0x1, 0x88(%rsp)
jne 0x25e9
cmpl $0x13, 0x90(%rsp)
jne 0x25e9
movq %rbx, %rdi
callq 0x20c0
leaq 0x50a5(%rip), %rsi      # 0x74f0
leaq 0x80(%rsp), %r14
movl $0xb1, %edx
movq %r14, %rdi
callq 0x2110
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rbx
movups %xmm0, -0x8(%rbx)
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
leaq 0x50(%rsp), %r15
movaps %xmm0, -0x30(%r15)
andl $0x0, -0x20(%r15)
movq %r15, -0x10(%r15)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x5512
cmpl $0x0, 0x8(%rsp)
jne 0x25ca
cmpq $0x1, 0x28(%rsp)
jne 0x25ca
cmpl $0x2a, 0x38(%rsp)
jne 0x25ca
leaq 0x3e8f(%rip), %rsi      # 0x6351
movq %rbx, %rdi
callq 0x2676
testb %al, %al
je 0x25ca
movq %rbx, %rdi
callq 0x20c0
leaq 0x38(%rsp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x30(%rbx)
andq $0x0, 0x40(%rbx)
movups %xmm0, 0x10(%rbx)
andl $0x0, -0x8(%rbx)
movaps %xmm0, -0x18(%rbx)
movq %r15, 0x8(%rbx)
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x5548
cmpl $0x0, 0x8(%rsp)
jne 0x2579
cmpq $0x1, 0x28(%rsp)
jne 0x2579
cmpl $0x2a, 0x38(%rsp)
jne 0x2579
leaq 0x40(%rsp), %rdi
leaq 0x3e0d(%rip), %rsi      # 0x6351
callq 0x2676
testb %al, %al
je 0x2579
leaq 0x60(%rsp), %rdi
leaq 0x3e59(%rip), %rsi      # 0x63b2
callq 0x2676
testb %al, %al
je 0x2579
movq %rbx, %rdi
callq 0x268e
xorl %eax, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3e5a(%rip), %rdi      # 0x63da
leaq 0x3cf8(%rip), %rsi      # 0x627f
leaq 0x3cfe(%rip), %rcx      # 0x628c
movl $0x98, %edx
callq 0x2100
leaq 0x3c96(%rip), %rdi      # 0x6235
leaq 0x3cd9(%rip), %rsi      # 0x627f
leaq 0x3cdf(%rip), %rcx      # 0x628c
pushq $0x73
jmp 0x2600
leaq 0x3d22(%rip), %rdi      # 0x62da
leaq 0x3cc0(%rip), %rsi      # 0x627f
leaq 0x3cc6(%rip), %rcx      # 0x628c
pushq $0x79
jmp 0x2600
leaq 0x3d8f(%rip), %rdi      # 0x6360
leaq 0x3ca7(%rip), %rsi      # 0x627f
leaq 0x3cad(%rip), %rcx      # 0x628c
movl $0x8e, %edx
callq 0x2100
leaq 0x3d3c(%rip), %rdi      # 0x632c
leaq 0x3c88(%rip), %rsi      # 0x627f
leaq 0x3c8e(%rip), %rcx      # 0x628c
pushq $0x7f
popq %rdx
callq 0x2100
movq %rax, %r14
movq %rbx, %rdi
callq 0x268e
jmp 0x2637
jmp 0x2615
movq %rax, %r14
movq %rbx, %rdi
jmp 0x2632
movq %rax, %r14
leaq 0x20(%rsp), %rdi
jmp 0x2632
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x2180