]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/serialization/impl/IntSerializer.java
Add qualifier for SLF4J version to force update of JAR in TP
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / serialization / impl / IntSerializer.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.IntegerBinding;
8 import org.simantics.databoard.binding.error.BindingException;
9 import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
10
11 public class IntSerializer  extends NonRecursiveSerializer {
12
13         IntegerBinding binding;
14         
15         public IntSerializer(IntegerBinding binding) { this.binding = binding; }
16         
17         @Override
18         public Object deserialize(DataInput in) throws IOException {
19                 try {
20                         int value = in.readInt();
21                         return binding.create(value);
22                 } catch (BindingException e) {
23                         throw new IOException( e ); 
24                 }
25         }
26         
27         @Override
28         public void deserializeTo(DataInput in, Object obj) throws IOException {
29                 try {
30                         binding.setValue(obj, in.readInt());
31                 } catch (BindingException e) {
32                         throw new IOException( e ); 
33                 }
34         }
35         
36         @Override
37         public void skip(DataInput in)
38                         throws IOException {
39                 in.skipBytes(4);                        
40         }
41
42         @Override
43         public void serialize(DataOutput out, Object obj) throws IOException {
44                 try {
45                         int value = binding.getValue_(obj);
46                         out.writeInt(value);
47                 } catch (BindingException e) {
48                         throw new IOException( e ); 
49                 }
50         }
51
52         @Override
53         public Integer getConstantSize() {
54                 return 4;
55         }
56
57         @Override
58         public int getSize(Object obj) {
59                 return 4;
60         }
61         
62         @Override
63         public int getMinSize() {
64                 return 4;
65         }
66         
67         public int getInt(DataInput in) throws IOException
68         {
69                 return in.readInt();
70         }
71         
72         public void putInt(DataOutput out, int x) throws IOException
73         {
74                 out.writeInt(x);
75         }
76         
77         
78 }