Class AsnType

java.lang.Object
org.asnlab.asndt.runtime.type.AsnType
All Implemented Interfaces:
EncodingRules, org.asnlab.asndt.runtime.type.Constants

public abstract class AsnType extends Object implements org.asnlab.asndt.runtime.type.Constants, EncodingRules
Instances of the class AsnType represent the metadata of ASN.1 type. The metadata type is independent of any concrete value which may be represent by anything. Value object is related to metadata type by means of AsnConverter.

The following example uses a AsnType object and a AsnConverter to encode a value object:

     object = ...
     type = ...
     converter = ...
     type.encode(object, buffer, converter);
 
Since:
3.0
Version:
3.14159
Author:
Ryan
  • Field Details

  • Constructor Details

    • AsnType

      public AsnType()
  • Method Details

    • getTypeId

      public abstract int getTypeId()
      Return the id of this type
      Returns:
      The type id
    • getXmlTag

      public String getXmlTag(AsnConverter converter)
    • nativeName

      public abstract String nativeName()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • encode

      public byte[] encode(Object object, AsnConverter converter)
      Encode object into byte array using UNALIGNED_PACKED_ENCODING_RULES
      Parameters:
      object - The object to encode
      converter - The ASN.1 object converter
      Returns:
      The byte array of encoding result
    • decode

      public Object decode(byte[] content, AsnConverter converter)
      Decode object from byte array using UNALIGNED_PACKED_ENCODING_RULES
      Parameters:
      content - The encoding content to decode
      converter - The ASN.1 object converter
      Returns:
      The decoding result
    • encode

      public byte[] encode(Object object, byte encodingRules, AsnConverter converter)
      Encode object into byte array
      Parameters:
      object - The object to encode
      encodingRules - The encoding rules
      converter - The ASN.1 object converter
      Returns:
      The byte array of encoding result
    • decode

      public Object decode(byte[] content, byte encodingRules, AsnConverter converter)
      Decode object from byte array
      Parameters:
      content - The encoding content to decode
      encodingRules - The encoding rules
      converter - The ASN.1 object converter
      Returns:
      The decoding result
    • encode

      public void encode(Object object, byte encodingRules, AsnConverter converter, OutputStream out) throws IOException
      Encode the object into output stream
      Parameters:
      object - The object to encode
      encodingRules - The encoding rules
      converter - The converter specific to the object
      out - The output stream to encode into
      Throws:
      IOException - If error in writing to output stream
    • decode

      public Object decode(InputStream in, byte encodingRules, AsnConverter converter) throws IOException
      Decode the object from input stream
      Parameters:
      in - The input stream to decode from
      encodingRules - The encoding rules
      converter - The converter specific to the object
      Returns:
      The decoded object
      Throws:
      IOException - If error in reading from input stream
    • encode

      public void encode(Object object, Buffer buffer, AsnConverter converter)
      Encode the object into buffer. The buffer will be flipped.
      Parameters:
      object - The object to encode
      buffer - The working buffer
      converter - The converter specific to the object
    • decode

      public Object decode(Buffer buffer, AsnConverter converter)
      Decode object from buffer.
      Parameters:
      buffer - The working buffer
      converter - The object specific converter
      Returns:
      The decoded object
    • encode

      protected abstract void encode(Object object, org.asnlab.asndt.runtime.type.Codec codec, AsnConverter converter)
    • decode

      protected abstract Object decode(org.asnlab.asndt.runtime.type.Codec codec, AsnConverter converter)
    • realType

      protected AsnType realType()
    • computeConverter

      public AsnConverter computeConverter()
      Return the "generic" AsnConverter for this ASN.1 type
      Returns:
      the "generic" AsnConverter for this ASN.1 type
    • computeConverter

      protected abstract AsnConverter computeConverter(Hashtable<Object,Object> dejavu)
    • clone

      public Object clone(Object object, AsnConverter converter)
      Clone a copy of the object
      Parameters:
      object - The object to clone
      converter - The object specific converter
      Returns:
      The cloned object
    • equals

      public boolean equals(Object o1, Object o2, AsnConverter converter)
      Tells whether the two objects o1, o2 is equal from the point of view of ASN.1.
      Parameters:
      o1 - The 1st object
      o2 - The 2nd object
      converter - The metadata converter
      Returns:
      true if, and only if, two objects equal to each other.
    • equals

      public boolean equals(Object o1, Object o2, AsnConverter c1, AsnConverter c2)
      Tells whether the two objects o1, o2 is equal from the point of view of ASN.1.
      Parameters:
      o1 - The 1st object
      o2 - The 2nd object
      c1 - The 1st converter
      c2 - The 2nd converter
      Returns:
      true if, and only if, two objects equal to each other.
    • print

      public PrintStream print(Object object, AsnConverter converter, PrintStream out)
      Print out the readable message of this object.
      Parameters:
      object - The object to print
      converter - The converter specific to the object
      out - The output print stream
      Returns:
      The PrintStream
    • print

      public PrintStream print(Object object, AsnConverter converter, PrintStream out, boolean trimNulls)
      Print out the readable message of this object.
      Parameters:
      object - The object to print
      converter - The converter specific to the object
      out - The output print stream
      trimNulls - Whether trim nulls in the output
      Returns:
      The PrintStream
    • json

      public PrintStream json(Object object, AsnConverter converter, PrintStream out)
    • encodeTag

      public static int encodeTag(short tagClass, short tagForm, int tagNumber)
    • decodeTag

      public static int[] decodeTag(int tag)
    • getTag

      public abstract int getTag(Object object, AsnConverter converter)
    • short2bytes

      protected static byte[] short2bytes(short number)
    • int2bytes

      protected static byte[] int2bytes(int number)
    • unsignedint2bytes

      protected static byte[] unsignedint2bytes(int number)
    • long2bytes

      protected static byte[] long2bytes(long number)
    • unsignedlong2bytes

      protected static byte[] unsignedlong2bytes(long number)
    • bytes2unsignedlong

      protected static long bytes2unsignedlong(byte[] bytes)
    • unsignint2seplets

      protected static byte[] unsignint2seplets(int value)
    • numOfBytes

      protected static int numOfBytes(short number)
    • numOfBytes

      protected static int numOfBytes(int number)
    • numOfBytes

      protected static int numOfBytes(long number)
    • numOfOcts

      protected static int numOfOcts(int n)
    • numOfOcts

      protected static int numOfOcts(long n)
    • numOfBits

      protected static int numOfBits(int n)
    • numOfBits

      protected static int numOfBits(long n)
    • toHexString

      public static String toHexString(byte[] octets)
    • toHexString

      public static String toHexString(byte[] octets, String separator)
    • parseHexString

      public static byte[] parseHexString(String hex)