kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
kinetic_message.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
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.
14 *
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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kinetic_message.h"
21 #include "kinetic_logger.h"
22 
23 // e.g. CONFIG_FIELD_BYTE_BUFFER(key, message->keyValue, entry)
24 #define CONFIG_FIELD_BYTE_BUFFER(_name, _proto_name, _field, _entry) { \
25  if ((_entry)->_name.array.data != NULL \
26  && (_entry)->_name.array.len > 0 \
27  && (_entry)->_name.bytesUsed > 0 \
28  && (_entry)->_name.bytesUsed <= (_entry)->_name.array.len) \
29  { \
30  (_field)._proto_name.data = (_entry)->_name.array.data; \
31  (_field)._proto_name.len = (_entry)->_name.bytesUsed; \
32  (_field).has_ ## _proto_name = true; \
33  } \
34  else { \
35  (_field).has_ ## _proto_name = false; \
36  } \
37 }
38 
40  const KineticEntry* entry)
41 {
42  KINETIC_ASSERT(message != NULL);
43  KINETIC_ASSERT(entry != NULL);
44 
45  // Enable command body and keyValue fields by pointing at
46  // pre-allocated elements in message
47  message->command.body = &message->body;
48  message->command.body->keyvalue = &message->keyValue;
49 
50  // Set keyValue fields appropriately
51  CONFIG_FIELD_BYTE_BUFFER(key, key, message->keyValue, entry);
52  CONFIG_FIELD_BYTE_BUFFER(newVersion, newversion, message->keyValue, entry);
53  CONFIG_FIELD_BYTE_BUFFER(dbVersion, dbversion, message->keyValue, entry);
54  CONFIG_FIELD_BYTE_BUFFER(tag, tag, message->keyValue, entry);
55 
56  message->keyValue.has_force = (bool)((int)entry->force);
57  if (message->keyValue.has_force) {
58  message->keyValue.force = entry->force;
59  }
60 
61  message->keyValue.has_algorithm = (bool)((int)entry->algorithm > 0);
62  if (message->keyValue.has_algorithm) {
63  message->keyValue.algorithm =
65  }
66  message->keyValue.has_metadataonly = entry->metadataOnly;
67  if (message->keyValue.has_metadataonly) {
68  message->keyValue.metadataonly = entry->metadataOnly;
69  }
70 
71  message->keyValue.has_synchronization = (entry->synchronization > 0);
72  if (message->keyValue.has_synchronization) {
73  message->keyValue.synchronization =
75  entry->synchronization);
76  }
77 }
78 
79 
81  const KineticKeyRange* range)
82 {
83  KINETIC_ASSERT(message != NULL);
84  KINETIC_ASSERT(range != NULL);
85  KINETIC_ASSERT(range->startKey.array.data != NULL);
86  KINETIC_ASSERT(range->startKey.array.len > 0);
87  KINETIC_ASSERT(range->startKey.bytesUsed > 0);
89  KINETIC_ASSERT(range->maxReturned > 0);
90 
91  // Enable command body and keyValue fields by pointing at
92  // pre-allocated elements in message
93  message->command.body = &message->body;
94  message->command.body->range = &message->keyRange;
95 
96  // Populate startKey, if supplied
97  message->command.body->range->has_startkey =
98  (range->startKey.array.data != NULL);
99  if (message->command.body->range->has_startkey) {
100  message->command.body->range->startkey = (ProtobufCBinaryData) {
101  .data = range->startKey.array.data,
102  .len = range->startKey.bytesUsed,
103  };
104  }
105 
106  // Populate endKey, if supplied
107  message->command.body->range->has_endkey =
108  (range->endKey.array.data != NULL);
109  if (message->command.body->range->has_endkey) {
110  message->command.body->range->endkey = (ProtobufCBinaryData) {
111  .data = range->endKey.array.data,
112  .len = range->endKey.bytesUsed,
113  };
114  }
115 
116  // Populate start/end key inclusive flags, if specified
117  if (range->startKeyInclusive) {
118  message->command.body->range->startkeyinclusive = range->startKeyInclusive;
119  }
120  message->command.body->range->has_startkeyinclusive = range->startKeyInclusive;
121  if (range->endKeyInclusive) {
122  message->command.body->range->endkeyinclusive = range->endKeyInclusive;
123  }
124  message->command.body->range->has_endkeyinclusive = range->endKeyInclusive;
125 
126  // Populate max keys to return
127  message->command.body->range->maxreturned = range->maxReturned;
128  message->command.body->range->has_maxreturned = true;
129 
130  // Populate reverse flag (return keys in reverse order)
131  if (range->reverse) {
132  message->command.body->range->reverse = range->reverse;
133  }
134  message->command.body->range->has_reverse = range->reverse;
135 }
void KineticMessage_ConfigureKeyRange(KineticMessage *const message, const KineticKeyRange *range)
bool reverse
Optional bool, defaults to false If true, the key range will be returned in reverse order...
bool endKeyInclusive
Optional bool, defaults to false If set, indicates that the end key should be included in the returne...
Com__Seagate__Kinetic__Proto__Command__Range keyRange
bool force
If set for a GET/DELETE request, will override version checking.
bool metadataOnly
If set for a GET request, will return only the metadata for the specified object (value will not be r...
KineticAlgorithm algorithm
Algorithm used to generate the specified tag
ByteArray array
ByteArray holding allocated array w/length = allocated size.
Definition: byte_array.h:54
void KineticMessage_ConfigureKeyValue(KineticMessage *const message, const KineticEntry *entry)
Kinetic object instance.
int32_t maxReturned
Required int32, must be greater than 0 The maximum number of keys returned, in sorted order...
#define CONFIG_FIELD_BYTE_BUFFER(_name, _proto_name, _field, _entry)
Kinetic Key Range request structure.
#define KINETIC_ASSERT(cond)
Com__Seagate__Kinetic__Proto__Command__Algorithm Com__Seagate__Kinetic__Proto__Command__Algorithm_from_KineticAlgorithm(KineticAlgorithm kinteicAlgorithm)
ByteBuffer startKey
Required bytes, the beginning of the requested range.
Com__Seagate__Kinetic__Proto__Command__Body body
size_t len
Number of bytes in the data field.
Definition: byte_array.h:35
Com__Seagate__Kinetic__Proto__Command__Synchronization Com__Seagate__Kinetic__Proto__Command__Synchronization_from_KineticSynchronization(KineticSynchronization sync_mode)
Com__Seagate__Kinetic__Proto__Command__KeyValue keyValue
bool startKeyInclusive
Optional bool, defaults to false If set, indicates that the start key should be included in the retur...
uint8_t * data
Pointer to an allocated array of data bytes.
Definition: byte_array.h:36
Com__Seagate__Kinetic__Proto__Command command
size_t bytesUsed
Reflects the number of bytes used from the array
Definition: byte_array.h:55
ByteBuffer endKey
Required bytes, the end of the requested range.
KineticSynchronization synchronization
Synchronization method to use for PUT/DELETE requests.