gint32
thrift_binary_protocol_read_field_begin (ThriftProtocol *protocol,
                                         gchar **name,
                                         ThriftType *field_type,
                                         gint16 *field_id,
                                         GError **error)
{
  THRIFT_UNUSED_VAR (name);
  g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);

  gint32 ret;
  gint32 xfer = 0;
  gint8 type;

  if ((ret = thrift_protocol_read_byte (protocol, &type, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  *field_type = (ThriftType) type;
  if (*field_type == T_STOP)
  {
    *field_id = 0;
    return xfer;
  }
  if ((ret = thrift_protocol_read_i16 (protocol, field_id, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  return xfer;
}
int32_t
thrift_binary_protocol_read_list_begin (ThriftProtocol *protocol,
                                        ThriftType *element_type,
                                        u_int32_t *size, int *error)
{
  int32_t ret;
  int32_t xfer = 0;
  int8_t e;
  int32_t sizei;

  if ((ret = thrift_protocol_read_byte (protocol, &e, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  *element_type = (ThriftType) e;

  if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) < 0)
  {
    return -1;
  }
  xfer += ret;

  if (sizei < 0)
  {
    *error = THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE;
    os_log(OS_LOG_ERR, "Got negative size of %d", sizei);
    return -1;
  }

  *size = (u_int32_t) sizei;
  return xfer;
}
int32_t
thrift_binary_protocol_read_field_begin (ThriftProtocol *protocol,
                                         char **name,
                                         ThriftType *field_type,
                                         int16_t *field_id,
                                         int *error)
{
  int32_t ret;
  int32_t xfer = 0;
  int8_t type;

  if ((ret = thrift_protocol_read_byte (protocol, &type, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  *field_type = (ThriftType) type;
  if (*field_type == T_STOP)
  {
    *field_id = 0;
    return xfer;
  }
  if ((ret = thrift_protocol_read_i16 (protocol, field_id, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  return xfer;
}
gint32
thrift_binary_protocol_read_map_begin (ThriftProtocol *protocol,
                                       ThriftType *key_type,
                                       ThriftType *value_type,
                                       guint32 *size,
                                       GError **error)
{
  g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);

  gint32 ret;
  gint32 xfer = 0;
  gint8 k, v;
  gint32 sizei;

  if ((ret = thrift_protocol_read_byte (protocol, &k, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  *key_type = (ThriftType) k;

  if ((ret = thrift_protocol_read_byte (protocol, &v, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  *value_type = (ThriftType) v;

  if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) <0)
  {
    return -1;
  }
  xfer += ret;

  if (sizei < 0)
  {
    g_set_error (error, THRIFT_PROTOCOL_ERROR,
                 THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
                 "got negative size of %d", sizei);
    return -1;
  }

  *size = (guint32) sizei;
  return xfer;
}
int32_t
thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type, int *error)
{
  switch (type)
  {
    case T_BOOL:
      {
        u_int8_t boolv;
        return thrift_protocol_read_bool (protocol, &boolv, error);
      }
    case T_BYTE:
      {
        int8_t bytev;
        return thrift_protocol_read_byte (protocol, &bytev, error);
      }

    case T_I16:
      {
        int16_t i16;
        return thrift_protocol_read_i16 (protocol, &i16, error);
      }
    case T_I32:
      {
        int32_t i32;
        return thrift_protocol_read_i32 (protocol, &i32, error);
      }
    case T_I64:
      {
        int64_t i64;
        return thrift_protocol_read_i64 (protocol, &i64, error);
      }
    case T_U16:
      {
        u_int16_t u16;
        return thrift_protocol_read_u16 (protocol, &u16, error);
      }
    case T_U32:
      {
        u_int32_t u32;
        return thrift_protocol_read_u32 (protocol, &u32, error);
      }
    case T_U64:
      {
        u_int64_t u64;
        return thrift_protocol_read_u64 (protocol, &u64, error);
      }
    case T_DOUBLE:
      {
        double dub;
        return thrift_protocol_read_double (protocol, &dub, error);
      }
    case T_STRING:
    case T_XML:
      {
        void *data;
        u_int32_t len;
        u_int32_t ret = thrift_protocol_read_binary (protocol, &data, &len, error);
        os_free (data);
        return ret;
      }
    case T_STRUCT:
      {
        u_int32_t result = 0;
        char *name;
        int16_t fid;
        ThriftType ftype;
        result += thrift_protocol_read_struct_begin (protocol, &name, error);

        while (1)
        {
          result += thrift_protocol_read_field_begin (protocol, &name, &ftype,
                                                      &fid, error);
          if (ftype == T_STOP)
          {
            break;
          }
          result += thrift_protocol_skip (protocol, ftype, error);
          result += thrift_protocol_read_field_end (protocol, error);
        }
        result += thrift_protocol_read_struct_end (protocol, error);
        return result;
      }
    case T_MAP:
      {
        u_int32_t result = 0;
        ThriftType elem_type;
        u_int32_t i, size;
        result += thrift_protocol_read_set_begin (protocol, &elem_type, &size,
                                                  error);
        for (i = 0; i < size; i++)
        {
          result += thrift_protocol_skip (protocol, elem_type, error);
        }
        result += thrift_protocol_read_set_end (protocol, error);
        return result;
      }
    case T_LIST:
      {
        u_int32_t result = 0;
        ThriftType elem_type;
        u_int32_t i, size;
        result += thrift_protocol_read_list_begin (protocol, &elem_type, &size,
                                                   error);
        for (i = 0; i < size; i++)
        {
          result += thrift_protocol_skip (protocol, elem_type, error);
        }
        result += thrift_protocol_read_list_end (protocol, error);
        return result;
      }
    default:
      return 0;
  }
}
Beispiel #6
0
gint32
thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type, GError **error)
{
  switch (type)
  {
    case T_BOOL:
      {
        gboolean boolv;
        return thrift_protocol_read_bool (protocol, &boolv, error);
      }
    case T_BYTE:
      {
        gint8 bytev;
        return thrift_protocol_read_byte (protocol, &bytev, error);
      }

    case T_I16:
      {
        gint16 i16;
        return thrift_protocol_read_i16 (protocol, &i16, error);
      }
    case T_I32:
      {
        gint32 i32;
        return thrift_protocol_read_i32 (protocol, &i32, error);
      }
    case T_I64:
      {
        gint64 i64;
        return thrift_protocol_read_i64 (protocol, &i64, error);
      }
    case T_DOUBLE:
      {
        gdouble dub;
        return thrift_protocol_read_double (protocol, &dub, error);
      }
    case T_STRING:
      {
        gpointer data;
        guint32 len;
        gint32 ret = thrift_protocol_read_binary (protocol, &data, &len, error);
        g_free (data);
        return ret;
      }
    case T_STRUCT:
      {
        guint32 result = 0;
        gchar *name;
        gint16 fid;
        ThriftType ftype;
        result += thrift_protocol_read_struct_begin (protocol, &name, error);

        while (1)
        {
          result += thrift_protocol_read_field_begin (protocol, &name, &ftype,
                                                      &fid, error);
          if (ftype == T_STOP)
          {
            break;
          }
          result += thrift_protocol_skip (protocol, ftype, error);
          result += thrift_protocol_read_field_end (protocol, error);
        }
        result += thrift_protocol_read_struct_end (protocol, error);
        return result;
      }
    case T_SET:
      {
        guint32 result = 0;
        ThriftType elem_type;
        guint32 i, size;
        result += thrift_protocol_read_set_begin (protocol, &elem_type, &size,
                                                  error);
        for (i = 0; i < size; i++)
        {
          result += thrift_protocol_skip (protocol, elem_type, error);
        }
        result += thrift_protocol_read_set_end (protocol, error);
        return result;
      }
    case T_MAP:
      {
        guint32 result = 0;
        ThriftType elem_type;
        ThriftType key_type;
        guint32 i, size;
        result += thrift_protocol_read_map_begin (protocol, &key_type, &elem_type, &size,
                                                  error);
        for (i = 0; i < size; i++)
        {
          result += thrift_protocol_skip (protocol, key_type, error);
          result += thrift_protocol_skip (protocol, elem_type, error);
        }
        result += thrift_protocol_read_map_end (protocol, error);
        return result;
      }
    case T_LIST:
      {
        guint32 result = 0;
        ThriftType elem_type;
        guint32 i, size;
        result += thrift_protocol_read_list_begin (protocol, &elem_type, &size,
                                                   error);
        for (i = 0; i < size; i++)
        {
          result += thrift_protocol_skip (protocol, elem_type, error);
        }
        result += thrift_protocol_read_list_end (protocol, error);
        return result;
      }
    default:
      return 0;
  }
}