0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ScanBlock.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #include <Common/Compat.h>
28 
29 #include "ScanBlock.h"
30 
31 #include <AsyncComm/Protocol.h>
32 
33 #include <Common/Error.h>
34 #include <Common/Logger.h>
35 #include <Common/Serialization.h>
36 
37 using namespace Hypertable;
38 using namespace Serialization;
39 
40 
42  m_iter = m_vec.end();
43 }
44 
45 
47  const uint8_t *decode_ptr = event->payload + 4;
48  size_t decode_remain = event->payload_len - 4;
49  uint32_t len;
50 
51  m_event = event;
52  m_vec.clear();
53  m_iter = m_vec.end();
54 
55  if ((m_error = (int)Protocol::response_code(event)) != Error::OK)
56  return m_error;
57 
58  try {
59  m_response.decode(&decode_ptr, &decode_remain);
60  len = decode_i32(&decode_ptr, &decode_remain);
61  }
62  catch (Exception &e) {
63  HT_ERROR_OUT << e << HT_END;
64  return e.code();
65  }
66  uint8_t *p = (uint8_t *)decode_ptr;
67  uint8_t *endp = p + len;
68  SerializedKey key;
69  ByteString value;
70 
71  while (p < endp) {
72  key.ptr = p;
73  p += key.length();
74  value.ptr = p;
75  p += value.length();
76  m_vec.push_back(std::make_pair(key, value));
77  }
78  m_iter = m_vec.begin();
79 
80  return m_error;
81 }
82 
83 
85 
86  assert(m_error == Error::OK);
87 
88  if (m_iter == m_vec.end())
89  return false;
90 
91  key = (*m_iter).first;
92  value = (*m_iter).second;
93 
94  ++m_iter;
95 
96  return true;
97 }
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
Logging routines and macros.
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
Functions to serialize/deserialize primitives to/from a memory buffer.
size_t length() const
Retrieves the length of the serialized string.
Definition: ByteString.h:62
#define HT_ERROR_OUT
Definition: Logger.h:301
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
Hypertable definitions
bool next(SerializedKey &key, ByteString &value)
Returns the next key/value pair in the scanblock.
Definition: ScanBlock.cc:84
Declarations for Protocol.
This is a generic exception class for Hypertable.
Definition: Error.h:314
Declarations for ScanBlock.
Error codes, Exception handling, error logging.
int load(EventPtr &event)
Loads scanblock data returned from RangeServer.
Definition: ScanBlock.cc:46
int code() const
Returns the error code.
Definition: Error.h:391