-/* Copyright (C) 2009-2013, Martin Johansson <martin@fatbob.nu>
- Copyright (C) 2005-2013, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
#include <stdlib.h>
#include "pds.h"
#include "log.h"
+#include "memory.h"
/*
* Data serialization functions below
pds->bOk = false;
return 0;
}
-
+
}
static inline uint64_t next(pds_t *pds)
pds_t *Pds_create(uint8_t *buf, int size)
{
- pds_t *pds = malloc(sizeof(pds_t));
- if (pds == NULL)
- Log_fatal("Out of memory");
+ pds_t *pds = Memory_safeMalloc(1, sizeof(pds_t));
pds->data = buf;
pds->offset = pds->overshoot = 0;
pds->maxsize = size;
void Pds_add_double(pds_t *pds, double value)
{
double64u_t u;
-
+
u.dval = value;
-
+
Pds_add_numval(pds, u.u64);
}
void Pds_add_numval(pds_t *pds, const uint64_t value)
{
uint64_t i = value;
-
+
if ((i & 0x8000000000000000LL) && (~i < 0x100000000LL)) {
// Signed number.
i = ~i;
append_val(pds, i & 0xFF);
}
}
-
+
uint64_t Pds_get_numval(pds_t *pds)
{
uint64_t i = 0;
uint64_t v = next(pds);
-
+
if ((v & 0x80) == 0x00) {
i=(v & 0x7F);
} else if ((v & 0xC0) == 0x80) {