Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
does avro C implementation support streaming rather than file output?

I have gone through the C document at avro and I see that I can get only avro output to file. How do I get the serialized output to a buffer so that I can send over a tcp socket. Any help is much appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There is an avro_writer_memory() exactly for this case, it takes buffer pointer and length as parameters and gives you avro_writer_t that can be used in regular write functions. You can find its usage in tests, like this or this. The minimum example is going to be something like this (outputting encoded value to stderr, so better redirect that to some file and examine it after program run):

#include <avro.h>
#include <stdio.h>
#include <unistd.h>

static const char json_schema[] = "{ \"type\": \"string\" }";

int main(void)
{
    char buf[1024];
    avro_writer_t writer;
    avro_schema_t schema;
    avro_value_iface_t* iface;
    avro_value_t val;
    size_t len;

    if (avro_schema_from_json_literal(json_schema, &schema) != 0) {
        printf("failed to initialize schema\n");
        goto out;
    }
    if ((writer = avro_writer_memory(buf, sizeof(buf))) == NULL) {
        printf("failed to initialize writer\n");
        goto out_schema;
    }
    if ((iface = avro_generic_class_from_schema(schema)) == NULL) {
        printf("failed to get class from schema\n");
        goto out_writer;
    }
    if (avro_generic_value_new(iface, &val) != 0) {
        printf("failed to create new value\n");
        goto out_iface;
    }
    if (avro_value_reset(&val) != 0) {
        printf("failed to reset value\n");
        goto out_val;
    }
    if (avro_value_set_string(&val, "some string wrapped by avro") != 0) {
        printf("failed to set value string\n");
        goto out_val;
    }
    if (avro_value_write(writer, &val) != 0) {
        printf("failed to write value into the buffer\n");
        goto out_val;
    }
    len = avro_writer_tell(writer);
    printf("got %lu bytes\n", (unsigned long)len);
    if (write(STDERR_FILENO, buf, len) != len) {
        printf("failed to write to stderr, oops\n");
        goto out_val;
    }
out_val:
    avro_value_decref(&val);
out_iface:
    avro_value_iface_decref(iface);
out_writer:
    avro_writer_free(writer);
out_schema:
    avro_schema_decref(schema);
out:
    return 0;
}

Also, there is an avro_writer_memory_set_dest() that allows to set new buffer to use by the existing writer.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda