Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created September 25, 2010 05:40
Show Gist options
  • Save frsyuki/596519 to your computer and use it in GitHub Desktop.
Save frsyuki/596519 to your computer and use it in GitHub Desktop.
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