Class BitStringConverter

java.lang.Object
org.asnlab.asndt.runtime.conv.AsnConverter
org.asnlab.asndt.runtime.conv.BitStringConverter
Direct Known Subclasses:
BitSetConverter, ReflectionBitStringConverter

public abstract class BitStringConverter extends AsnConverter
The BitStringConverter can convert BitString to ASN.1 recognized values and vice versa.

The following is an example customize the BitStringConverter to convert an array of boolean to and from ASN.1 recognized values.

 public class MyBitStringConverter extends BitStringConverter {
 
                public Object createObject(byte[] bytes, byte unusedBits) {
                        BitString bitString = new BitString(bytes, unusedBits);
                        int size = bytes.length*8-unusedBits;
                        boolean[] array = new boolean[size];
                        for(int i=0; i<size; i++) {
                                array[i] = bitString.getBit(i);
                        }
                        return array;
                }

                public byte[] getBytes(Object object) {
                        boolean[] array = (boolean[]) object;
                        BitString bitString = new BitString(array.length);
                        for(int i=0; i<size; i++) {
                                bitString.setBit(i, array[i]);
                        }
                        return bitString.bytes;
                }
 
                public byte getUnusedBits(Object object) {
                        boolean[] array = (boolean[]) object;
                        if(array.length%8==0) {
                                return 0;
                        }
                        else {
                                return (8-array.length%8);
                        }
                }
 
 }
 
  • Field Details

  • Constructor Details

    • BitStringConverter

      public BitStringConverter()
  • Method Details

    • createObject

      public abstract Object createObject(byte[] bytes, byte unusedBits)
    • getBytes

      public byte[] getBytes(org.asnlab.asndt.runtime.type.BitStringType type, Object object)
      Return the bytes of the BIT STRING value
      Parameters:
      object - The BIT STRING value
      Returns:
      The bytes of the BIT STRING value
    • getUnusedBits

      public byte getUnusedBits(org.asnlab.asndt.runtime.type.BitStringType type, Object object)
      Return the unused bits of the BIT STRING value
      Parameters:
      object - The BIT STRING value
      Returns:
      The unused bits of the BIT STRING value