Package org.asnlab.asndt.runtime.conv
Class BitStringConverter
java.lang.Object
org.asnlab.asndt.runtime.conv.AsnConverter
org.asnlab.asndt.runtime.conv.BitStringConverter
- Direct Known Subclasses:
BitSetConverter
,ReflectionBitStringConverter
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Object
createObject
(byte[] bytes, byte unusedBits) byte[]
Return the bytes of the BIT STRING valuebyte
getUnusedBits
(org.asnlab.asndt.runtime.type.BitStringType type, Object object) Return the unused bits of the BIT STRING valueMethods inherited from class org.asnlab.asndt.runtime.conv.AsnConverter
isAnonymous
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
BitStringConverter
public BitStringConverter()
-
-
Method Details
-
createObject
-
getBytes
Return the bytes of the BIT STRING value- Parameters:
object
- The BIT STRING value- Returns:
- The bytes of the BIT STRING value
-
getUnusedBits
Return the unused bits of the BIT STRING value- Parameters:
object
- The BIT STRING value- Returns:
- The unused bits of the BIT STRING value
-