Exemplo n.º 1
0
/* destructor */
static void
thrift_memory_buffer_finalize (GObject *object)
{
  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);

  if (t->owner && t->buf != NULL)
  {
    g_byte_array_unref (t->buf);
  }
  t->buf = NULL;
}
Exemplo n.º 2
0
/* initializes class after constructor properties are set */
static void
thrift_memory_buffer_constructed (GObject *object)
{
  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);

  if (t->buf == NULL) {
    t->buf = g_byte_array_new ();
  }

  G_OBJECT_CLASS (thrift_memory_buffer_parent_class)->constructed (object);
}
Exemplo n.º 3
0
/* destructor */
static void
thrift_memory_buffer_finalize (GObject *object)
{
  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);

  if (transport->buf != NULL)
  {
    g_byte_array_free (transport->buf, TRUE);
  }
  transport->buf = NULL;
}
Exemplo n.º 4
0
/* property mutator */
void
thrift_memory_buffer_set_property (GObject *object, guint property_id,
                                   const GValue *value, GParamSpec *pspec)
{
  THRIFT_UNUSED_VAR (pspec);
  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);

  switch (property_id)
  {
    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
      transport->buf_size = g_value_get_uint (value);
      break;
  }
}
Exemplo n.º 5
0
/* implements thrift_transport_read */
gint32
thrift_memory_buffer_read (ThriftTransport *transport, gpointer buf,
                           guint32 len, GError **error)
{
  THRIFT_UNUSED_VAR (error);
  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);
  guint32 give = len; 

  /* if the requested bytes are more than what we have available,
   * just give all that we have the buffer */
  if (t->buf->len < len)
  {
    give = t->buf->len;
  }

  memcpy (buf, t->buf->data, give);
  g_byte_array_remove_range (t->buf, 0, give);

  return give;
}
Exemplo n.º 6
0
/* implements thrift_transport_write */
gboolean
thrift_memory_buffer_write (ThriftTransport *transport,
                            const gpointer buf,     
                            const guint32 len, GError **error)
{
  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);

  THRIFT_UNUSED_VAR (error);

  /* return an exception if the buffer doesn't have enough space. */
  if (len > t->buf_size - t->buf->len)
  {
    g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_SEND,
                 "unable to write %d bytes to buffer of length %d",
                 len, t->buf_size);
    return FALSE;
  } else {
    t->buf = g_byte_array_append (t->buf, buf, len);
    return TRUE;
  }
}
Exemplo n.º 7
0
/* property mutator */
void
thrift_memory_buffer_set_property (GObject *object, guint property_id,
                                   const GValue *value, GParamSpec *pspec)
{
  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);

  THRIFT_UNUSED_VAR (pspec);

  switch (property_id)
  {
    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
      t->buf_size = g_value_get_uint (value);
      break;
    case PROP_THRIFT_MEMORY_BUFFER_BUFFER:
      t->buf = (GByteArray*) g_value_get_pointer (value);
      break;
    case PROP_THRIFT_MEMORY_BUFFER_OWNER:
      t->owner = g_value_get_boolean (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}