1 package org.simantics.databoard.serialization.impl;
3 import java.io.DataInput;
4 import java.io.DataOutput;
5 import java.io.IOException;
7 import org.simantics.databoard.binding.BooleanBinding;
8 import org.simantics.databoard.binding.error.BindingException;
9 import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
11 public class BooleanSerializer extends NonRecursiveSerializer {
13 BooleanBinding binding;
15 public BooleanSerializer(BooleanBinding binding) {
16 this.binding = binding;
20 public Object deserialize(DataInput in) throws IOException {
22 boolean value = in.readByte() != 0;
23 return binding.create(value);
24 } catch (BindingException e) {
25 throw new IOException( e );
30 public void deserializeTo(DataInput in, Object obj) throws IOException {
32 boolean newValue = in.readByte() != 0;
33 binding.setValue(obj, newValue);
34 } catch (BindingException e) {
35 throw new IOException( e );
40 public void skip(DataInput in)
46 public void serialize(DataOutput out, Object obj) throws IOException {
48 boolean value = binding.getValue_(obj);
49 out.write( (byte) (value ? 1 : 0) );
50 } catch (BindingException e) {
51 throw new IOException( e );
56 public Integer getConstantSize() {
61 public int getSize(Object obj) {
66 public int getMinSize() {
70 public boolean getBoolean(DataInput in) throws IOException
72 return in.readByte() != 0;
75 public void putBoolean(DataOutput out, boolean x) throws IOException