@Override
  public StorageResponse read(Unpacker unpacker, StorageResponse response, boolean required)
      throws IOException {
    ValueType type = unpacker.getNextType();

    if (type == ValueType.MAP) {
      MapValue mapValue = (MapValue) unpacker.readValue();

      return new FileMetaResponse(
          mapValue.get(ValueFactory.createRawValue("attributes")).toString(),
          mapValue.get(ValueFactory.createRawValue("key")).toString(),
          mapValue.get(ValueFactory.createRawValue("size")).asIntegerValue().getLong(),
          mapValue.get(ValueFactory.createRawValue("timestamp_ms")).asIntegerValue().getLong());
    } else if (type == ValueType.RAW) {
      return new DataResponse(unpacker.readByteArray());
    } else if (type == ValueType.ARRAY) {
      ArrayValue arrayValue = (ArrayValue) unpacker.readValue();

      StorageErrorType storageErrorType =
          StorageErrorType.byOrdinal(arrayValue.get(1).asIntegerValue().getInt());
      throw new StorageResponseError(STORAGE_SERVICE_NAME, storageErrorType);
    } else {
      throw new IllegalArgumentException("Can't parse storage response");
    }
  }
Esempio n. 2
0
 @Override
 public Object fromBytes(byte[] bytes) throws Exception {
   MapValue v = (MapValue) msgPack.read(bytes);
   //            System.out.println("v = " + v);
   System.out.println("name = " + v.containsKey("name"));
   return v;
 }