Created
September 25, 2010 05:40
-
-
Save frsyuki/596519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package serializers.thrift; | |
import java.io.IOException; | |
import org.msgpack.Packer; | |
import org.msgpack.Unpacker; | |
import org.msgpack.MessagePackable; | |
import org.msgpack.MessageUnpackable; | |
import org.msgpack.MessageConvertable; | |
import org.msgpack.MessageTypeException; | |
public enum Size implements MessagePackable, MessageUnpackable, MessageConvertable { | |
SMALL(0), | |
LARGE(1), | |
; | |
private int value; | |
private Size() { | |
this.value = 0; | |
} | |
private Size(int value) { | |
this.value = value; | |
} | |
public int getValue() { | |
return value; | |
} | |
public void messagePack(Packer pk) throws IOException { | |
pk.packInt(this.value); | |
} | |
public void messageUnpack(Unpacker pac) throws IOException, MessageTypeException { | |
int val = pac.unpackInt(); | |
switch(val) { | |
case 0: | |
case 1: | |
this.value = val; | |
break; | |
default: | |
throw new MessageTypeException(); | |
} | |
} | |
public void messageConvert(Object obj) throws MessageTypeException { | |
if(!(obj instanceof Number)) { | |
throw new MessageTypeException(); | |
} | |
int val = ((Number)obj).intValue(); | |
switch(val) { | |
case 0: | |
case 1: | |
this.value = val; | |
break; | |
default: | |
throw new MessageTypeException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment