org.msgpack.packer.Packer Java Examples
The following examples show how to use
org.msgpack.packer.Packer.
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: WriterFactory.java From transit-java with Apache License 2.0 | 6 votes |
public static <T> Writer<T> getMsgpackInstance(final OutputStream out, Map<Class, WriteHandler<?,?>> customHandlers, WriteHandler<?, ?> defaultWriteHandler, Function<Object,Object> transform) throws IOException { Packer packer = new MessagePack().createPacker(out); final MsgpackEmitter emitter = new MsgpackEmitter(packer, handlerMap(customHandlers), defaultWriteHandler, transform); final WriteCache writeCache = new WriteCache(true); return new Writer<T>() { @Override public void write(T o) { try { emitter.emit(o, false, writeCache.init()); out.flush(); } catch (Throwable e) { throw new RuntimeException(e); } } }; }
Example #2
Source File: MessagePackRequestMarshaller.java From ob1k with Apache License 2.0 | 6 votes |
@Override public byte[] marshallRequestParams(final Object[] requestParams) throws IOException { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Packer packer = msgPack.createPacker(outputStream); final Object[] params; if (requestParams == null) { params = new Object[0]; } else { params = requestParams; } packer.writeArrayBegin(params.length); for (final Object param : params) { packer.write(param); } packer.writeArrayEnd(); return outputStream.toByteArray(); }
Example #3
Source File: ObjectTemplate.java From jvm-serializer with Apache License 2.0 | 5 votes |
@Override public void write(Packer pk, Object v, boolean required) throws IOException { if (v == null) { if (required) { throw new MessageTypeException("Attempted to write null"); } pk.writeNil(); return; } pk.write(v); }
Example #4
Source File: NotifyMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void messagePack(Packer pk) throws IOException { writeTo(pk); /* * pk.packArray(3); pk.packInt(Messages.NOTIFY); pk.packString(method); * pk.packArray(args.length); for(Object arg : args) { pk.pack(arg); } */ }
Example #5
Source File: NotifyMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void writeTo(Packer pk) throws IOException { pk.writeArrayBegin(3); pk.write(Messages.NOTIFY); pk.write(method); pk.writeArrayBegin(args.length); for (Object arg : args) { pk.write(arg); } pk.writeArrayEnd(); pk.writeArrayEnd(); }
Example #6
Source File: RequestMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void messagePack(Packer pk) throws IOException { writeTo(pk); /* * pk.packArray(4); pk.packInt(Messages.REQUEST); pk.packInt(msgid); * pk.packString(method); pk.packArray(args.length); for(Object arg : * args) { pk.pack(arg); } */ }
Example #7
Source File: RequestMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void writeTo(Packer pk) throws IOException { pk.writeArrayBegin(4); pk.write(Messages.REQUEST); pk.write(msgid); pk.write(method); pk.writeArrayBegin(args.length); for (Object arg : args) { pk.write(arg); } pk.writeArrayEnd(); pk.writeArrayEnd(); }
Example #8
Source File: ResponseMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void messagePack(Packer pk) throws IOException { writeTo(pk); /* * pk.packArray(4); pk.packInt(Messages.RESPONSE); pk.packInt(msgid); * pk.pack(error); pk.pack(result); */ }
Example #9
Source File: ResponseMessage.java From msgpack-rpc-java with Apache License 2.0 | 5 votes |
public void writeTo(Packer pk) throws IOException { pk.writeArrayBegin(4); pk.write(Messages.RESPONSE); pk.write(msgid); pk.write(error); pk.write(result); pk.writeArrayEnd(); }
Example #10
Source File: TransitMPTest.java From transit-java with Apache License 2.0 | 5 votes |
public Reader readerOf(Object... things) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); MessagePack msgpack = new MessagePack(); Packer packer = msgpack.createPacker(out); for (Object o : things) { packer.write(o); } InputStream in = new ByteArrayInputStream(out.toByteArray()); return TransitFactory.reader(TransitFactory.Format.MSGPACK, in); }
Example #11
Source File: ObjectTemplate.java From jvm-serializer with Apache License 2.0 | 5 votes |
@Override public void write(Packer pk, Object v, boolean required) throws IOException { if (v == null) { if (required) { throw new MessageTypeException("Attempted to write null"); } pk.writeNil(); return; } pk.write(v); }
Example #12
Source File: MsgpackEmitter.java From transit-java with Apache License 2.0 | 4 votes |
public MsgpackEmitter(Packer gen, WriteHandlerMap writeHandlerMap, WriteHandler defaultWriteHandler, Function<Object,Object> transform) { super(writeHandlerMap, defaultWriteHandler, transform); this.gen = gen; }
Example #13
Source File: MsgpackEmitter.java From transit-java with Apache License 2.0 | 4 votes |
public MsgpackEmitter(Packer gen, WriteHandlerMap writeHandlerMap, WriteHandler defaultWriteHandler) { super(writeHandlerMap, defaultWriteHandler); this.gen = gen; }
Example #14
Source File: MsgpackEmitter.java From transit-java with Apache License 2.0 | 4 votes |
@Deprecated public MsgpackEmitter(Packer gen, WriteHandlerMap writeHandlerMap) { super(writeHandlerMap, null); this.gen = gen; }
Example #15
Source File: ArgumentError.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void messagePack(Packer pk) throws IOException { pk.writeArrayBegin(1); pk.write(getMessage()); pk.writeArrayEnd(); }
Example #16
Source File: RemoteError.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void messagePack(Packer pk) throws IOException { pk.write(data); }
Example #17
Source File: RemoteError.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void writeTo(Packer pk) throws IOException { pk.write(data); }
Example #18
Source File: NoMethodError.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void writeTo(Packer pk) throws IOException { pk.writeArrayBegin(1); pk.write(getMessage()); pk.writeArrayEnd(); }
Example #19
Source File: NoMethodError.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void messagePack(Packer pk) throws IOException { writeTo(pk); /* * pk.packArray(1); pk.pack(getMessage()); */ }
Example #20
Source File: MessagePackMarshallingStrategy.java From ob1k with Apache License 2.0 | 3 votes |
@Override public byte[] marshall(final Object value) throws IOException { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Packer packer = messagePack.createPacker(outputStream); packer.write(value); return outputStream.toByteArray(); }