org.msgpack.unpacker.Converter Java Examples
The following examples show how to use
org.msgpack.unpacker.Converter.
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: GeneralMesseageConsumer.java From laser with Apache License 2.0 | 6 votes |
private boolean setItemProfile(String title, Vector profile) { try { Object[] req = new Object[1]; req[0] = title; Value res = msgpackClient.read(req, "splitTitle"); Converter converter = new org.msgpack.unpacker.Converter(res); SparseVector vec = converter.read(SparseVector.class); converter.close(); while (vec.hasNext()) { profile.set(vec.getIndex(), vec.get()); } } catch (Exception e) { return false; } return true; }
Example #2
Source File: MessagePackMarshallingStrategy.java From ob1k with Apache License 2.0 | 6 votes |
@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 #3
Source File: Future.java From msgpack-rpc-java with Apache License 2.0 | 6 votes |
public V getResult() { Value result = impl.getResult(); if (resultTemplate == null) { return (V) result; } else if (result.isNilValue()) { return null; } else { try { return (V) resultTemplate.read( new Converter(messagePack, result), null); // return (V)messagePack.c(result,); // result.convert(resultTemplate); } catch (IOException e) { return null; } } }
Example #4
Source File: MsgpackClient.java From laser with Apache License 2.0 | 5 votes |
public Object asyncRead(Object[] req, String method, Class<?> valueClass) throws IOException { Value vaule = asyncRead(req, method); if (null == vaule) { return null; } Converter converter = new org.msgpack.unpacker.Converter(vaule); Object ret = converter.read(valueClass); converter.close(); return ret; }
Example #5
Source File: MsgpackClient.java From laser with Apache License 2.0 | 5 votes |
public Object write(Object[] req, String method, Class<?> valueClass) throws Exception { Value vaule = write(req, method); if (null == vaule) { return null; } Converter converter = new org.msgpack.unpacker.Converter(vaule); Object ret = converter.read(valueClass); converter.close(); return ret; }
Example #6
Source File: TestMessagePack.java From springJredisCache with Apache License 2.0 | 5 votes |
@org.junit.Test public void test() throws IOException { // Create serialize objects. List<String> src = new ArrayList<String>(); src.add("msgpack"); src.add("kumofs"); src.add("viver"); MessagePack msgpack = new MessagePack(); // Serialize byte[] raw = msgpack.write(src); // Deserialize directly using a template List<String> dst1 = msgpack.read(raw, Templates.tList(Templates.TString)); System.out.println(dst1.get(0)); System.out.println(dst1.get(1)); System.out.println(dst1.get(2)); // Or, Deserialze to Value then convert type. Value dynamic = msgpack.read(raw); List<String> dst2 = new Converter(dynamic) .read(Templates.tList(Templates.TString)); System.out.println(dst2.get(0)); System.out.println(dst2.get(1)); System.out.println(dst2.get(2)); }
Example #7
Source File: MessagePackTranscoder.java From ob1k with Apache License 2.0 | 5 votes |
@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 #8
Source File: ReflectionProxyBuilder.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public Object invoke(Object proxy, Method method, Object[] args) { ReflectionMethodEntry e = entryMap.get(method); if(e == null) { // FIXME } Object[] params = e.sort(args); if(e.isAsync()) { Future<Value> f = s.callAsyncApply(e.getRpcName(), params); return new Future<Object>(messagePack, f, e.getReturnTypeTemplate()); } else { Value obj = s.callApply(e.getRpcName(), params); if(obj.isNilValue()){ return null; }else{ Template tmpl = e.getReturnTypeTemplate(); if(tmpl == null) { return null; } try { return tmpl.read(new Converter(messagePack,obj),null); //return messagePack.convert(obj,tmpl);// obj.convert(tmpl); } catch (IOException e1) { return null; } } } }
Example #9
Source File: ReflectionInvokerBuilder.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void convert(Object[] params, Value obj) throws MessageTypeException { try { params[getIndex()] = template.read(new Converter(messagePack,obj),null);//messagePack.convert(obj,template); } catch (IOException e) { new MessageTypeException(e); } }