renamed number parsing functions
This commit is contained in:
parent
a20fbe0515
commit
781de171bd
9 changed files with 32 additions and 32 deletions
|
@ -30,16 +30,16 @@ extern "C" {
|
|||
// Parses a number. Identified by type (SML_TYPE_INTEGER or SML_TYPE_UNSIGNED)
|
||||
// and maximal number of bytes (SML_TYPE_NUMBER_8, SML_TYPE_NUMBER_16,
|
||||
// SML_TYPE_NUMBER_32, SML_TYPE_NUMBER_64)
|
||||
u64 mc_sml_parse_number(sml_buffer *buf, unsigned char type, int max_size);
|
||||
u64 sml_number_parse(sml_buffer *buf, unsigned char type, int max_size);
|
||||
|
||||
#define mc_sml_parse_u8(buf) (u8) mc_sml_parse_number(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8)
|
||||
#define mc_sml_parse_u16(buf) (u16) mc_sml_parse_number(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16)
|
||||
#define mc_sml_parse_u32(buf) (u32) mc_sml_parse_number(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32)
|
||||
#define mc_sml_parse_u64(buf) (u64) mc_sml_parse_number(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64)
|
||||
#define mc_sml_parse_i8(buf) (i8) mc_sml_parse_number(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8)
|
||||
#define mc_sml_parse_i16(buf) (i16) mc_sml_parse_number(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16)
|
||||
#define mc_sml_parse_i32(buf) (i32) mc_sml_parse_number(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32)
|
||||
#define mc_sml_parse_i64(buf) (i64) mc_sml_parse_number(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64)
|
||||
#define sml_u8_parse(buf) (u8) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8)
|
||||
#define sml_u16_parse(buf) (u16) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16)
|
||||
#define sml_u32_parse(buf) (u32) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32)
|
||||
#define sml_u64_parse(buf) (u64) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64)
|
||||
#define sml_i8_parse(buf) (i8) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8)
|
||||
#define sml_i16_parse(buf) (i16) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16)
|
||||
#define sml_i32_parse(buf) (i32) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32)
|
||||
#define sml_i64_parse(buf) (i64) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64)
|
||||
|
||||
void sml_number_write(unsigned char type, int size, u64 value, sml_buffer *buf);
|
||||
|
||||
|
|
|
@ -78,10 +78,10 @@ sml_list *sml_list_parse(sml_buffer *buf) {
|
|||
cur->val_time = SML_SKIP_OPTIONAL sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
cur->unit = SML_SKIP_OPTIONAL mc_sml_parse_u8(buf);
|
||||
cur->unit = SML_SKIP_OPTIONAL sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
cur->scaler = SML_SKIP_OPTIONAL mc_sml_parse_i8(buf);
|
||||
cur->scaler = SML_SKIP_OPTIONAL sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
cur->value = SML_SKIP_OPTIONAL sml_value_parse(buf);
|
||||
|
|
|
@ -55,16 +55,16 @@ sml_message *sml_message_parse(sml_buffer *buf) {
|
|||
msg->transaction_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->group_id = mc_sml_parse_u8(buf);
|
||||
msg->group_id = sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->abort_on_error = mc_sml_parse_u8(buf);
|
||||
msg->abort_on_error = sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->message_body = sml_message_body_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->crc = mc_sml_parse_u16(buf);
|
||||
msg->crc = sml_u16_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) {
|
||||
|
@ -130,7 +130,7 @@ sml_message_body *sml_message_body_parse(sml_buffer *buf) {
|
|||
goto error;
|
||||
}
|
||||
|
||||
msg_body->tag = mc_sml_parse_u16(buf);
|
||||
msg_body->tag = sml_u16_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
switch (msg_body->tag) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
u64 mc_sml_parse_number(sml_buffer *buf, unsigned char type, int max_size) {
|
||||
u64 sml_number_parse(sml_buffer *buf, unsigned char type, int max_size) {
|
||||
|
||||
int l, i;
|
||||
u64 n = 0;
|
||||
|
|
|
@ -100,7 +100,7 @@ sml_open_request *sml_open_request_parse(sml_buffer *buf) {
|
|||
msg->password = SML_SKIP_OPTIONAL sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->sml_version = SML_SKIP_OPTIONAL mc_sml_parse_u8(buf);
|
||||
msg->sml_version = SML_SKIP_OPTIONAL sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return msg;
|
||||
|
|
|
@ -50,7 +50,7 @@ sml_open_response *sml_open_response_parse(sml_buffer *buf) {
|
|||
msg->ref_time = SML_SKIP_OPTIONAL sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->sml_version = SML_SKIP_OPTIONAL mc_sml_parse_u8(buf);
|
||||
msg->sml_version = SML_SKIP_OPTIONAL sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return msg;
|
||||
|
|
|
@ -29,20 +29,20 @@ sml_status *sml_status_parse(sml_buffer *buf) {
|
|||
case SML_TYPE_UNSIGNED:
|
||||
switch (byte & SML_LENGTH_FIELD) {
|
||||
case SML_TYPE_NUMBER_8:
|
||||
state->status8 = mc_sml_parse_u8(buf);
|
||||
state->status8 = sml_u8_parse(buf);
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16:
|
||||
state->status16 = mc_sml_parse_u16(buf);
|
||||
state->status16 = sml_u16_parse(buf);
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16 + 1:
|
||||
case SML_TYPE_NUMBER_32:
|
||||
state->status32 = mc_sml_parse_u32(buf);
|
||||
state->status32 = sml_u32_parse(buf);
|
||||
break;
|
||||
case SML_TYPE_NUMBER_32 + 1:
|
||||
case SML_TYPE_NUMBER_32 + 2:
|
||||
case SML_TYPE_NUMBER_32 + 3:
|
||||
case SML_TYPE_NUMBER_64:
|
||||
state->status64 = mc_sml_parse_u64(buf);
|
||||
state->status64 = sml_u64_parse(buf);
|
||||
break;
|
||||
default:
|
||||
buf->error = 1;
|
||||
|
|
|
@ -35,10 +35,10 @@ sml_time *sml_time_parse(sml_buffer *buf) {
|
|||
goto error;
|
||||
}
|
||||
|
||||
tme->tag = mc_sml_parse_u8(buf);
|
||||
tme->tag = sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tme->data = mc_sml_parse_u32(buf);
|
||||
tme->data = sml_u32_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return tme;
|
||||
|
|
|
@ -35,23 +35,23 @@ sml_value *sml_value_parse(sml_buffer *buf) {
|
|||
case SML_TYPE_UNSIGNED:
|
||||
switch (byte & SML_LENGTH_FIELD) {
|
||||
case SML_TYPE_NUMBER_8:
|
||||
value->data.uint8 = mc_sml_parse_u8(buf);
|
||||
value->data.uint8 = sml_u8_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_8;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16:
|
||||
value->data.uint16 = mc_sml_parse_u16(buf);
|
||||
value->data.uint16 = sml_u16_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_16;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16 + 1:
|
||||
case SML_TYPE_NUMBER_32:
|
||||
value->data.uint32 = mc_sml_parse_u32(buf);
|
||||
value->data.uint32 = sml_u32_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_32;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_32 + 1:
|
||||
case SML_TYPE_NUMBER_32 + 2:
|
||||
case SML_TYPE_NUMBER_32 + 3:
|
||||
case SML_TYPE_NUMBER_64:
|
||||
value->data.uint64 = mc_sml_parse_u64(buf);
|
||||
value->data.uint64 = sml_u64_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_64;
|
||||
break;
|
||||
default:
|
||||
|
@ -67,23 +67,23 @@ sml_value *sml_value_parse(sml_buffer *buf) {
|
|||
// TODO: check if same problem exists for other SML_TYPEs too
|
||||
switch ((byte & SML_LENGTH_FIELD)-1) {
|
||||
case SML_TYPE_NUMBER_8:
|
||||
value->data.int8 = mc_sml_parse_i8(buf);
|
||||
value->data.int8 = sml_i8_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_8;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16:
|
||||
value->data.int16 = mc_sml_parse_i16(buf);
|
||||
value->data.int16 = sml_i16_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_16;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_16 + 1:
|
||||
case SML_TYPE_NUMBER_32:
|
||||
value->data.int32 = mc_sml_parse_i32(buf);
|
||||
value->data.int32 = sml_i32_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_32;
|
||||
break;
|
||||
case SML_TYPE_NUMBER_32 + 1:
|
||||
case SML_TYPE_NUMBER_32 + 2:
|
||||
case SML_TYPE_NUMBER_32 + 3:
|
||||
case SML_TYPE_NUMBER_64:
|
||||
value->data.int64 = mc_sml_parse_i64(buf);
|
||||
value->data.int64 = sml_i64_parse(buf);
|
||||
value->type |= SML_TYPE_NUMBER_64;
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Add table
Reference in a new issue