Esempio n. 1
0
byte *
zchunk_data (zchunk_t *self)
{
    assert (self);
    assert (zchunk_is (self));
    return self->data;
}
Esempio n. 2
0
size_t
zchunk_max_size (zchunk_t *self)
{
    assert (self);
    assert (zchunk_is (self));
    return self->max_size;
}
Esempio n. 3
0
void
zchunk_print (zchunk_t *self)
{
    assert (self);
    assert (zchunk_is (self));

    zchunk_fprint (self, stderr);
}
Esempio n. 4
0
zframe_t *
zchunk_pack (zchunk_t *self)
{
    assert(self);
    assert(zchunk_is(self));

    return zframe_new (self->data, self->max_size);
}
Esempio n. 5
0
zchunk_t *
zchunk_dup (zchunk_t *self)
{
    assert (self);
    assert (zchunk_is (self));

    return zchunk_new (self->data, self->max_size);
}
Esempio n. 6
0
bool
zchunk_exhausted (zchunk_t *self)
{
    assert (self);
    assert (zchunk_is (self));

    assert (self->consumed <= self->size);
    return self->consumed == self->size;
}
Esempio n. 7
0
int
zchunk_write (zchunk_t *self, FILE *handle)
{
    assert (self);
    assert (zchunk_is (self));

    size_t items = fwrite (self->data, 1, self->size, handle);
    int rc = (items < self->size)? -1: 0;
    return rc;
}
Esempio n. 8
0
size_t
zchunk_consume (zchunk_t *self, zchunk_t *source)
{
    assert (self);
    assert (zchunk_is (self));
    assert (source);
    assert (zchunk_is (source));

    //  We can take at most this many bytes from source
    size_t size = source->size - source->consumed;

    //  And we can store at most this many bytes in chunk
    if (self->size + size > self->max_size)
        size = self->max_size - self->size;

    memcpy (self->data + self->size, source->data + source->consumed, size);
    source->consumed += size;
    self->size += size;
    return self->size;
}
Esempio n. 9
0
size_t
zchunk_append (zchunk_t *self, const void *data, size_t size)
{
    assert (self);
    assert (zchunk_is (self));

    if (self->size + size > self->max_size)
        size = self->max_size - self->size;

    memcpy (self->data + self->size, data, size);
    self->size += size;
    return self->size;
}
Esempio n. 10
0
size_t
zchunk_fill (zchunk_t *self, byte filler, size_t size)
{
    assert (self);
    assert (zchunk_is (self));

    if (size > self->max_size)
        size = self->max_size;

    memset (self->data, filler, size);
    self->size = size;
    return size;
}
Esempio n. 11
0
void
zchunk_resize (zchunk_t *self, size_t size)
{
    assert (self);
    assert (zchunk_is (self));

    //  If data was reallocated independently, free it independently
    if (self->data != (byte *) self + sizeof (zchunk_t))
        free (self->data);

    self->data = (byte *) zmalloc (size);
    self->max_size = size;
    self->size = 0;
}
Esempio n. 12
0
size_t
zchunk_set (zchunk_t *self, const void *data, size_t size)
{
    assert (self);
    assert (zchunk_is (self));

    if (size > self->max_size)
        size = self->max_size;
    if (data)
        memcpy (self->data, data, size);

    self->size = size;
    return size;
}
Esempio n. 13
0
void
zchunk_destroy (zchunk_t **self_p)
{
    assert (self_p);
    if (*self_p) {
        zchunk_t *self = *self_p;
        assert (zchunk_is (self));
        //  If data was reallocated independently, free it independently
        if (self->data != (byte *) self + sizeof (zchunk_t))
            free (self->data);
        self->tag = 0xDeadBeef;
        free (self);
        *self_p = NULL;
    }
}
Esempio n. 14
0
static int
s_config_printf (zconfig_t *self, void *arg, char *format, ...)
{
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);
    if (!string)
        return -1;

    if (arg) {
        if (zchunk_is (arg))
            zchunk_append ((zchunk_t *) arg, string, strlen (string));
        else
            fprintf ((FILE *) arg, "%s", string);
    }
    int size = strlen (string);
    free (string);
    return size;
}
Esempio n. 15
0
void
zchunk_fprint (zchunk_t *self, FILE *file)
{
    assert (self);
    assert (zchunk_is (self));

    fprintf (file, "--------------------------------------\n");
    if (!self) {
        fprintf (file, "NULL");
        return;
    }
    assert (self);
    int is_bin = 0;
    uint char_nbr;
    for (char_nbr = 0; char_nbr < self->size; char_nbr++)
        if (self->data [char_nbr] < 9 || self->data [char_nbr] > 127)
            is_bin = 1;

    fprintf (file, "[%03d] ", (int) self->size);
    for (char_nbr = 0; char_nbr < self->size; char_nbr++) {
        if (is_bin) {
            fprintf (file, "%02X", (unsigned char) self->data [char_nbr]);
            if (char_nbr > 35) {
                fprintf (file, "...");
                break;
            }
        }
        else {
            fprintf (file, "%c", self->data [char_nbr]);
            if (char_nbr > 70) {
                fprintf (file, "...");
                break;
            }
        }
    }
    fprintf (file, "\n");
}
Esempio n. 16
0
///
//  Probe the supplied object, and report if it looks like a zchunk_t.
bool QZchunk::is (void *self)
{
    bool rv = zchunk_is (self);
    return rv;
}
Esempio n. 17
0
JNIEXPORT jboolean JNICALL
Java_org_zeromq_czmq_Zchunk__1_1is (JNIEnv *env, jclass c, jlong self)
{
    jboolean is_ = (jboolean) zchunk_is ((void *) (intptr_t) self);
    return is_;
}