2
* Copyright (C) 2013 Drizzle Developer Group
3
* Copyright (C) 2013 Kuldeep Porwal
6
* Use and distribution licensed under the BSD license. See
7
* the COPYING file in the parent directory for full text.
9
* summary: parse table map event
14
#include "libdrizzle/common.h"
15
#include "libdrizzle/commonapi.h"
26
#include<libdrizzle-5.1/table_map_event.h>
32
using namespace binlogevent;
36
void TableMapEvent::initWithData(const unsigned char* data)
41
int start_pos = header.setHeader(data);
45
tmp = getByte6(start_pos,data);
48
setTableId((uint64_t)tmp);
49
start_pos+=6;// 6 byte for table id.
51
tmp = getByte2(start_pos,data);
54
setFlagPh((uint16_t)tmp);
55
start_pos+=2;// 2 byte for post-header flag.
57
if(sizeof(data)-start_pos<1)
59
setSchemaNameLen((uint8_t)data[start_pos]);
60
start_pos+=1;// 1 byte for schema name length.
62
tmp_char = getString(start_pos,schema_name_len,data);
65
setSchemaName(tmp_char);
66
start_pos+= schema_name_len; //schema_name_len byte for schema name.
68
// data[start_pos+getSchemaNameLen()] is Null
69
start_pos+=1; // +1 for Null.
71
if(sizeof(data)-start_pos<1)
73
setTableNameLen((uint8_t)data[start_pos]);
74
start_pos+=1;// 1 byte for table name length.
76
tmp_char = getString(start_pos,schema_name_len,data);
79
setTableName(tmp_char);
80
start_pos+=table_name_len+1; // +1 for null
82
tmp_int = getEncodedLen(start_pos,data);
85
setColumnCount(getEncodedLen(start_pos,data)); // start_pos will also get updated
88
if(sizeof(data)-start_pos<getColumnCount())
90
uint8_t *tmp_array = (uint8_t *)(malloc(sizeof(uint8_t)*getColumnCount()));
91
for(uint64_t i=0;i<getColumnCount();i++)
93
tmp_array[i]=(uint8_t)data[start_pos+i];
95
setColumnTypeDef(tmp_array);
96
start_pos+=column_count;
99
int metaSize= getEncodedLen(start_pos,data);
102
column_meta_data = (uint64_t *)(malloc(sizeof(uint64_t)*column_count));
104
if(sizeof(data)-start_pos<column_count)
106
for(uint64_t col=0;col<column_count;col++)
108
int type= column_type_def[col];
109
int nextBytes= lookup_metadata_field_size((enum_field_types)type);
114
metaData= (int)data[start_pos];
117
metaData= (int)getByte2(start_pos,data);
122
column_meta_data[col]= metaData;
123
start_pos+=nextBytes;
130
uint32_t TableMapEvent::getTimestamp()
132
return header.timestamp;
134
enum_event_type TableMapEvent::getType()
136
return (enum_event_type)header.type;
138
uint32_t TableMapEvent::getServerId()
140
return header.server_id;
142
uint32_t TableMapEvent::getLogPos()
144
return header.log_pos;
146
uint16_t TableMapEvent::getFlagH()
150
uint64_t TableMapEvent::getTableId()
154
uint16_t TableMapEvent::getFlagPh()
158
int TableMapEvent::getSchemaNameLen()
160
return (int)schema_name_len;
162
char * TableMapEvent::getSchemaName()
166
int TableMapEvent::getTableNameLen()
168
return (int)table_name_len;
170
char * TableMapEvent::getTableName()
174
uint64_t TableMapEvent::getColumnCount()
178
uint8_t * TableMapEvent::getColumnTypeDef()
180
return column_type_def;
183
enum_col_type TableMapEvent::getColType(int colNo)
185
enum_field_bytes num;
186
num = lookup_field_bytes((enum_field_types)column_type_def[colNo]);
190
return (enum_col_type)1;
197
return (enum_col_type)2;
204
void TableMapEvent::setTableId(uint64_t value)
208
void TableMapEvent::setFlagPh(uint16_t value)
212
void TableMapEvent::setSchemaNameLen(uint8_t value)
214
schema_name_len = value;
216
void TableMapEvent::setSchemaName(char *value)
220
void TableMapEvent::setTableNameLen(uint8_t value)
222
table_name_len = value;
224
void TableMapEvent::setTableName(char *value)
228
void TableMapEvent::setColumnCount(uint64_t value)
230
column_count = value;
232
void TableMapEvent::setColumnTypeDef(uint8_t * value)
234
column_type_def = value;