int32_t
thrift_binary_protocol_read_sandesh_begin (ThriftProtocol *protocol,
                                           char **name,
                                           int *error)
{
  int32_t ret;
  int32_t xfer = 0;

  if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0)
  {
    return -1;
  }
  xfer += ret;
  return xfer;
}
示例#2
0
gint32
thrift_binary_protocol_read_message_begin (ThriftProtocol *protocol,
                                           gchar **name,
                                           ThriftMessageType *message_type,
                                           gint32 *seqid, GError **error)
{
  g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);

  gint32 ret;
  gint32 xfer = 0;
  gint32 sz;

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

  if (sz < 0)
  {
    /* check for version */
    guint32 version = sz & THRIFT_BINARY_PROTOCOL_VERSION_MASK;
    if (version != THRIFT_BINARY_PROTOCOL_VERSION_1)
    {
      g_set_error (error, THRIFT_PROTOCOL_ERROR,
                   THRIFT_PROTOCOL_ERROR_BAD_VERSION,
                   "expected version %d, got %d",
                   THRIFT_BINARY_PROTOCOL_VERSION_1, version);
      return -1;
    }

    *message_type = (ThriftMessageType) (sz & 0x000000ff);

    if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0)
    {
      return -1;
    }
    xfer += ret;

    if ((ret = thrift_protocol_read_i32 (protocol, seqid, error)) < 0)
    {
      return -1;
    }
    xfer += ret;
  }
  return xfer;
}
int32_t
thrift_binary_protocol_read_message_begin (ThriftProtocol *protocol,
                                           char **name,
                                           ThriftMessageType *message_type,
                                           int32_t *seqid, int *error)
{
  int32_t ret;
  int32_t xfer = 0;
  int32_t sz;

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

  if (sz < 0)
  {
    /* check for version */
    u_int32_t version = sz & THRIFT_BINARY_PROTOCOL_VERSION_MASK;
    if (version != THRIFT_BINARY_PROTOCOL_VERSION_1)
    {
      *error = THRIFT_PROTOCOL_ERROR_BAD_VERSION;
      os_log(OS_LOG_ERR, "Expected version %d, got %d",
             THRIFT_BINARY_PROTOCOL_VERSION_1, version);
      return -1;
    }

    *message_type = (ThriftMessageType) (sz & 0x000000ff);

    if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0)
    {
      return -1;
    }
    xfer += ret;

    if ((ret = thrift_protocol_read_i32 (protocol, seqid, error)) < 0)
    {
      return -1;
    }
    xfer += ret;
  }
  return xfer;
}
示例#4
0
gboolean t_test_second_service_client_recv_secondtest_string (TTestSecondServiceIf * iface, gchar ** _return, GError ** error)
{

    gint32 rseqid;
    gchar * fname = NULL;
    ThriftMessageType mtype;
    ThriftProtocol * protocol = T_TEST_SECOND_SERVICE_CLIENT (iface)->input_protocol;

    if (thrift_protocol_read_message_begin (protocol, &fname, &mtype, &rseqid, error) < 0)
    {
        if (fname) g_free (fname);
        return FALSE;
    }

    if (mtype == T_EXCEPTION) {
        if (fname) g_free (fname);
        ThriftApplicationException *xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
        thrift_struct_read (THRIFT_STRUCT (xception), protocol, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, xception->type, "application error: %s", xception->message);
        g_object_unref (xception);
        return FALSE;
    } else if (mtype != T_REPLY) {
        if (fname) g_free (fname);
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE, "invalid message type %d, expected T_REPLY", mtype);
        return FALSE;
    } else if (strncmp (fname, "secondtestString", 16) != 0) {
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, error);
        thrift_transport_read_end (protocol->transport, error);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME, "wrong method name %s, expected secondtestString", fname);
        if (fname) g_free (fname);
        return FALSE;
    }
    if (fname) g_free (fname);

    {
        gint32 ret;
        gint32 xfer = 0;
        gchar *name = NULL;
        ThriftType ftype;
        gint16 fid;
        guint32 len = 0;
        gpointer data = NULL;


        /* satisfy -Wall in case these aren't used */
        THRIFT_UNUSED_VAR (len);
        THRIFT_UNUSED_VAR (data);

        /* read the struct begin marker */
        if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
        {
            if (name) g_free (name);
            return 0;
        }
        xfer += ret;
        if (name) g_free (name);
        name = NULL;

        /* read the struct fields */
        while (1)
        {
            /* read the beginning of a field */
            if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype, &fid, error)) < 0)
            {
                if (name) g_free (name);
                return 0;
            }
            xfer += ret;
            if (name) g_free (name);
            name = NULL;

            /* break if we get a STOP field */
            if (ftype == T_STOP)
            {
                break;
            }

            switch (fid)
            {
            case 0:
                if (ftype == T_STRING)
                {
                    if (*_return != NULL)
                    {
                        g_free(*_return);
                        *_return = NULL;
                    }

                    if ((ret = thrift_protocol_read_string (protocol, &*_return, error)) < 0)
                        return 0;
                    xfer += ret;
                } else {
                    if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                        return 0;
                    xfer += ret;
                }
                break;
            default:
                if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                    return 0;
                xfer += ret;
                break;
            }
            if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
                return 0;
            xfer += ret;
        }

        if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
            return 0;
        xfer += ret;

    }

    if (thrift_protocol_read_message_end (protocol, error) < 0)
        return FALSE;

    if (!thrift_transport_read_end (protocol->transport, error))
        return FALSE;

    return TRUE;
}
示例#5
0
/* reads a log_entry object */
gint32
log_entry_read (ThriftStruct *object, ThriftProtocol *protocol, GError **error)
{
  gint32 ret;
  gint32 xfer = 0;
  gchar *name = NULL;
  ThriftType ftype;
  gint16 fid;
  guint32 len = 0;
  gpointer data = NULL;
  LogEntry * this_object = LOG_ENTRY(object);

  /* satisfy -Wall in case these aren't used */
  THRIFT_UNUSED_VAR (len);
  THRIFT_UNUSED_VAR (data);
  THRIFT_UNUSED_VAR (this_object);

  /* read the struct begin marker */
  if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
  {
    if (name) g_free (name);
    return -1;
  }
  xfer += ret;
  if (name) g_free (name);
  name = NULL;

  /* read the struct fields */
  while (1)
  {
    /* read the beginning of a field */
    if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype, &fid, error)) < 0)
    {
      if (name) g_free (name);
      return -1;
    }
    xfer += ret;
    if (name) g_free (name);
    name = NULL;

    /* break if we get a STOP field */
    if (ftype == T_STOP)
    {
      break;
    }

    switch (fid)
    {
      case 1:
        if (ftype == T_STRING)
        {
          if (this_object->category != NULL)
          {
            g_free(this_object->category);
            this_object->category = NULL;
          }

          if ((ret = thrift_protocol_read_string (protocol, &this_object->category, error)) < 0)
            return -1;
          xfer += ret;
          this_object->__isset_category = TRUE;
        } else {
          if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
            return -1;
          xfer += ret;
        }
        break;
      case 2:
        if (ftype == T_STRING)
        {
          if (this_object->message != NULL)
          {
            g_free(this_object->message);
            this_object->message = NULL;
          }

          if ((ret = thrift_protocol_read_string (protocol, &this_object->message, error)) < 0)
            return -1;
          xfer += ret;
          this_object->__isset_message = TRUE;
        } else {
          if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
            return -1;
          xfer += ret;
        }
        break;
      default:
        if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
          return -1;
        xfer += ret;
        break;
    }
    if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
      return -1;
    xfer += ret;
  }

  if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
    return -1;
  xfer += ret;

  return xfer;
}