Skip to content

Commit

Permalink
Implemented the encode method for the SelectFromCode
Browse files Browse the repository at this point in the history
  • Loading branch information
jdl17 committed Jul 29, 2015
1 parent 52c21c0 commit c811a9b
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
import org.codehaus.preon.descriptor.Documenters;
import org.codehaus.preon.el.*;

import java.io.IOException;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -152,8 +155,22 @@ public T decode(BitBuffer buffer, Resolver resolver, Builder builder)
}
}

public void encode(T value, BitChannel channel, Resolver resolver) {
throw new UnsupportedOperationException();
public void encode(T value, BitChannel channel, Resolver resolver) throws IOException {
if (prefixSize <= 0) {
for (int i = 0; i < conditions.size(); i++) {
if (conditions.get(i).eval(resolver)) {
Codec<T> c = (Codec<T>) codecs.get(i);
c.encode(value, channel, resolver);
return;
}
}
}
if (defaultCodec != null) {
Codec<T> c = (Codec<T>) defaultCodec;
c.encode(value, channel, resolver);
} else {
throw new UnsupportedOperationException();
}
}

public Expression<Integer, Resolver> getSize() {
Expand Down

0 comments on commit c811a9b

Please sign in to comment.