29 return do_check_match(other);
38 return _has_fixed_byte_size;
47 return _fixed_byte_size;
60 return _has_fixed_structure;
70 return _has_range_limits;
80 return _num_length_bytes;
92 return _has_nested_fields;
102 return _num_nested_fields;
116 INLINE
void DCPackerInterface::
117 do_pack_int8(
char *buffer,
int value) {
118 buffer[0] = (char)(value & 0xff);
124 INLINE
void DCPackerInterface::
125 do_pack_int16(
char *buffer,
int value) {
126 buffer[0] = (char)(value & 0xff);
127 buffer[1] = (char)((value >> 8) & 0xff);
133 INLINE
void DCPackerInterface::
134 do_pack_int32(
char *buffer,
int value) {
135 buffer[0] = (char)(value & 0xff);
136 buffer[1] = (char)((value >> 8) & 0xff);
137 buffer[2] = (char)((value >> 16) & 0xff);
138 buffer[3] = (char)((value >> 24) & 0xff);
144 INLINE
void DCPackerInterface::
145 do_pack_int64(
char *buffer, int64_t value) {
146 buffer[0] = (char)(value & 0xff);
147 buffer[1] = (char)((value >> 8) & 0xff);
148 buffer[2] = (char)((value >> 16) & 0xff);
149 buffer[3] = (char)((value >> 24) & 0xff);
150 buffer[4] = (char)((value >> 32) & 0xff);
151 buffer[5] = (char)((value >> 40) & 0xff);
152 buffer[6] = (char)((value >> 48) & 0xff);
153 buffer[7] = (char)((value >> 56) & 0xff);
159 INLINE
void DCPackerInterface::
160 do_pack_uint8(
char *buffer,
unsigned int value) {
161 buffer[0] = (char)(value & 0xff);
167 INLINE
void DCPackerInterface::
168 do_pack_uint16(
char *buffer,
unsigned int value) {
169 buffer[0] = (char)(value & 0xff);
170 buffer[1] = (char)((value >> 8) & 0xff);
176 INLINE
void DCPackerInterface::
177 do_pack_uint32(
char *buffer,
unsigned int value) {
178 buffer[0] = (char)(value & 0xff);
179 buffer[1] = (char)((value >> 8) & 0xff);
180 buffer[2] = (char)((value >> 16) & 0xff);
181 buffer[3] = (char)((value >> 24) & 0xff);
187 INLINE
void DCPackerInterface::
188 do_pack_uint64(
char *buffer, uint64_t value) {
189 buffer[0] = (char)(value & 0xff);
190 buffer[1] = (char)((value >> 8) & 0xff);
191 buffer[2] = (char)((value >> 16) & 0xff);
192 buffer[3] = (char)((value >> 24) & 0xff);
193 buffer[4] = (char)((value >> 32) & 0xff);
194 buffer[5] = (char)((value >> 40) & 0xff);
195 buffer[6] = (char)((value >> 48) & 0xff);
196 buffer[7] = (char)((value >> 56) & 0xff);
202 INLINE
void DCPackerInterface::
203 do_pack_float64(
char *buffer,
double value) {
204 #ifdef WORDS_BIGENDIAN 206 char *p = (
char *)&value;
207 for (
size_t i = 0; i < 8; i++) {
208 buffer[i] = p[7 - i];
211 memcpy(buffer, &value, 8);
219 INLINE
int DCPackerInterface::
220 do_unpack_int8(
const char *buffer) {
221 return (
int)(
signed char)buffer[0];
227 INLINE
int DCPackerInterface::
228 do_unpack_int16(
const char *buffer) {
229 return (
int)((
unsigned int)(
unsigned char)buffer[0] |
230 ((int)(
signed char)buffer[1] << 8));
236 INLINE
int DCPackerInterface::
237 do_unpack_int32(
const char *buffer) {
238 return (
int)((
unsigned int)(
unsigned char)buffer[0] |
239 ((
unsigned int)(
unsigned char)buffer[1] << 8) |
240 ((
unsigned int)(
unsigned char)buffer[2] << 16) |
241 ((int)(
signed char)buffer[3] << 24));
247 INLINE int64_t DCPackerInterface::
248 do_unpack_int64(
const char *buffer) {
249 return (int64_t)((uint64_t)(
unsigned char)buffer[0] |
250 ((uint64_t)(
unsigned char)buffer[1] << 8) |
251 ((uint64_t)(
unsigned char)buffer[2] << 16) |
252 ((uint64_t)(
unsigned char)buffer[3] << 24) |
253 ((uint64_t)(
unsigned char)buffer[4] << 32) |
254 ((uint64_t)(
unsigned char)buffer[5] << 40) |
255 ((uint64_t)(
unsigned char)buffer[6] << 48) |
256 ((int64_t)(
signed char)buffer[7] << 54));
261 INLINE
unsigned int DCPackerInterface::
262 do_unpack_uint8(
const char *buffer) {
263 return (
unsigned int)(
unsigned char)buffer[0];
269 INLINE
unsigned int DCPackerInterface::
270 do_unpack_uint16(
const char *buffer) {
271 return ((
unsigned int)(
unsigned char)buffer[0] |
272 ((
unsigned int)(
unsigned char)buffer[1] << 8));
278 INLINE
unsigned int DCPackerInterface::
279 do_unpack_uint32(
const char *buffer) {
280 return ((
unsigned int)(
unsigned char)buffer[0] |
281 ((
unsigned int)(
unsigned char)buffer[1] << 8) |
282 ((
unsigned int)(
unsigned char)buffer[2] << 16) |
283 ((
unsigned int)(
unsigned char)buffer[3] << 24));
289 INLINE uint64_t DCPackerInterface::
290 do_unpack_uint64(
const char *buffer) {
291 return ((uint64_t)(
unsigned char)buffer[0] |
292 ((uint64_t)(
unsigned char)buffer[1] << 8) |
293 ((uint64_t)(
unsigned char)buffer[2] << 16) |
294 ((uint64_t)(
unsigned char)buffer[3] << 24) |
295 ((uint64_t)(
unsigned char)buffer[4] << 32) |
296 ((uint64_t)(
unsigned char)buffer[5] << 40) |
297 ((uint64_t)(
unsigned char)buffer[6] << 48) |
298 ((int64_t)(
signed char)buffer[7] << 54));
305 INLINE
double DCPackerInterface::
306 do_unpack_float64(
const char *buffer) {
307 #ifdef WORDS_BIGENDIAN 311 for (
size_t i = 0; i < 8; i++) {
312 reverse[i] = buffer[7 - i];
314 return *(
double *)reverse;
316 return *(
double *)buffer;
317 #endif // WORDS_BIGENDIAN 330 int mask = ((int)1 << (num_bits - 1)) - 1;
335 if (value != mask && value != -1) {
346 int64_t mask = ((int64_t)1 << (num_bits - 1)) - 1;
349 if (value != mask && value != -1) {
363 unsigned int mask = ((
unsigned int)1 << num_bits) - 1;
377 uint64_t mask = ((uint64_t)1 << num_bits) - 1;
static void validate_uint64_limits(uint64_t value, int num_bits, bool &range_error)
Confirms that the unsigned value fits within num_bits bits.
const std::string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
bool has_fixed_structure() const
Returns true if this field type always has the same structure regardless of the data in the stream,...
bool has_nested_fields() const
Returns true if this field type has any nested fields (and thus expects a push() .
static void validate_int_limits(int value, int num_bits, bool &range_error)
Confirms that the signed value fits within num_bits bits.
bool has_fixed_byte_size() const
Returns true if this field type always packs to the same number of bytes, false if it is variable.
int get_num_nested_fields() const
Returns the number of nested fields required by this field type.
size_t get_fixed_byte_size() const
If has_fixed_byte_size() returns true, this returns the number of bytes this field type will use.
bool has_range_limits() const
Returns true if this field, or any sub-field of this field, has a limit imposed in the DC file on its...
bool check_match(const DCPackerInterface *other) const
Returns true if the other interface is bitwise the same as this oneāthat is, a uint32 only matches a ...
size_t get_num_length_bytes() const
Returns the number of bytes that should be written into the stream on a push() to record the number o...
static void validate_int64_limits(int64_t value, int num_bits, bool &range_error)
Confirms that the signed value fits within num_bits bits.
DCPackType get_pack_type() const
Returns the type of value expected by this field.
This defines the internal interface for packing values into a DCField.
static void validate_uint_limits(unsigned int value, int num_bits, bool &range_error)
Confirms that the unsigned value fits within num_bits bits.