TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / tools / emugen / tests / t.001 / expected / decoder / foo_dec.cpp
1 // Generated Code - DO NOT EDIT !!
2 // generated by 'emugen'
3
4
5 #include <string.h>
6 #include "foo_opcodes.h"
7
8 #include "foo_dec.h"
9
10
11 #include "ProtocolUtils.h"
12
13 #include "ChecksumCalculatorThreadInfo.h"
14
15 #include <stdio.h>
16
17 typedef unsigned int tsize_t; // Target "size_t", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.
18
19 #ifdef OPENGL_DEBUG_PRINTOUT
20 #  define DEBUG(...) do { if (emugl_cxt_logger) { emugl_cxt_logger(__VA_ARGS__); } } while(0)
21 #else
22 #  define DEBUG(...)  ((void)0)
23 #endif
24
25 #ifdef CHECK_GLERROR
26 #  define SET_LASTCALL(name)  sprintf(lastCall, #name)
27 #else
28 #  define SET_LASTCALL(name)  ((void)0)
29 #endif
30
31 using namespace emugl;
32
33 size_t foo_decoder_context_t::decode(void *buf, size_t len, IOStream *stream)
34 {
35                            
36         size_t pos = 0;
37         if (len < 8) return pos; 
38         unsigned char *ptr = (unsigned char *)buf;
39         bool unknownOpcode = false;  
40 #ifdef CHECK_GL_ERROR 
41         char lastCall[256] = {0}; 
42 #endif 
43         while ((len - pos >= 8) && !unknownOpcode) {   
44                 uint32_t opcode = *(uint32_t *)ptr;   
45                 size_t packetLen = *(uint32_t *)(ptr + 4);
46                 if (len - pos < packetLen)  return pos; 
47                 bool useChecksum = ChecksumCalculatorThreadInfo::getVersion() > 0;
48                 size_t checksumSize = 0;
49                 if (useChecksum) {
50                         checksumSize = ChecksumCalculatorThreadInfo::checksumByteSize();
51                 }
52                 switch(opcode) {
53                 case OP_fooAlphaFunc: {
54                         FooInt var_func = Unpack<FooInt,uint32_t>(ptr + 8);
55                         FooFloat var_ref = Unpack<FooFloat,uint32_t>(ptr + 8 + 4);
56                         if (useChecksum) {
57                                 ChecksumCalculatorThreadInfo::validOrDie(ptr, 8 + 4 + 4, ptr + 8 + 4 + 4, checksumSize, 
58                                         "8 + 4 + 4::decode, OP_foo_decoder_context_t: GL checksumCalculator failure\n");
59                         }
60                         DEBUG("foo(%p): fooAlphaFunc(%d %f )\n", stream,var_func, var_ref);
61                         this->fooAlphaFunc(var_func, var_ref);
62                         SET_LASTCALL("fooAlphaFunc");
63                         break;
64                 }
65                 case OP_fooIsBuffer: {
66                         uint32_t size_stuff __attribute__((unused)) = Unpack<uint32_t,uint32_t>(ptr + 8);
67                         InputBuffer inptr_stuff(ptr + 8 + 4, size_stuff);
68                         if (useChecksum) {
69                                 ChecksumCalculatorThreadInfo::validOrDie(ptr, 8 + 4 + size_stuff, ptr + 8 + 4 + size_stuff, checksumSize, 
70                                         "8 + 4 + size_stuff::decode, OP_foo_decoder_context_t: GL checksumCalculator failure\n");
71                         }
72                         size_t totalTmpSize = sizeof(FooBoolean);
73                         totalTmpSize += checksumSize;
74                         unsigned char *tmpBuf = stream->alloc(totalTmpSize);
75                         DEBUG("foo(%p): fooIsBuffer(%p(%u) )\n", stream,(void*)(inptr_stuff.get()), size_stuff);
76                         *(FooBoolean *)(&tmpBuf[0]) =                   this->fooIsBuffer((void*)(inptr_stuff.get()));
77                         if (useChecksum) {
78                                 ChecksumCalculatorThreadInfo::writeChecksum(&tmpBuf[0], totalTmpSize - checksumSize, &tmpBuf[totalTmpSize - checksumSize], checksumSize);
79                         }
80                         stream->flush();
81                         SET_LASTCALL("fooIsBuffer");
82                         break;
83                 }
84                 case OP_fooUnsupported: {
85                         uint32_t size_params __attribute__((unused)) = Unpack<uint32_t,uint32_t>(ptr + 8);
86                         InputBuffer inptr_params(ptr + 8 + 4, size_params);
87                         if (useChecksum) {
88                                 ChecksumCalculatorThreadInfo::validOrDie(ptr, 8 + 4 + size_params, ptr + 8 + 4 + size_params, checksumSize, 
89                                         "8 + 4 + size_params::decode, OP_foo_decoder_context_t: GL checksumCalculator failure\n");
90                         }
91                         DEBUG("foo(%p): fooUnsupported(%p(%u) )\n", stream,(void*)(inptr_params.get()), size_params);
92                         this->fooUnsupported((void*)(inptr_params.get()));
93                         SET_LASTCALL("fooUnsupported");
94                         break;
95                 }
96                 case OP_fooDoEncoderFlush: {
97                         FooInt var_param = Unpack<FooInt,uint32_t>(ptr + 8);
98                         if (useChecksum) {
99                                 ChecksumCalculatorThreadInfo::validOrDie(ptr, 8 + 4, ptr + 8 + 4, checksumSize, 
100                                         "8 + 4::decode, OP_foo_decoder_context_t: GL checksumCalculator failure\n");
101                         }
102                         DEBUG("foo(%p): fooDoEncoderFlush(%d )\n", stream,var_param);
103                         this->fooDoEncoderFlush(var_param);
104                         SET_LASTCALL("fooDoEncoderFlush");
105                         break;
106                 }
107                 case OP_fooTakeConstVoidPtrConstPtr: {
108                         uint32_t size_param __attribute__((unused)) = Unpack<uint32_t,uint32_t>(ptr + 8);
109                         InputBuffer inptr_param(ptr + 8 + 4, size_param);
110                         if (useChecksum) {
111                                 ChecksumCalculatorThreadInfo::validOrDie(ptr, 8 + 4 + size_param, ptr + 8 + 4 + size_param, checksumSize, 
112                                         "8 + 4 + size_param::decode, OP_foo_decoder_context_t: GL checksumCalculator failure\n");
113                         }
114                         DEBUG("foo(%p): fooTakeConstVoidPtrConstPtr(%p(%u) )\n", stream,(const void* const*)(inptr_param.get()), size_param);
115                         this->fooTakeConstVoidPtrConstPtr((const void* const*)(inptr_param.get()));
116                         SET_LASTCALL("fooTakeConstVoidPtrConstPtr");
117                         break;
118                 }
119                         default:
120                                 unknownOpcode = true;
121                 } //switch
122                 if (!unknownOpcode) {
123                         pos += packetLen;
124                         ptr += packetLen;
125                 }
126         } // while
127         return pos;
128 }