Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
¿La implementación de avro C admite la transmisión en lugar de la salida de archivos?

Revisé el documento C en avro y veo que solo puedo obtener la salida de avro para archivar. ¿Cómo obtengo la salida serializada en un búfer para poder enviarla a través de un socket tcp? Cualquier ayuda es muy apreciada.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Hay un avro_writer_memory() exactamente para este caso, toma el puntero del búfer y la longitud como parámetros y le da avro_writer_t que se puede usar en funciones de escritura regulares. Puede encontrar su uso en pruebas, como this o this . El ejemplo mínimo será algo como esto (dando salida al valor codificado a stderr, así que es mejor redirigirlo a algún archivo y examinarlo después de ejecutar el programa):

 #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; }

Además, hay un avro_writer_memory_set_dest() que permite configurar un nuevo búfer para que lo use el escritor existente.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!