mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-26 11:46:34 +01:00
java: adds MessagePackObject class 2
This commit is contained in:
parent
1621a68191
commit
02ae247536
@ -23,7 +23,7 @@ import org.msgpack.*;
|
||||
class BigIntegerTypeIMPL extends IntegerType {
|
||||
private BigInteger value;
|
||||
|
||||
BigIntegerTypeIMPL(BigInteger vlaue) {
|
||||
BigIntegerTypeIMPL(BigInteger value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class BooleanType extends MessagePackObject {
|
||||
|
||||
@Override
|
||||
public boolean isBooleanType() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ import org.msgpack.*;
|
||||
class DoubleTypeIMPL extends FloatType {
|
||||
private double value;
|
||||
|
||||
public DoubleTypeIMPL(double vlaue) {
|
||||
public DoubleTypeIMPL(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -24,5 +24,13 @@ public abstract class FloatType extends MessagePackObject {
|
||||
public boolean isFloatType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static FloatType create(float value) {
|
||||
return new FloatTypeIMPL(value);
|
||||
}
|
||||
|
||||
public static FloatType create(double value) {
|
||||
return new DoubleTypeIMPL(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import org.msgpack.*;
|
||||
class FloatTypeIMPL extends FloatType {
|
||||
private float value;
|
||||
|
||||
public FloatTypeIMPL(float vlaue) {
|
||||
public FloatTypeIMPL(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,11 @@ import java.math.BigInteger;
|
||||
import org.msgpack.*;
|
||||
|
||||
public abstract class IntegerType extends MessagePackObject {
|
||||
@Override
|
||||
public boolean isIntegerType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IntegerType create(byte value) {
|
||||
return new ShortIntegerTypeIMPL((int)value);
|
||||
}
|
||||
@ -40,10 +45,5 @@ public abstract class IntegerType extends MessagePackObject {
|
||||
public static IntegerType create(BigInteger value) {
|
||||
return new BigIntegerTypeIMPL(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntegerType() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ import java.util.Map;
|
||||
import org.msgpack.*;
|
||||
|
||||
public class MapType extends MessagePackObject {
|
||||
MessagePackObject[] map;
|
||||
private MessagePackObject[] map;
|
||||
|
||||
public MapType(MessagePackObject[] map) {
|
||||
this.map = map;
|
||||
@ -30,7 +30,7 @@ public class MapType extends MessagePackObject {
|
||||
|
||||
@Override
|
||||
public boolean isMapType() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
48
java/src/main/java/org/msgpack/object/RawType.java
Normal file
48
java/src/main/java/org/msgpack/object/RawType.java
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// 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.object;
|
||||
|
||||
import org.msgpack.*;
|
||||
|
||||
class RawType extends MessagePackObject {
|
||||
private byte[] bytes;
|
||||
|
||||
public RawType(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRawType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
try {
|
||||
return new String(bytes, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
throw new MessageTypeException("type error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user