// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl $0x0, (%rsp)
movl $0x1, %edi
callq 0xb030
movq %rax, %rbx
cmpl $0x0, (%r12)
je 0x110e9
cmpq $0x0, 0x8(%r12)
je 0x110e9
movq 0xa082(%rip), %r15      # 0x1afb8
leaq 0x44fe(%rip), %rsi      # 0x1543b
movl $0xd, %edx
movq %r15, %rdi
callq 0xb870
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq 0xa050(%rip), %rdi      # 0x1afb8
callq 0xb040
movq %rax, %rdi
callq 0xb540
leaq 0x8(%r14), %r15
movq 0xa038(%rip), %rdi      # 0x1afb8
movq %r15, %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 %r15, %rdi
movq %r12, %rsi
callq 0xb5e0
movq 0x9ff4(%rip), %r13      # 0x1afb8
leaq 0x447e(%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 0x9fc1(%rip), %rdi      # 0x1afb8
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq 0x9fad(%rip), %rdi      # 0x1afb8
movq %r15, %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(%r14)
jne 0x11067
cmpl $0x6, (%r12)
jb 0x110e9
movb $0x1, 0x18(%r14)
movq 0x8(%r12), %rax
movzwl 0x4(%rax), %ecx
movw %cx, 0x4(%r14)
movl (%rax), %eax
movl %eax, (%r14)
movq %r15, 0x10(%rsp)
movl 0x8(%r14), %r15d
leal -0x6(%r15), %r12d
movq 0x10(%r14), %rbp
cmpl $0x6, %r15d
movl $0x1, %edi
cmovneq %r12, %rdi
callq 0xb030
movq %rax, %r13
cmpl $0x6, %r15d
je 0x110a5
addq $0x6, %rbp
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xb670
movl %r12d, (%rsp)
movq %rbx, %rdi
callq 0xb990
movq %r12, %rdi
callq 0xb030
movq %rax, %rbx
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 (%r14), %r12d
cmpq %r12, %rax
movq 0x10(%rsp), %r15
jae 0x11106
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0xb990
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0x11134
cmpl $0x2, %eax
je 0x11127
cmpl $0x3, %eax
jne 0x1113f
movq %rsp, %rsi
movq %r14, %rdi
callq 0xb460
jmp 0x1113f
movq %rsp, %rsi
movq %r14, %rdi
callq 0xbe50
jmp 0x1113f
movq %rsp, %rsi
movq %r14, %rdi
callq 0xba40
movl (%r14), %esi
movq %r15, %rdi
callq 0xbb80
movl $0x0, (%r14)
movw $0x0, 0x4(%r14)
movb $0x0, 0x18(%r14)
jmp 0x110ec
jmp 0x11170
movq %rax, %r14
movq %r13, %rdi
callq 0xb990
jmp 0x11173
jmp 0x11170
movq %rax, %r14
movq %rbx, %rdi
callq 0xb990
movq %r14, %rdi
callq 0xbce0
nop