Java Code Examples for org.msgpack.packer.Packer#write()

The following examples show how to use org.msgpack.packer.Packer#write() . 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: MessagePackRequestMarshaller.java    From ob1k with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@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: TransitMPTest.java    From transit-java with Apache License 2.0 5 votes vote down vote up
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 5
Source File: ResponseMessage.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
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 6
Source File: RequestMessage.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
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 7
Source File: NotifyMessage.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
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 8
Source File: ArgumentError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void messagePack(Packer pk) throws IOException {
    pk.writeArrayBegin(1);
    pk.write(getMessage());
    pk.writeArrayEnd();
}
 
Example 9
Source File: RemoteError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void messagePack(Packer pk) throws IOException {
    pk.write(data);
}
 
Example 10
Source File: RemoteError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void writeTo(Packer pk) throws IOException {
    pk.write(data);
}
 
Example 11
Source File: NoMethodError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void writeTo(Packer pk) throws IOException {
    pk.writeArrayBegin(1);
    pk.write(getMessage());
    pk.writeArrayEnd();

}
 
Example 12
Source File: MessagePackMarshallingStrategy.java    From ob1k with Apache License 2.0 3 votes vote down vote up
@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();
}