All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /******************************************************************************
27  * TYPES
28  *****************************************************************************/
29 
30 #if defined(__APPLE__) || defined(CF_WINDOWS)
31 
32 #pragma pack(push, 1) // packing is now 1
33 typedef struct as_proto_s {
34  uint64_t version :8;
35  uint64_t type :8;
36  uint64_t sz :48;
37 } as_proto;
38 #pragma pack(pop) // packing is back to what it was
39 
40 #pragma pack(push, 1) // packing is now 1
41 typedef struct as_msg_s {
42 /*00*/ uint8_t header_sz; // number of uint8_ts in this header
43 /*01*/ uint8_t info1; // bitfield about this request
44 /*02*/ uint8_t info2;
45 /*03*/ uint8_t info3;
46 /*04*/ uint8_t unused;
47 /*05*/ uint8_t result_code;
48 /*06*/ uint32_t generation;
49 /*10*/ uint32_t record_ttl;
50 /*14*/ uint32_t transaction_ttl;
51 /*18*/ uint16_t n_fields; // size in uint8_ts
52 /*20*/ uint16_t n_ops; // number of operations
53 /*22*/ uint8_t data[0]; // data contains first the fields, then the ops
54 } as_msg;
55 #pragma pack(pop) // packing is back to what it was
56 
57 #pragma pack(push, 1) // packing is now 1
58 typedef struct as_proto_msg_s {
59  as_proto proto;
60  as_msg m;
61 } as_proto_msg;
62 #pragma pack(pop) // packing is back to what it was
63 
64 #else
65 
66 typedef struct as_proto_s {
67  uint8_t version;
68  uint8_t type;
69  uint64_t sz:48;
70  uint8_t data[];
71 } __attribute__ ((__packed__)) as_proto;
72 
73 typedef struct as_msg_s {
74 /*00*/ uint8_t header_sz; // number of uint8_ts in this header
75 /*01*/ uint8_t info1; // bitfield about this request
76 /*02*/ uint8_t info2;
77 /*03*/ uint8_t info3;
78 /*04*/ uint8_t unused;
79 /*05*/ uint8_t result_code;
80 /*06*/ uint32_t generation;
81 /*10*/ uint32_t record_ttl;
82 /*14*/ uint32_t transaction_ttl;
83 /*18*/ uint16_t n_fields; // size in uint8_ts
84 /*20*/ uint16_t n_ops; // number of operations
85 /*22*/ uint8_t data[]; // data contains first the fields, then the ops
86 } __attribute__((__packed__)) as_msg;
87 
88 typedef struct as_proto_msg_s {
89  as_proto proto;
90  as_msg m;
91 } __attribute__((__packed__)) as_proto_msg;
92 
93 #endif
94 
95 /******************************************************************************
96  * FUNCTIONS
97  ******************************************************************************/
98 
99 void as_proto_swap_to_be(as_proto *m);
100 void as_proto_swap_from_be(as_proto *m);
101 void as_msg_swap_header_from_be(as_msg *m);
102 
103 #ifdef __cplusplus
104 } // end extern "C"
105 #endif
uint8_t result_code
Definition: as_proto.h:79
as_proto proto
Definition: as_proto.h:89
as_msg m
Definition: as_proto.h:765
as_msg m
Definition: as_proto.h:90
uint32_t record_ttl
Definition: as_proto.h:81
void as_proto_swap_from_be(as_proto *m)
uint16_t n_ops
Definition: as_proto.h:84
uint32_t generation
Definition: as_proto.h:80
uint8_t data[]
Definition: as_proto.h:85
uint8_t info3
Definition: as_proto.h:77
uint8_t data[]
Definition: as_proto.h:70
uint32_t transaction_ttl
Definition: as_proto.h:82
uint8_t version
Definition: as_proto.h:67
uint8_t unused
Definition: as_proto.h:78
uint8_t info1
Definition: as_proto.h:75
uint8_t header_sz
Definition: as_proto.h:74
uint8_t data[]
Definition: as_proto.h:767
struct as_proto_s __attribute__((__packed__)) as_proto
uint8_t type
Definition: as_proto.h:68
uint8_t info2
Definition: as_proto.h:76
void as_msg_swap_header_from_be(as_msg *m)
uint64_t sz
Definition: as_proto.h:69
uint16_t n_fields
Definition: as_proto.h:83
void as_proto_swap_to_be(as_proto *m)