The schema won't be embedded if you use AvroIODatumWriter directly.
You'll have to make sure that the schema is available when you later
deserialize the record, but I assumed you have a solution for that
already.

If you want to see a Java version of this, we do this in the Kite
SDK[1] to make sure that we're getting the same types that we'd see in
deserialized objects:

https://github.com/kite-sdk/kite/blob/master/kite-data/kite-data-core/src/main/java/org/kitesdk/data/spi/DataModelUtil.java#L144

Again, there's not schema in the byte array, just the serialized bytes.

-Joey

[1] http://www.kitesdk.org

On Thu, Jul 10, 2014 at 9:18 PM, Vadim Keylis <[email protected]> wrote:
> Hi Joey. Thanks so much for responding. I can serialize. My problem is
> decoupling schema that is embedded in the avro message from serialized
> message. How would I do this in php or very least in Java? I want to send to
> the Kafka node only avro serialized record without embedded schema.
>
> On Jul 10, 2014 5:54 PM, "Joey Echeverria" <[email protected]> wrote:
>>
>> I've not used the PHP bindings, so this may not be the full procedure.
>>
>> You should be able to create an AvroIODatumWriter[1] to write to a
>> string. In order to do that, you need to first create an
>> AvroStringIO[2] and wrap that in a AvroIOBinaryEncoder[3]. It should
>> look something like this:
>>
>> $io = new AvroStringIO();
>> $encoder = new AvroIOBinaryEncoder($io);
>> $writer = new AvroIODataumWriter($schema);
>> $writer->write($datum, $encoder);
>> $io->string(); // gets the serialized data as a string which in PHP is
>> an array of bytes
>>
>> -Joey
>>
>> [1]
>> https://github.com/apache/avro/blob/trunk/lang/php/lib/avro/datum.php#L73
>> [2]
>> https://github.com/apache/avro/blob/trunk/lang/php/lib/avro/io.php#L146
>> [3]
>> https://github.com/apache/avro/blob/trunk/lang/php/lib/avro/datum.php#L231
>>
>>
>> On Thu, Jul 10, 2014 at 6:28 PM, Vadim Keylis <[email protected]>
>> wrote:
>> > How do I just serialize single message using php? It appears php uses
>> > Container Files serialization approach and for my project I need to
>> > serialize single message without attaching schema as header.
>> >
>> > Thanks so much for your help
>> >
>> >
>>
>>
>>
>> --
>> Joey Echeverria



-- 
Joey Echeverria

Reply via email to