]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/serialization/impl/ByteSerializer.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / serialization / impl / ByteSerializer.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.ByteBinding;
8 import org.simantics.databoard.binding.error.BindingException;
9 import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
10
11 public class ByteSerializer extends NonRecursiveSerializer {
12
13         ByteBinding binding;
14         
15         public ByteSerializer(ByteBinding binding) {
16                 this.binding = binding;
17         }
18         
19         @Override
20         public Object deserialize(DataInput in) throws IOException {
21                 try {
22                         byte value = in.readByte();
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                         binding.setValue(obj, in.readByte());
33                 } catch (BindingException e) {
34                         throw new IOException( e ); 
35                 }
36         }
37
38         @Override
39         public void skip(DataInput in)
40                         throws IOException {
41                 in.skipBytes(1);                        
42         }
43         
44         @Override
45         public void serialize(DataOutput out, Object obj) throws IOException {
46                 try {
47                         byte value = binding.getValue_(obj);
48                         out.write(value);
49                 } catch (BindingException e) {
50                         throw new IOException( e ); 
51                 }
52         }
53
54         @Override
55         public Integer getConstantSize() {
56                 return 1;
57         }
58
59         @Override
60         public int getSize(Object obj) {
61                 return 1;
62         }       
63         
64         @Override
65         public int getMinSize() {
66                 return 1;
67         }
68         
69         public byte getByte(DataInput in) throws IOException
70         {
71                 return in.readByte();
72         }
73         
74         public void putByte(DataOutput out, byte x) throws IOException
75         {
76                 out.writeByte(x);
77         }
78         
79         
80 }