mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-22 16:33:49 +01:00
java: adds templates for primitive types
This commit is contained in:
parent
002b86198c
commit
0a41b253f3
@ -33,15 +33,52 @@ public class Templates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final Template TString = StringTemplate.getInstance();
|
public static final Template TByte = ByteTemplate.getInstance();
|
||||||
|
public static Template tByte() {
|
||||||
|
return TByte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TShort = ShortTemplate.getInstance();
|
||||||
|
public static Template tShort() {
|
||||||
|
return TShort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TInteger = IntegerTemplate.getInstance();
|
||||||
|
public static Template tInteger() {
|
||||||
|
return TInteger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TLong = LongTemplate.getInstance();
|
||||||
|
public static Template tLong() {
|
||||||
|
return TLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TBigInteger = BigIntegerTemplate.getInstance();
|
||||||
|
public static Template tBigInteger() {
|
||||||
|
return TBigInteger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TFloat = FloatTemplate.getInstance();
|
||||||
|
public static Template tFloat() {
|
||||||
|
return TFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TDouble = DoubleTemplate.getInstance();
|
||||||
|
public static Template tDouble() {
|
||||||
|
return TDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TBoolean = BooleanTemplate.getInstance();
|
||||||
|
public static Template tBoolean() {
|
||||||
|
return TBoolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Template TString = StringTemplate.getInstance();
|
||||||
public static Template tString() {
|
public static Template tString() {
|
||||||
return TString;
|
return TString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final Template TByteArray = ByteArrayTemplate.getInstance();
|
public static final Template TByteArray = ByteArrayTemplate.getInstance();
|
||||||
|
|
||||||
public static Template tByteArray() {
|
public static Template tByteArray() {
|
||||||
return TByteArray;
|
return TByteArray;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class BigIntegerTemplate implements Template {
|
||||||
|
private BigIntegerTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackBigInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asBigInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public BigIntegerTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final BigIntegerTemplate instance = new BigIntegerTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(BigInteger.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/BooleanTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/BooleanTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class BooleanTemplate implements Template {
|
||||||
|
private BooleanTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public BooleanTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final BooleanTemplate instance = new BooleanTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Boolean.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/ByteTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/ByteTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class ByteTemplate implements Template {
|
||||||
|
private ByteTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public ByteTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ByteTemplate instance = new ByteTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Byte.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/DoubleTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/DoubleTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class DoubleTemplate implements Template {
|
||||||
|
private DoubleTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public DoubleTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final DoubleTemplate instance = new DoubleTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Double.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/FloatTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/FloatTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class FloatTemplate implements Template {
|
||||||
|
private FloatTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public FloatTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final FloatTemplate instance = new FloatTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Float.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/IntegerTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/IntegerTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class IntegerTemplate implements Template {
|
||||||
|
private IntegerTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public IntegerTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final IntegerTemplate instance = new IntegerTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Integer.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/LongTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/LongTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class LongTemplate implements Template {
|
||||||
|
private LongTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LongTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final LongTemplate instance = new LongTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Long.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
java/src/main/java/org/msgpack/template/ShortTemplate.java
Normal file
44
java/src/main/java/org/msgpack/template/ShortTemplate.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class ShortTemplate implements Template {
|
||||||
|
private ShortTemplate() { }
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
return pac.unpackShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
return from.asShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public ShortTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ShortTemplate instance = new ShortTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CustomMessage.registerTemplate(Short.class, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ public class TestReflectionPackerTemplate {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPackConvert() throws Exception {
|
public void testPackConvert() throws Exception {
|
||||||
tString();
|
tString(); // FIXME link StringTemplate
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user