Return-Path: X-Original-To: apmail-avro-user-archive@www.apache.org Delivered-To: apmail-avro-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35B28CEF9 for ; Mon, 17 Jun 2013 03:16:07 +0000 (UTC) Received: (qmail 15736 invoked by uid 500); 17 Jun 2013 03:16:04 -0000 Delivered-To: apmail-avro-user-archive@avro.apache.org Received: (qmail 15646 invoked by uid 500); 17 Jun 2013 03:15:57 -0000 Mailing-List: contact user-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@avro.apache.org Delivered-To: mailing list user@avro.apache.org Received: (qmail 15609 invoked by uid 99); 17 Jun 2013 03:15:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jun 2013 03:15:55 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of dongre.avinash@gmail.com designates 74.125.82.173 as permitted sender) Received: from [74.125.82.173] (HELO mail-we0-f173.google.com) (74.125.82.173) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jun 2013 03:15:49 +0000 Received: by mail-we0-f173.google.com with SMTP id x54so1912242wes.18 for ; Sun, 16 Jun 2013 20:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ra1yL+sOFsuUbHc4RXgrq1Uf793b5o93sis+QCi2F5k=; b=x6eCOb4dHAgpbuI8vY0FcdvqB/ECVk43ClIXpW26ek7/fGd53qA06ClUhcQ9H6A0Sf sTe+BEx55VewCuiZKwT70Yivv+UIlTaCjmNvBEwzpcLzcQvANYs2k+8fqgAha1Ph0dzx 8DkGXV4ZLd0fiQ97pBSM/nC6/flLS3eLs4/oHuBeKpVb2/mvZz8rBiNFT6uN1jdVkSsq 4fUNlwm0WLuCKFE0N2IYVWAO1tQIypEFEFypjecXOBLdRPAVH1rcgEB+uFMEHY+cgOJV Q86QIjSvA6y7a3QjxgxUa/6rt7xyg5cN/c1zbPeG3pp2g5Yq1f0N8bgszNa+4Mh+0PaO yH5g== MIME-Version: 1.0 X-Received: by 10.194.108.73 with SMTP id hi9mr6700722wjb.85.1371438929484; Sun, 16 Jun 2013 20:15:29 -0700 (PDT) Received: by 10.194.22.231 with HTTP; Sun, 16 Jun 2013 20:15:29 -0700 (PDT) In-Reply-To: References: Date: Mon, 17 Jun 2013 08:45:29 +0530 Message-ID: Subject: Re: Sending Apache avro serialized data to thrift server From: Avinash Dongre To: user@avro.apache.org Content-Type: multipart/alternative; boundary=047d7bf10b283923f704df5102bd X-Virus-Checked: Checked by ClamAV on apache.org --047d7bf10b283923f704df5102bd Content-Type: text/plain; charset=ISO-8859-1 > Hi, > I am trying to send avro serialized data to my thrift server. But when I > try to de-serialized I get exception > org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: > -51 > > If I do the same operation in the same vm process everything works fine. > > Here is my small code. > > public static GenericRecord createContentNestedObject() throws Exception { > GenericRecord image1 = new GenericData.Record(IMAGE_SCHEMA); > image1.put("uri", new Utf8("http://javaone.com/keynote_large.jpg")); > image1.put("width", 0); > image1.put("height", 0); > image1.put("size", 2); > image1.put("title", new Utf8("Javaone Keynote")); > return image1; > } > > // Helper Method to serialize the object from avro to bytebuffer > public static ByteBuffer serialize(GenericRecord content, Schema schema) > throws Exception { > > ByteArrayOutputStream out = new ByteArrayOutputStream(); > DatumWriter writer = new > GenericDatumWriter( > schema); > // create Binary Encoder > EncoderFactory ef = new EncoderFactory(); > BinaryEncoder be = ef.binaryEncoder(out, null); > writer.write(content, be); > be.flush(); > out.close(); > > return ByteBuffer.wrap(out.toByteArray()); > } > > public static void main(String[] args) throws Exception { > try { > GenericRecord rd = createContentNestedObject(); > bf = serialize(rd, IMAGE_SCHEMA); > > } catch (Exception e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > // Deserialization. > DatumReader reader = new > GenericDatumReader(IMAGE_SCHEMA_1); > ByteArrayOutputStream out = new ByteArrayOutputStream(); > try { > out.write(bf.array()); > } catch (IOException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > } > BinaryDecoder decoder = > DecoderFactory.get().binaryDecoder(out.toByteArray(), null); > try { > GenericRecord result = reader.read(null, decoder); > System.out.println("RESULT : " + result.toString()); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > This code works. When I send the bf to my thrift api , I am getting the > error, > my thrift api is simple which accept ByteBuffer and try to deserialize it. > > following is the code in the thrift server api > > DatumReader reader = new > GenericDatumReader(IMAGE_SCHEMA_1); > ByteArrayOutputStream out = new ByteArrayOutputStream(); > try { > out.write(bf.array()); > } catch (IOException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > } > BinaryDecoder decoder = > DecoderFactory.get().binaryDecoder(out.toByteArray(), null); > try { > GenericRecord result = reader.read(null, decoder); > System.out.println("RESULT : " + result.toString()); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > > > What is wrong here. > > > Thanks > Aviansh > > > --047d7bf10b283923f704df5102bd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

=
Hi,
I am trying to send= avro serialized data to my thrift server. But when I try to de-serialized = I get exception=A0
org.apache.avro.AvroRuntimeException: Malformed data. Length is n= egative: -51

If I do the same operation in the same vm process= everything works fine.

Here is my small code.

public static GenericRecord createContentNestedO= bject() throws Exception {
=A0 =A0 GenericRecord image1 =3D new GenericData.Record(IMAGE_SCHEMA);=
=A0 =A0 image1.put("uri", new Utf8("http://javaone.com/ke= ynote_large.jpg"));
=A0 =A0 image1.put("width", 0);
=A0 =A0 image1.put= ("height", 0);
=A0 =A0 image1.put("size", 2);=
=A0 =A0 image1.put("title", new Utf8("Javaone Key= note"));
=A0 =A0 return image1;
=A0 }

=A0 //= Helper Method to serialize the object from avro to bytebuffer
= =A0 public static ByteBuffer serialize(GenericRecord content, Schema schema= )
=A0 =A0 =A0 throws Exception {

=A0 =A0 ByteArrayOu= tputStream out =3D new ByteArrayOutputStream();
=A0 =A0 DatumWrit= er<GenericRecord> writer =3D new GenericDatumWriter<GenericRecord&= gt;(
=A0 =A0 =A0 =A0 schema);
=A0 =A0 // create Binary Encoder
=A0 =A0 EncoderFactory ef =3D new EncoderFactory();
=A0 =A0 Bi= naryEncoder be =3D ef.binaryEncoder(out, null);
=A0 =A0 writer.wr= ite(content, be);
=A0 =A0 be.flush();
=A0 =A0 out.close();

=A0 =A0 return ByteBuffer.wrap(out.toByteArray());
=A0 }

=A0 public static void main(String[] args) throws Excepti= on {
=A0 =A0 try {
=A0 =A0 =A0 GenericRecord rd =3D createContentN= estedObject();
=A0 =A0 =A0 bf =3D serialize(rd, IMAGE_SCHEMA);
=A0 =A0 =A0=A0
=A0 =A0 } catch (Exception e) {
<= div>=A0 =A0 =A0 // TODO Auto-generated catch block
=A0 =A0 =A0 e.printStackTrace();
=A0 =A0 }
=A0 =A0= =A0
=A0 =A0 // Deserialization.=A0
=A0 =A0 DatumReader&= lt;GenericRecord> reader =3D new GenericDatumReader<GenericRecord>= (IMAGE_SCHEMA_1); =A0 =A0
=A0 =A0 ByteArrayOutputStream out =3D new ByteArrayOutputStream(= );
=A0 =A0 try {
=A0 =A0 =A0 out.write(bf.array());
=A0 =A0 } catch (IOException e1) {
=A0 =A0 =A0 // TODO Aut= o-generated catch block
=A0 =A0 =A0 e1.printStackTrace();
=A0 =A0 } =A0 =A0
=A0 =A0 BinaryDecoder decoder =3D DecoderFactory.get().binaryDecoder(out.= toByteArray(), null); =A0
=A0 =A0 try {
=A0 =A0 =A0 Gen= ericRecord result =3D reader.read(null, decoder);
=A0 =A0 =A0 System.out.println("RESULT : " + result.toString= ());
=A0 =A0 } catch (IOException e) {
=A0 =A0 =A0 // T= ODO Auto-generated catch block
=A0 =A0 =A0 e.printStackTrace();
=A0 =A0 }

This code works. When I send the bf to my thrift api , = I am getting the error,=A0
my thrift api is simple which accept B= yteBuffer and try to deserialize it.

following is the code in the thrift server api

DatumReader<GenericRecord> reader =3D new GenericDatumReader&l= t;GenericRecord>(IMAGE_SCHEMA_1); =A0 =A0
=A0 =A0 ByteArrayOutputStream out =3D new ByteArrayOutputStream();
=A0 =A0 try {
=A0 =A0 =A0 out.write(bf.array());
=A0 = =A0 } catch (IOException e1) {
=A0 =A0 =A0 // TODO Auto-generated= catch block
=A0 =A0 =A0 e1.printStackTrace();
=A0 =A0 } =A0 =A0
=A0= =A0 BinaryDecoder decoder =3D DecoderFactory.get().binaryDecoder(out.toByt= eArray(), null); =A0
=A0 =A0 try {
=A0 =A0 =A0 GenericR= ecord result =3D reader.read(null, decoder);
=A0 =A0 =A0 System.out.println("RESULT : " + result.toString= ());
=A0 =A0 } catch (IOException e) {
=A0 =A0 =A0 // T= ODO Auto-generated catch block
=A0 =A0 =A0 e.printStackTrace();
=A0 =A0 }



What is wrong here.
=


Thanks
Aviansh

<= /div>


--047d7bf10b283923f704df5102bd--