diff --git a/lib/java/se/lth/control/labcomm/EncoderChannel.java b/lib/java/se/lth/control/labcomm/EncoderChannel.java index 5949b1af117e3f349d0e8ce6b85a3fbca0c57bef..08f9c87074c6d675d3cb08fd397d481f708e1726 100644 --- a/lib/java/se/lth/control/labcomm/EncoderChannel.java +++ b/lib/java/se/lth/control/labcomm/EncoderChannel.java @@ -27,16 +27,19 @@ public class EncoderChannel implements Encoder { } public void register(SampleDispatcher dispatcher) throws IOException { - int index = def_registry.add(dispatcher); - begin(Constant.SAMPLE_DEF); - encodePacked32(index); - encodeString(dispatcher.getName()); - byte[] signature = dispatcher.getSignature(); - encodePacked32(signature.length); - for (int i = 0 ; i < signature.length ; i++) { - encodeByte(signature[i]); + if(dispatcher.getTypeDeclTag() == Constant.SAMPLE_DEF) { + int index = def_registry.add(dispatcher); + //begin(Constant.SAMPLE_DEF); + begin(dispatcher.getTypeDeclTag()); + encodePacked32(index); + encodeString(dispatcher.getName()); + byte[] signature = dispatcher.getSignature(); + encodePacked32(signature.length); + for (int i = 0 ; i < signature.length ; i++) { + encodeByte(signature[i]); + } + end(null); } - end(null); } public void registerSampleRef(SampleDispatcher dispatcher) throws IOException { diff --git a/lib/java/se/lth/control/labcomm/SampleDispatcher.java b/lib/java/se/lth/control/labcomm/SampleDispatcher.java index a8788284d2c5584e8177ab09bf64d7e4e55cdb3d..8870349ed3edbe05c0133c79d04964d6cd2babeb 100644 --- a/lib/java/se/lth/control/labcomm/SampleDispatcher.java +++ b/lib/java/se/lth/control/labcomm/SampleDispatcher.java @@ -11,5 +11,11 @@ public interface SampleDispatcher <T> { public void decodeAndHandle(Decoder decoder, SampleHandler handler) throws Exception; + /** return the tag SAMPLE_DEF or TYPE_DEF, for use + * by encoder.register. + * TODO: refactor types, moving this to a super-interface + * applicable to both type and sample defs. + */ + public byte getTypeDeclTag(); } diff --git a/lib/python/labcomm/LabComm.py b/lib/python/labcomm/LabComm.py index c45e705dcd1e18e7640bdb23212e6afc25fcdea7..c4b353c63d7c73994249ab4ab6221276f3a4d121 100644 --- a/lib/python/labcomm/LabComm.py +++ b/lib/python/labcomm/LabComm.py @@ -848,7 +848,7 @@ class Decoder(Codec): decl = self.index_to_decl[index].decode_decl(self) value = None elif index < i_USER: - raise exception("Invalid type index %d" % index) + raise Exception("Invalid type index %d" % index) else: decl = self.index_to_decl[index] value = decl.decode(self)