1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
20
#include <drizzled/global.h>
2
#include <drizzled/serialize/binary_log.h>
21
#include <drizzled/message/binary_log.h>
4
23
#include <google/protobuf/io/coded_stream.h>
6
using namespace google::protobuf;
7
using namespace google::protobuf::io;
25
using namespace google;
10
BinaryLog::Event::write(CodedOutputStream* out) const
28
BinaryLog::Event::write(protobuf::io::CodedOutputStream* out) const
12
30
// We frame each event in a length encoded in a special manner, and
13
31
// end it with a CRC-32 checksum.
20
38
char cs[4] = { 0 }; // !!! No checksum yet
39
#if GOOGLE_PROTOBUF_VERSION >= 2001000
40
out->WriteRaw(buf, static_cast<int>(end - buf)); // Length + Type
42
|| !m_message->SerializeToCodedStream(out)) // Event body
44
out->WriteRaw(cs, sizeof(cs)); // Checksum
21
48
if (!out->WriteRaw(buf, end - buf) || // Length + Type
22
49
!m_message->SerializeToCodedStream(out) || // Event body
23
50
!out->WriteRaw(cs, sizeof(cs))) // Checksum
31
BinaryLog::Event::read(CodedInputStream *in)
59
BinaryLog::Event::read(protobuf::io::CodedInputStream *in)
33
61
unsigned char buf[LENGTH_ENCODE_MAX_BYTES + 1];
39
67
// Read in the rest of the length bytes plus the type
40
68
size_t bytes= length_decode_bytes(*buf);
41
if (!in->ReadRaw(buf + 1, bytes))
69
if (! in->ReadRaw(buf + 1, static_cast<int>(bytes)))
78
110
// Read the event body as length bytes. It is necessary to limit the
79
111
// stream since otherwise ParseFromCodedStream reads all bytes of
81
CodedInputStream::Limit limit= in->PushLimit(length);
113
protobuf::io::CodedInputStream::Limit limit= in->PushLimit(static_cast<int>(length));
82
114
if (!message->ParseFromCodedStream(in))
84
116
in->PopLimit(limit);
103
135
BinaryLog::Event::print(std::ostream& out) const
105
using namespace google::protobuf;
107
137
switch (m_type) {
110
140
Query *event= static_cast<Query*>(m_message);
111
141
print_common(out, event);
112
for (RepeatedPtrField<Query::Variable>::const_iterator ii= event->variable().begin() ;
142
for (protobuf::RepeatedPtrField<Query::Variable>::const_iterator ii=
143
event->variable().begin() ;
113
144
ii != event->variable().end() ;
116
out << "set @" << ii->name() << " = '" << ii->value() << "'\n";
147
out << "set @" << ii->name() << " = '" << ii->val() << "'\n";
118
149
out << event->query() << std::endl;