Commit b53197ab authored by Adam Knapp's avatar Adam Knapp
Browse files

Lengthto codegen and runtime update for bit/octetstring (issue #419)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent aad72e28
......@@ -15,6 +15,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.titan.runtime.core.BER.ASN_BERdescriptor;
import org.eclipse.titan.runtime.core.BER.ASN_Tag;
import org.eclipse.titan.runtime.core.BER.ASN_TagClass;
import org.eclipse.titan.runtime.core.Base_Type.TTCN_Typedescriptor;
import org.eclipse.titan.runtime.core.JSON.TTCN_JSONdescriptor;
import org.eclipse.titan.runtime.core.JSON.json_string_escaping;
import org.eclipse.titan.runtime.core.JSON_Tokenizer.json_token_t;
......@@ -290,10 +291,16 @@ public class TitanBitString extends Base_Type {
return this;
}
public TitanBitString operator_assign(final TitanInteger otherValue) {
return operator_assign(AdditionalFunctions.int2bit(otherValue, n_bits));
}
@Override
public TitanBitString operator_assign(final Base_Type otherValue) {
if (otherValue instanceof TitanBitString) {
return operator_assign((TitanBitString)otherValue);
} else if (otherValue instanceof TitanInteger) {
return operator_assign((TitanInteger)otherValue);
}
throw new TtcnError(MessageFormat.format("Internal Error: value `{0}'' can not be cast to bitstring", otherValue));
......@@ -1525,4 +1532,23 @@ public class TitanBitString extends Base_Type {
public static TitanBitString convert_to_BitString(final TitanBitString_Element otherValue) {
return new TitanBitString(otherValue);
}
/**
* Based on the specified type descriptor, it re-decodes this bitstring as integer.
* @param p_td Type descriptor for RAW decode
* @return the value of this bitstring interpreted as integer
*/
public TitanInteger convert_to_Integer(final TTCN_Typedescriptor p_td) {
final TTCN_EncDec_ErrorContext errorContext = new TTCN_EncDec_ErrorContext("While converting to integer type '%s': ", p_td.name);
try{
final TTCN_Buffer ttcnBuffer = new TTCN_Buffer();
final raw_order_t order = p_td.raw.top_bit_order == top_bit_order_t.TOP_BIT_LEFT ? raw_order_t.ORDER_LSB : raw_order_t.ORDER_MSB;
encode(p_td, ttcnBuffer, coding_type.CT_RAW, 0);
final TitanInteger integer = new TitanInteger();
integer.RAW_decode(p_td, ttcnBuffer, ttcnBuffer.get_len() * 8, order);
return integer;
} finally {
errorContext.leave_context();
}
}
}
......@@ -17,6 +17,7 @@ import org.eclipse.titan.runtime.core.BER.ASN_BER_TLV;
import org.eclipse.titan.runtime.core.BER.ASN_BERdescriptor;
import org.eclipse.titan.runtime.core.BER.ASN_Tag;
import org.eclipse.titan.runtime.core.BER.ASN_TagClass;
import org.eclipse.titan.runtime.core.Base_Type.TTCN_Typedescriptor;
import org.eclipse.titan.runtime.core.JSON.TTCN_JSONdescriptor;
import org.eclipse.titan.runtime.core.JSON.json_string_escaping;
import org.eclipse.titan.runtime.core.JSON_Tokenizer.json_token_t;
......@@ -2405,4 +2406,8 @@ public class TitanInteger extends Base_Type {
}
return false;
}
public TitanInteger convert_to_Integer(final TTCN_Typedescriptor p_td) {
return this;
}
}
......@@ -237,11 +237,17 @@ public class TitanOctetString extends Base_Type {
return this;
}
public TitanOctetString operator_assign(final TitanInteger otherValue) {
return operator_assign(AdditionalFunctions.int2oct(otherValue, val_ptr.length));
}
@Override
public TitanOctetString operator_assign(final Base_Type otherValue) {
if (otherValue instanceof TitanOctetString) {
return operator_assign((TitanOctetString)otherValue);
}
} else if (otherValue instanceof TitanInteger) {
return operator_assign((TitanInteger)otherValue);
}
throw new TtcnError(MessageFormat.format("Internal Error: value `{0}'' can not be cast to octetstring", otherValue));
}
......@@ -1406,4 +1412,22 @@ public class TitanOctetString extends Base_Type {
public static TitanOctetString convert_to_OctetString(final TitanOctetString_Element otherValue) {
return new TitanOctetString(otherValue);
}
/**
* Based on the specified type descriptor, it re-decodes this octetstring as integer.
* @param p_td Type descriptor for RAW decode
* @return the value of this octetstring interpreted as integer
*/
public TitanInteger convert_to_Integer(final TTCN_Typedescriptor p_td) {
final TTCN_EncDec_ErrorContext errorContext = new TTCN_EncDec_ErrorContext("While converting to integer type '%s': ", p_td.name);
try{
final TTCN_Buffer ttcnBuffer = new TTCN_Buffer(this);
final raw_order_t order = p_td.raw.top_bit_order == top_bit_order_t.TOP_BIT_LEFT ? raw_order_t.ORDER_LSB : raw_order_t.ORDER_MSB;
final TitanInteger integer = new TitanInteger();
integer.RAW_decode(p_td, ttcnBuffer, ttcnBuffer.get_len() * 8, order);
return integer;
} finally {
errorContext.leave_context();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment