org.asnlab.asndt.runtime.type
Class AsnType

java.lang.Object
  extended by org.asnlab.asndt.runtime.type.AsnType
All Implemented Interfaces:
EncodingRules

public abstract class AsnType
extends java.lang.Object
implements 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.14
Author:
Ryan

Field Summary
static boolean DEBUG
           
static java.lang.String VERSION
           
 
Fields inherited from interface org.asnlab.asndt.runtime.conv.EncodingRules
ALIGNED_PACKED_ENCODING_RULES, BASIC_ENCODING_RULES, CANONICAL_ENCODING_RULES, DISTINGUISHED_ENCODING_RULES, UNALIGNED_PACKED_ENCODING_RULES
 
Constructor Summary
AsnType()
           
 
Method Summary
 java.lang.Object clone(java.lang.Object object, AsnConverter converter)
          Clone a copy of the object
static AsnConverter createAsnTypeConverter()
           
static AsnType createAsnTypeType()
           
 java.lang.Object decode(Buffer buffer, AsnConverter converter)
          Decode object from buffer.
 java.lang.Object decode(byte[] content, AsnConverter converter)
          Decode object from byte array using UNALIGNED_PACKED_ENCODING_RULES
 java.lang.Object decode(byte[] content, byte encodingRules, AsnConverter converter)
          Decode object from byte array
 java.lang.Object decode(java.io.InputStream in, byte encodingRules, AsnConverter converter)
          Decode the object from input stream
protected  byte[] decodeRawdata(org.asnlab.asndt.runtime.type.BitBuffer buffer)
           
 byte[] encode(java.lang.Object object, AsnConverter converter)
          Encode object into byte array using UNALIGNED_PACKED_ENCODING_RULES
 void encode(java.lang.Object object, Buffer buffer, AsnConverter converter)
          Encode the object into buffer.
 byte[] encode(java.lang.Object object, byte encodingRules, AsnConverter converter)
          Encode object into byte array
 void encode(java.lang.Object object, byte encodingRules, AsnConverter converter, java.io.OutputStream out)
          Encode the object into output stream
protected  void encodeRawdata(org.asnlab.asndt.runtime.type.BitBuffer buffer, byte[] rawdata)
           
static int encodeTag(short tagClass, short tagForm, int tagNumber)
          Encode the tag
 boolean equals(java.lang.Object o1, java.lang.Object o2, AsnConverter converter)
          Tells whether the two objects o1, o2 is equal from the point of view of ASN.1.
 boolean equals(java.lang.Object o1, java.lang.Object o2, AsnConverter c1, AsnConverter c2)
          Tells whether the two objects o1, o2 is equal from the point of view of ASN.1.
abstract  AsnConverter getGenericConverter()
          Return the "generic" AsnConverter for this metadata type
abstract  int getTypeId()
          Return the id of this type
protected static byte[] int2bytes(int number)
           
protected static byte[] long2bytes(long number)
           
protected static int numOfBits(int n)
           
protected static int numOfBits(long n)
           
protected static int numOfBytes(int number)
           
protected static int numOfBytes(long number)
           
protected static int numOfBytes(short number)
           
protected static int numOfOcts(int n)
           
protected static int numOfOcts(long n)
           
 java.io.PrintStream print(java.lang.Object object, AsnConverter converter, java.io.PrintStream out)
          Print out the readable message of this object.
protected static byte[] short2bytes(short number)
           
protected  void skipTLV(org.asnlab.asndt.runtime.type.ByteBuffer buffer, int tag)
           
static java.lang.String toHexString(byte[] octets)
           
protected static byte[] unsignedint2bytes(int number)
           
protected static byte[] unsignedlong2bytes(long number)
           
protected static byte[] unsignint2seplets(int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

DEBUG

public static boolean DEBUG
Constructor Detail

AsnType

public AsnType()
Method Detail

getTypeId

public abstract int getTypeId()
Return the id of this type

Returns:
The type id

encode

public byte[] encode(java.lang.Object object,
                     AsnConverter converter)
Encode object into byte array using UNALIGNED_PACKED_ENCODING_RULES

Parameters:
object - The object to encode
converter - The ASN.1 metadata converter

decode

public java.lang.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 metadata converter

encode

public byte[] encode(java.lang.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 metadata converter

decode

public java.lang.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 metadata converter

encode

public void encode(java.lang.Object object,
                   byte encodingRules,
                   AsnConverter converter,
                   java.io.OutputStream out)
            throws java.io.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:
java.io.IOException - If error in writing to output stream

decode

public java.lang.Object decode(java.io.InputStream in,
                               byte encodingRules,
                               AsnConverter converter)
                        throws java.io.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:
java.io.IOException - If error in reading from input stream

encode

public void encode(java.lang.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 java.lang.Object decode(Buffer buffer,
                               AsnConverter converter)
Decode object from buffer.

Parameters:
buffer - The working buffer
converter - The object specific converter
Returns:
The decoded object

skipTLV

protected void skipTLV(org.asnlab.asndt.runtime.type.ByteBuffer buffer,
                       int tag)

encodeRawdata

protected void encodeRawdata(org.asnlab.asndt.runtime.type.BitBuffer buffer,
                             byte[] rawdata)

decodeRawdata

protected byte[] decodeRawdata(org.asnlab.asndt.runtime.type.BitBuffer buffer)

getGenericConverter

public abstract AsnConverter getGenericConverter()
Return the "generic" AsnConverter for this metadata type

Returns:
the "generic" AsnConverter for this metadata type

clone

public java.lang.Object clone(java.lang.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(java.lang.Object o1,
                      java.lang.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(java.lang.Object o1,
                      java.lang.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 java.io.PrintStream print(java.lang.Object object,
                                 AsnConverter converter,
                                 java.io.PrintStream out)
Print out the readable message of this object.

Parameters:
object - The object to encode
converter - The converter specific to the object
out - The output print stream

encodeTag

public static int encodeTag(short tagClass,
                            short tagForm,
                            int tagNumber)
Encode the tag


createAsnTypeType

public static AsnType createAsnTypeType()

createAsnTypeConverter

public static AsnConverter createAsnTypeConverter()

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)

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 java.lang.String toHexString(byte[] octets)


Copyright �2009-2012 ASN Lab