From e023e674020f1a435f7b8c8b9276704f576ea6e5 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:08:45 +0200 Subject: structure change 1 --- .../org/uic/barcode/asn1/uper/BooleanCoder.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/org/uic/barcode/asn1/uper/BooleanCoder.java (limited to 'src/main/java/org/uic/barcode/asn1/uper/BooleanCoder.java') diff --git a/src/main/java/org/uic/barcode/asn1/uper/BooleanCoder.java b/src/main/java/org/uic/barcode/asn1/uper/BooleanCoder.java new file mode 100644 index 0000000..3bd7a38 --- /dev/null +++ b/src/main/java/org/uic/barcode/asn1/uper/BooleanCoder.java @@ -0,0 +1,35 @@ +package org.uic.barcode.asn1.uper; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +class BooleanCoder implements Decoder, Encoder { + + @Override public boolean canEncode(T obj, Annotation[] extraAnnotations) { + return obj instanceof Boolean; + } + + @Override public void encode(BitBuffer bitbuffer, T obj, Annotation[] extraAnnotations) { + UperEncoder.logger.debug(String.format("BOOLEAN %s", obj)); + bitbuffer.put((Boolean) obj); + } + + @Override public boolean canDecode(Class classOfT, Annotation[] extraAnnotations) { + return Boolean.class.isAssignableFrom(classOfT) + || boolean.class.isAssignableFrom(classOfT); + } + + @SuppressWarnings("unchecked") + @Override public T decode(BitBuffer bitbuffer, + Class classOfT, Field field, + Annotation[] extraAnnotations) { + Boolean result = new Boolean(bitbuffer.get()); + UperEncoder.logger.debug(String.format("BOOL: decoded as %s",result)); + return (T) result; + } + + @Override + public T getDefault(Class classOfT, Annotation[] extraAnnotations) { + throw new IllegalArgumentException("Default Boolean not yet implemented"); + } +} \ No newline at end of file -- cgit v1.2.3