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