ossp-pkg/xds/xdr-encode-int64.c 1.3 -> 1.4
--- xdr-encode-int64.c 2001/07/23 15:33:42 1.3
+++ xdr-encode-int64.c 2001/08/01 15:25:47 1.4
@@ -25,44 +25,37 @@
SUCH DAMAGE.
*/
-#include <assert.h>
#include "internal.h"
-int xdr_encode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+int xdr_encode_int64(xds_t* xds, void* engine_context,
+ void* buffer, size_t buffer_size, size_t* used_buffer_size,
+ va_list* args)
{
- /* Consistency checks. */
+ xds_uint64_t tmp;
+ xds_int64_t value;
- assert(xds != NULL);
- assert(buffer != NULL);
- assert(buffer_size != 0);
- assert(args != NULL);
- if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
- return XDS_ERR_INVALID_ARG;
+ xds_init_encoding_engine(8);
/* Get value and format it into the buffer. */
- if (buffer_size >= 8)
+ value = va_arg(*args, xds_uint64_t);
+ if (value < 0)
{
- xds_uint64_t tmp;
- xds_int64_t value = va_arg(*args, xds_uint64_t);
- if (value < 0)
- {
- value = 0 - value;
- tmp = 0 - (xds_uint64_t)value;
- }
- else
- tmp = (xds_uint64_t)value;
- ((xds_uint8_t*)buffer)[0] = (tmp >> 56) & 0x000000ff;
- ((xds_uint8_t*)buffer)[1] = (tmp >> 48) & 0x000000ff;
- ((xds_uint8_t*)buffer)[2] = (tmp >> 40) & 0x000000ff;
- ((xds_uint8_t*)buffer)[3] = (tmp >> 32) & 0x000000ff;
- ((xds_uint8_t*)buffer)[4] = (tmp >> 24) & 0x000000ff;
- ((xds_uint8_t*)buffer)[5] = (tmp >> 16) & 0x000000ff;
- ((xds_uint8_t*)buffer)[6] = (tmp >> 8) & 0x000000ff;
- ((xds_uint8_t*)buffer)[7] = (tmp >> 0) & 0x000000ff;
+ value = 0 - value;
+ tmp = 0 - (xds_uint64_t)value;
}
+ else
+ tmp = (xds_uint64_t)value;
+ ((xds_uint8_t*)buffer)[0] = (tmp >> 56) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[1] = (tmp >> 48) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[2] = (tmp >> 40) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[3] = (tmp >> 32) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[4] = (tmp >> 24) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[5] = (tmp >> 16) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[6] = (tmp >> 8) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[7] = (tmp >> 0) & 0x000000ff;
/* Done. */
- return 8;
+ return XDS_OK;
}
|
|