Java Code Examples for org.msgpack.core.MessagePack#newDefaultPacker()

The following examples show how to use org.msgpack.core.MessagePack#newDefaultPacker() . 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: MessagePackRecordAccessor.java    From fluency with Apache License 2.0 6 votes vote down vote up
@Override
public void setTimestamp(long timestamp)
{
    int mapSize = mapValueBytes.map().size();
    try (ByteArrayOutputStream output = new ByteArrayOutputStream(mapValueBytes.byteArray().length + 16)) {
        try (MessagePacker packer = MessagePack.newDefaultPacker(output)) {
            if (mapValueBytes.map().containsKey(KEY_TIME)) {
                packer.packMapHeader(mapSize);
            }
            else {
                packer.packMapHeader(mapSize + 1);
                KEY_TIME.writeTo(packer);
                packer.packLong(timestamp);
            }

            for (Map.Entry<Value, Value> entry : mapValueBytes.map().entrySet()) {
                packer.packValue(entry.getKey());
                packer.packValue(entry.getValue());
            }
        }
        mapValueBytes = new MapValueBytes(ByteBuffer.wrap(output.toByteArray()));
    }
    catch (IOException e) {
        throw new IllegalStateException("Failed to upsert `time` field", e);
    }
}
 
Example 2
Source File: MsgpackIOUtil.java    From protostuff with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the {@code message} into an {@link MessageBufferOutput} using the given {@code schema}.
 */
public static <T> void writeTo(MessageBufferOutput out, T message, Schema<T> schema, boolean numeric)
        throws IOException
{

    MessagePacker packer = MessagePack.newDefaultPacker(out);

    try
    {
        writeTo(packer, message, schema, numeric);
    }
    finally
    {
        packer.flush();
    }
}
 
Example 3
Source File: MsgpackIOUtil.java    From protostuff with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the {@code messages} into the stream using the given schema.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric) throws IOException
{

    MessagePacker packer = MessagePack.newDefaultPacker(out);

    try
    {
        writeListTo(packer, messages, schema, numeric);
    }
    finally
    {
        packer.flush();
    }
}
 
Example 4
Source File: MsgpackIOUtil.java    From protostuff with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the {@code messages} into the stream using the given schema.
 */
public static <T> void writeListTo(MessageBufferOutput out, List<T> messages,
        Schema<T> schema, boolean numeric) throws IOException
{

    MessagePacker packer = MessagePack.newDefaultPacker(out);

    try
    {
        writeListTo(packer, messages, schema, numeric);
    }
    finally
    {
        packer.flush();
    }
}
 
Example 5
Source File: MessagePackSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize( Options options, OutputStream output, @Optional Object object )
{
    try( MessagePacker packer = MessagePack.newDefaultPacker( output ) )
    {
        Value value = doSerialize( options, object, true );
        packer.packValue( value );
        packer.flush();
    }
    catch( IOException ex )
    {
        throw new SerializationException( "Unable to serialize " + object, ex );
    }
}
 
Example 6
Source File: MsgpackIOUtil.java    From protostuff with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric) throws IOException
{

    MessagePacker packer = MessagePack.newDefaultPacker(out);

    try
    {
        writeTo(packer, message, schema, numeric);
    }
    finally
    {
        packer.flush();
    }
}
 
Example 7
Source File: MpackTypes.java    From funcj with MIT License 4 votes vote down vote up
public static OutStream outputOf(OutputStream os) {
    return new OutputImpl(MessagePack.newDefaultPacker(os));
}
 
Example 8
Source File: XML2Bin.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
private static void parseXml(final File file, StringBuilder mapCode) throws Exception {
        String clsName = fileNameToResName(file.getName()) + "_lang";

        DocumentBuilderFactory dbFactory
                = DocumentBuilderFactory.newInstance();
//        dbFactory.setValidating(false);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        dBuilder.setEntityResolver(new EntityResolver() {
            @Override
            public InputSource resolveEntity(String s, String systemId) throws SAXException, IOException {
                if (systemId.contains("xmode.dtd")) {
                    return new InputSource(new FileInputStream(new File(assetsPath, "xmode.dtd")));
                }
                return null;
            }
        });
        Document doc = dBuilder.parse(file);
        doc.getDocumentElement().normalize();

        NodeList nList = doc.getChildNodes();
        int length = nList.getLength();
        for (int i = 0; i < length; i++) {
            Node item = nList.item(i);
            o("node " + item.getNodeName() + " " + item.getNodeType());
            if (item.getNodeType() == Node.ELEMENT_NODE) {

                if (!item.getNodeName().equals("MODE"))
                    throw new RuntimeException("!MODE: " + item.getNodeName());
                File langFile = new File(rawPath, clsName);
                packer = MessagePack.newDefaultPacker(new FileOutputStream(langFile));

                handleChild((Element)item);

                mapCode.append(space(12)).append("case ").append(textString(file.getName()))
                        .append(": return R.raw.").append(clsName).append(";\n");


                packer.close();
            }
        }
    }