org.msgpack.template.Template Java Examples

The following examples show how to use org.msgpack.template.Template. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessagePackMarshallingStrategy.java    From ob1k with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T unmarshall(final Type type, final Response response) throws IOException {

  final int statusCode = response.getStatusCode();

  if (statusCode < 200 || statusCode >= 300) {
    log.debug("request fail, status code: {}", statusCode, response);
    throw new IOException("Call failed for url: " + response.getUrl() + ", status code: " + statusCode + ".\n" +
            response.getResponseBody());
  }

  if (HttpResponseStatus.NO_CONTENT.code() == statusCode || !response.hasResponseBody()) {
    // on empty body the object mapper throws "JsonMappingException: No content to map due to end-of-input"
    return null;
  }

  final Value value = messagePack.read(response.getResponseBodyAsBytes());
  final Template<T> template = (Template<T>) messagePack.lookup(type);
  return template.read(new Converter(messagePack, value), null);
}
 
Example #2
Source File: MessagePackTranscoder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public T decode(final byte[] b) {
  final Template<?> template = messagePack.lookup(valueType);

  try {
    final Value value = messagePack.read(b);
    return (T) template.read(new Converter(messagePack, value), null);
  } catch (final IOException e) {
    throw new SerializationException("Failed to decode to type " + valueType.getTypeName(), e);
  }
}
 
Example #3
Source File: JavassistInvokerBuilder.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
public Invoker buildInvoker(Method m, ArgumentEntry[] entries, boolean async) {
	ReflectionArgumentEntry[] res = new ReflectionArgumentEntry[entries.length];
	for(int i=0; i < entries.length; i++) {
		ArgumentEntry e = entries[i];
		Class<?> type = e.getType();
		if(!e.isAvailable()) {
			res[i] = new ReflectionInvokerBuilder.NullArgumentEntry(e);
		} else if(type.equals(boolean.class)) {
			res[i] = new ReflectionInvokerBuilder.BooleanArgumentEntry(e);
		} else if(type.equals(byte.class)) {
			res[i] = new ReflectionInvokerBuilder.ByteArgumentEntry(e);
		} else if(type.equals(short.class)) {
			res[i] = new ReflectionInvokerBuilder.ShortArgumentEntry(e);
		} else if(type.equals(int.class)) {
			res[i] = new ReflectionInvokerBuilder.IntArgumentEntry(e);
		} else if(type.equals(long.class)) {
			res[i] = new ReflectionInvokerBuilder.LongArgumentEntry(e);
		} else if(type.equals(float.class)) {
			res[i] = new ReflectionInvokerBuilder.FloatArgumentEntry(e);
		} else if(type.equals(double.class)) {
			res[i] = new ReflectionInvokerBuilder.DoubleArgumentEntry(e);
		} else {
               Type t = e.getGenericType();
			Template tmpl = messagePack.lookup(t);
               if(tmpl == null){
                   messagePack.register((Class<?>)t);
                   tmpl = messagePack.lookup(t);
               }
			res[i] = new ReflectionInvokerBuilder.ObjectArgumentEntry(messagePack,e, tmpl);
		}
	}
	return buildInvoker(m, res, async);
}
 
Example #4
Source File: Future.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
Future(MessagePack messagePack, FutureImpl impl, Template resultTemplate) {
    this.impl = impl;
    this.resultTemplate = resultTemplate;
    this.messagePack = messagePack;
}
 
Example #5
Source File: Future.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public Future(MessagePack messagePack, Future<Value> future, Template resultTemplate) {
    this(messagePack, future.impl, resultTemplate);
}