// File: /workspace/github_cpp_makefile_star2_O1/Unreality3D[P]Unreality3D/indie-studio/source/Network/protocol/Deserializer.cpp
// Function: IndieProtocol::Deserializer::operator()(IndieProtocol::Serialized const&)
size_t	Deserializer::operator() (Serialized const &to_handle)
  {
    Serialized	tmp;

    if (!to_handle.size || !to_handle.data)
      return 0;

    std::cout << "old buffer : " << std::endl;
    std::cout << _buffer << std::endl;

    _buffer += to_handle;

    std::cout << "new buffer : " << std::endl;
    std::cout << _buffer << std::endl;

    if (!_isReading)
      {
	if (to_handle.size >= sizeof(Header))
	  {
	    // get the header data
	    _isReading = true;
	    memcpy(&_header, to_handle.data, sizeof(Header));
	  }
	else
	  return 0;
      }
    tmp = _buffer + sizeof(Header);

    // can read the whole packet
    if (tmp.size + sizeof(Header) >= _header.size)
      {
	size_t to_return = _header.size;
	switch (_header.messageType)
	  {
	  case PacketType::CONNECT:
	    deserializeConnect(tmp);
	    break;
	  case PacketType::LIST:
	    deserializeList(tmp);
	    break;
	  case PacketType::MESSAGE:
	    deserializeMessage(tmp);
	    break;
	  default: // error or not implemented
	    break;
	  }
	reset();
	return to_return;
      }
    return 0;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl $0x0, (%rsp)
movl $0x1, %edi
callq 0xb030
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r12)
je 0x110bb
cmpq $0x0, 0x8(%r12)
je 0x110bb
movq %rax, %r15
movq 0xa0a9(%rip), %r14      # 0x1afb8
leaq 0x4525(%rip), %rsi      # 0x1543b
movl $0xd, %edx
movq %r14, %rdi
callq 0xb870
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq 0xa077(%rip), %rdi      # 0x1afb8
callq 0xb040
movq %rax, %rdi
callq 0xb540
leaq 0x8(%rbx), %r14
movq 0xa05f(%rip), %rdi      # 0x1afb8
movq %r14, %rsi
callq 0xb610
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq %r14, %rdi
movq %r12, %rsi
callq 0xb5e0
movq 0xa01b(%rip), %r13      # 0x1afb8
leaq 0x44a5(%rip), %rsi      # 0x15449
movl $0xd, %edx
movq %r13, %rdi
callq 0xb870
movq (%r13), %rax
addq -0x18(%rax), %r13
movq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq 0x9fe8(%rip), %rdi      # 0x1afb8
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq 0x9fd4(%rip), %rdi      # 0x1afb8
movq %r14, %rsi
callq 0xb610
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
cmpb $0x0, 0x18(%rbx)
jne 0x1103c
cmpl $0x6, (%r12)
jb 0x110bb
movb $0x1, 0x18(%rbx)
movq 0x8(%r12), %rax
movzwl 0x4(%rax), %ecx
movw %cx, 0x4(%rbx)
movl (%rax), %eax
movl %eax, (%rbx)
movq %r14, 0x10(%rsp)
movl 0x8(%rbx), %r14d
leal -0x6(%r14), %r12d
movq 0x10(%rbx), %rbp
cmpl $0x6, %r14d
movl $0x1, %edi
cmovneq %r12, %rdi
callq 0xb030
movq %rax, %r13
cmpl $0x6, %r14d
je 0x1107a
addq $0x6, %rbp
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xb670
movl %r12d, (%rsp)
movq %r15, %rdi
callq 0xb990
movq %r12, %rdi
callq 0xb030
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xb670
movq %r13, %rdi
callq 0xb990
leaq 0x6(%r12), %rax
movl (%rbx), %r15d
cmpq %r15, %rax
movq 0x10(%rsp), %r14
jae 0x110df
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x110cd
callq 0xb990
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x4(%rbx), %eax
cmpl $0x1, %eax
je 0x1110c
cmpl $0x2, %eax
je 0x110ff
cmpl $0x3, %eax
jne 0x11117
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xb460
jmp 0x11117
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xbe50
jmp 0x11117
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xba40
movl (%rbx), %esi
movq %r14, %rdi
callq 0xbb80
movl $0x0, (%rbx)
movw $0x0, 0x4(%rbx)
movb $0x0, 0x18(%rbx)
jmp 0x110be
jmp 0x11144
movq %rax, %rbx
movq %r13, %rdi
callq 0xb990
jmp 0x11147
jmp 0x11144
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x11156
callq 0xb990
movq %rbx, %rdi
callq 0xbce0