]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/serialization/impl/BooleanSerializer.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / serialization / impl / BooleanSerializer.java
1 package org.simantics.databoard.serialization.impl;
2
3 import java.io.DataInput;
4 import java.io.DataOutput;
5 import java.io.IOException;
6
7 import org.simantics.databoard.binding.BooleanBinding;
8 import org.simantics.databoard.binding.error.BindingException;
9 import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
10
11 public class BooleanSerializer extends NonRecursiveSerializer {
12
13         BooleanBinding binding;
14         
15         public BooleanSerializer(BooleanBinding binding) {
16                 this.binding = binding;
17         }
18         
19         @Override
20         public Object deserialize(DataInput in) throws IOException {
21                 try {
22                         boolean value = in.readByte() != 0; 
23                         return binding.create(value);
24                 } catch (BindingException e) {
25                         throw new IOException( e ); 
26                 }
27         }
28         
29         @Override
30         public void deserializeTo(DataInput in, Object obj) throws IOException {
31                 try {
32                         boolean newValue = in.readByte() != 0; 
33                         binding.setValue(obj, newValue);
34                 } catch (BindingException e) {
35                         throw new IOException( e ); 
36                 }
37         }
38         
39         @Override
40         public void skip(DataInput in)
41                         throws IOException {
42                 in.skipBytes(1);                        
43         }
44
45         @Override
46         public void serialize(DataOutput out, Object obj) throws IOException {
47                 try {
48                         boolean value = binding.getValue_(obj);
49                         out.write( (byte) (value ? 1 : 0) );
50                 } catch (BindingException e) {
51                         throw new IOException( e ); 
52                 }
53         }
54
55         @Override
56         public Integer getConstantSize() {
57                 return 1;
58         }
59
60         @Override
61         public int getSize(Object obj) {
62                 return 1;
63         }
64
65         @Override
66         public int getMinSize() {
67                 return 1;
68         }
69         
70         public boolean getBoolean(DataInput in) throws IOException
71         {
72                 return in.readByte() != 0;
73         }
74         
75         public void putBoolean(DataOutput out, boolean x) throws IOException
76         {
77                 out.writeBoolean(x);
78         }
79         
80 }