2 * This file is part of buxton.
4 * Copyright (C) 2013 Intel Corporation
6 * buxton is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
13 * \file serialize.h Internal header
14 * This file is used internally by buxton to provide serialization
26 #include "buxtonarray.h"
29 * Magic for Buxton messages
31 #define BUXTON_CONTROL_CODE 0x672
34 * Location of size in serialized message data
36 #define BUXTON_LENGTH_OFFSET sizeof(uint32_t)
39 * Minimum size of serialized BuxtonData
40 * 2 is the minimum number of characters in a valid SMACK label
41 * 0 is the mimimum number of characters in a valid value (NULL STRING)
43 #define BXT_MINIMUM_SIZE sizeof(BuxtonDataType) \
44 + (sizeof(uint32_t) * 2) \
48 * Length of valid message header
50 #define BUXTON_MESSAGE_HEADER_LENGTH sizeof(uint32_t) \
53 * Maximum length of valid control message
55 #define BUXTON_MESSAGE_MAX_LENGTH 32768
58 * Maximum length of valid control message
60 #define BUXTON_MESSAGE_MAX_PARAMS 16
63 * Serialize data internally for backend consumption
64 * @param source Data to be serialized
65 * @param label Label to be serialized
66 * @param target Pointer to store serialized data in
67 * @return a size_t value, indicating the size of serialized data
69 size_t buxton_serialize(BuxtonData *source, BuxtonString *label,
71 __attribute__((warn_unused_result));
74 * Deserialize internal data for client consumption
75 * @param source Serialized data pointer
76 * @param target A pointer where the deserialize data will be stored
77 * @param label A pointer where the deserialize label will be stored
79 void buxton_deserialize(uint8_t *source, BuxtonData *target,
83 * Serialize an internal buxton message for wire communication
84 * @param dest Pointer to store serialized message in
85 * @param message The type of message to be serialized
86 * @param msgid The message ID to be serialized
87 * @param list An array of BuxtonData's to be serialized
88 * @return a size_t, 0 indicates failure otherwise size of dest
90 size_t buxton_serialize_message(uint8_t **dest,
91 BuxtonControlMessage message,
94 __attribute__((warn_unused_result));
97 * Deserialize the given data into an array of BuxtonData structs
98 * @param data The source data to be deserialized
99 * @param r_message An empty pointer that will be set to the message type
100 * @param size The size of the data being deserialized
101 * @param r_msgid The message ID being deserialized
102 * @param list A pointer that will be filled out as an array of BuxtonData structs
103 * @return the length of the array, or -1 if deserialization failed
105 ssize_t buxton_deserialize_message(uint8_t *data,
106 BuxtonControlMessage *r_message,
107 size_t size, uint32_t *r_msgid,
109 __attribute__((warn_unused_result));
112 * Get size of a buxton message data stream
113 * @param data The source data stream
114 * @param size The size of the data stream (from read)
115 * @return a size_t length of the complete message or 0
117 size_t buxton_get_message_size(uint8_t *data, size_t size)
118 __attribute__((warn_unused_result));
120 void include_serialize(void);
123 * Editor modelines - http://www.wireshark.org/tools/modelines.html
128 * indent-tabs-mode: t
131 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
132 * :indentSize=8:tabSize=8:noTabs=false: