Examples of BinaryDecoder


Examples of org.apache.avro.io.BinaryDecoder

     *
     * @throws IOException if deserialization failed
     */
    public static <T extends SpecificRecord> T deserializeAvro(org.apache.avro.Schema writer, ByteBuffer bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(ByteBufferUtil.getArray(bytes), null);
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return reader.read(ob, dec);
    }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

 
  /** Writes a request message and reads a response or error message. */
  public synchronized Object request(String messageName, Object request)
    throws Exception {
    Transceiver t = getTransceiver();
    BinaryDecoder in = null;
    Message m;
    RPCContext context = new RPCContext();
    do {
      ByteBufferOutputStream bbo = new ByteBufferOutputStream();
      //safe to use encoder because this is synchronized
      BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);
     
      // use local protocol to write request
      m = getLocal().getMessages().get(messageName);
      if (m == null)
        throw new AvroRuntimeException("Not a local message: "+messageName);
      context.setMessage(m);
   
      writeRequest(m.getRequest(), request, out); // write request payload
     
      out.flush();
      List<ByteBuffer> payload = bbo.getBufferList();
     
      writeHandshake(out);                       // prepend handshake if needed
     
      context.setRequestPayload(payload);
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientSendRequest(context);        // get meta-data from plugins
      }
      META_WRITER.write(context.requestCallMeta(), out);

      out.writeString(m.getName());               // write message name

      out.flush();
      bbo.append(payload);
     
      List<ByteBuffer> requestBytes = bbo.getBufferList();

      if (m.isOneWay() && t.isConnected()) {      // send one-way message
        t.writeBuffers(requestBytes);
       
        return null;
      } else {                                    // two-way message
        List<ByteBuffer> response = t.transceive(requestBytes);
        ByteBufferInputStream bbi = new ByteBufferInputStream(response);
        in = DecoderFactory.get().binaryDecoder(bbi, in);
      }
    } while (!readHandshake(in));

    // use remote protocol to read response
    Message rm = remote.getMessages().get(messageName);
    if (rm == null)
      throw new AvroRuntimeException("Not a remote message: "+messageName);

    if ((m.isOneWay() != rm.isOneWay()) && t.isConnected())
      throw new AvroRuntimeException("Not both one-way messages: "+messageName);

    if (m.isOneWay() && t.isConnected()) return null; // one-way w/ handshake
       
    context.setResponseCallMeta(META_READER.read(null, in));
   
    if (!in.readBoolean()) {                      // no error
      Object response = readResponse(rm.getResponse(), in);
      context.setResponse(response);
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientReceiveResponse(context);
      }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    out.writeInt(0);                              // empty metadata
    out.writeString("");                          // bogus message name
    List<ByteBuffer> response =
      getTransceiver().transceive(bbo.getBufferList());
    ByteBufferInputStream bbi = new ByteBufferInputStream(response);
    BinaryDecoder in =
      DecoderFactory.get().binaryDecoder(bbi, null);
    readHandshake(in);
    return this.remote;
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    Text currentFam = null;
    int currentPos = 0;
    Schema currentSchema = null;
    Field currentField = null;

    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(new byte[0], null);

    while (iter.hasNext()) {
      Entry<Key,Value> entry = iter.next();

      if (row == null) {
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    AvroEventDeserializer.Builder desBuilder =
        new AvroEventDeserializer.Builder();
    EventDeserializer deserializer = desBuilder.build(new Context(),
        new ResettableFileInputStream(tempFile, tracker));

    BinaryDecoder decoder = null;
    DatumReader<GenericRecord> reader =
        new GenericDatumReader<GenericRecord>(schema);

    decoder = DecoderFactory.get().binaryDecoder(
        deserializer.readEvent().getBody(), decoder);
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    record.x = 5;
    record.y = 10;
    writer.write(record, new BinaryEncoder(out));
    ReflectDatumReader reader = new ReflectDatumReader(schm, prefix);
    Object decoded =
      reader.read(null, new BinaryDecoder
                  (new ByteArrayInputStream(out.toByteArray())));
    assertEquals(record, decoded);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    writer.write(a, new BinaryEncoder(out));
    AnotherSampleRecord b = new AnotherSampleRecord(10);
    writer.write(b, new BinaryEncoder(out));
    ReflectDatumReader reader = new ReflectDatumReader(schm, prefix);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Object decoded = reader.read(null, new BinaryDecoder(in));
    assertEquals(a, decoded);
    decoded = reader.read(null, new BinaryDecoder(in));
    assertEquals(b, decoded);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    byte[] data = out.toByteArray();

    reader.setSchema(schema);
       
    Object decoded =
      reader.read(null, new BinaryDecoder(new ByteArrayInputStream(data)));
     
    assertEquals("Decoded data does not match.", datum, decoded);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, new BinaryDecoder(new ByteArrayInputStream(new byte[0])));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryDecoder

    long length = in.length();
    in.seek(length-4);
    int footerSize=(in.read()<<24)+(in.read()<<16)+(in.read()<<8)+in.read();
    in.seek(length-footerSize);
    this.vin = new BinaryDecoder(in);
    long l = vin.readMapStart();
    if (l > 0) {
      do {
        for (long i = 0; i < l; i++) {
          String key = vin.readString(null).toString();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.