summaryrefslogtreecommitdiff
path: root/java-plan2/src/org/msgpack/schema/RawSchema.java
blob: 847ad29401d9b0356b1cdd1a7a35a921d634c9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.msgpack.schema;

import java.io.IOException;
import java.nio.charset.Charset;
import org.msgpack.*;

public class RawSchema extends Schema {
	public RawSchema()
	{
		super("raw");
	}

	public String getFullName()
	{
		return "byte[]";
	}

	@Override
	public void pack(Packer pk, Object obj) throws IOException
	{
		if(obj == null) {
			pk.packNil();
			return;
		}
		byte[] d = (byte[])obj;
		pk.packRaw(d.length);
		pk.packRawBody(d);
	}

	@Override
	public Object convert(GenericObject obj)
	{
		return obj.asBytes();
	}

	@Override
	public Object createRaw(byte[] b, int offset, int length)
	{
		byte[] d = new byte[length];
		System.arraycopy(b, offset, d, 0, length);
		return d;
	}
}