mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 18:29:53 +00:00
import MessagePack for Java implementation plan 2
This commit is contained in:
parent
93a95725fc
commit
e39e1d4f60
48 changed files with 3676 additions and 0 deletions
48
java-plan2/src/org/msgpack/schema/StringSchema.java
Normal file
48
java-plan2/src/org/msgpack/schema/StringSchema.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package org.msgpack.schema;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import org.msgpack.*;
|
||||
|
||||
public class StringSchema extends Schema {
|
||||
public StringSchema()
|
||||
{
|
||||
super("string");
|
||||
}
|
||||
|
||||
public String getFullName()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pack(Packer pk, Object obj) throws IOException
|
||||
{
|
||||
if(obj == null) {
|
||||
pk.packNil();
|
||||
return;
|
||||
}
|
||||
String s = (String)obj;
|
||||
byte[] d = s.getBytes("UTF-8");
|
||||
pk.packRaw(d.length);
|
||||
pk.packRawBody(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(GenericObject obj)
|
||||
{
|
||||
return obj.asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createRaw(byte[] b, int offset, int length)
|
||||
{
|
||||
try {
|
||||
return new String(b, offset, length, "UTF-8"); // XXX FIXME debug
|
||||
} catch (Exception e) {
|
||||
// FIXME
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue