Commit 6e034fc3 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

add basic description for JSON coding.


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent 52fafb6e
......@@ -169,9 +169,10 @@ Parameter `p_td` is a special type descriptor. Each type has its own descriptor,
Parameter `p_buf` contains the encoded value. For details about using it, please consult the previous subsection.
Parameter `p_coding` is the desired coding mechanism. As `coding_type` is defined in `TTCN_EncDec`, its value must be prefixed with `TTCN_EncDec.`. For the time being, this parameter may have one of the following valuesfootnote:[BER, TEXT and XER coding is not yet supported]:
Parameter `p_coding` is the desired coding mechanism. As `coding_type` is defined in `TTCN_EncDec`, its value must be prefixed with `TTCN_EncDec.`. For the time being, this parameter may have one of the following valuesfootnote:[BER, TEXT, XER and OER coding is not yet supported]:
* CT_RAW RAW - coding;
* CT_RAW - RAW coding;
* CT_JSON - JSON coding;
The `flavour` parameter is depending on the chosen coding.
......@@ -303,6 +304,166 @@ XML encoding and decoding is not yet supported on the Java side.
== JSON
JSON encoding and decoding is not yet fully supported on the Java side.
The encoding rules defined in the section "JSON Encoder and Decoder" of the link:https://github.com/eclipse/titan.core/tree/master/usrguide/referenceguide[Programmer's Technical Reference] can be used to encode and decode the following TTCN–3 types:
Semantic checks for checking that the JSON attribute is used consistently is available, but code generation and runtime support is still missing.
* anytype
* array
* bitstring
* boolean
* charstring
* enumerated
* float
* hexstring
* integer
* objid
* octetstring
* record`, set
* record of`, set of
* union
* universal charstring
* verdicttype
The rules also apply to the following ASN.1 types (if imported to a TTCN-3 module):
* ANY
* BIT STRING
* BOOLEAN
* BMPString
* CHOICE, open type (in instances of parameterized types)
* ENUMERATED
* GeneralString
* GraphicString
* IA5String
* INTEGER
* NULL
* NumericString
* OBJECT IDENTIFIER
* OCTET STRING
* PrintableString
* RELATIVE`-OID
* SEQUENCE, SET
* SEQUENCE OF, SET OF
* TeletexString
* UniversalString
* UTF8String
* VideotexString
* VisibleString
The compiler will produce code capable of JSON encoding/decoding for compound types if they have at least one JSON variant attribute or the `encode "JSON"` attribute (and, for compound types, all fields and elements of compound types also have a JSON variant attribute or the `encode "JSON"` attribute).
The encoder and the decoder work with JSON data encoded in UTF-8 (described in link:https://tools.ietf.org/html/rfc3629[UTF-8, a transformation format of ISO 10646]), stored in an object of type `TTCN_Buffer`. Although the contents of this object can be retrieved (using the overloads of the `get_string` function) as an instance of `TitanOctetString`, `TitanCharString` or `TitanUniversalCharString`, it is recommended to use only the `TitanOctetString` representation. `TitanCharString` is not recommended, because UTF-8 is an 8-bit encoding so the buffer may contain bytes with values over 127, which are not valid characters for a TTCN-3 `charstring` (which is implemented by `TitanCharString`, see <<5-mapping_ttcn3_data_types_to_c+\+_constructs.adoc#Charstring, Charstring>>). `TitanUniversalCharString` must not be used because its internal representation is not UTF-8.
[[error-situations-3]]
=== Error Situations
There are no extra error situations apart from the ones in <<the-common-API, The Common API>>.
[[api-3]]
=== API
The Application Programming Interface for JSON encoding and decoding is described in the following.
[[encoding-3]]
==== Encoding
[source]
----
void encode(final TTCN_Typedescriptor p_td, final TTCN_Buffer p_buf,
final coding_type p_coding, final int flavour) const;
----
The parameter `p_coding` must be set to `TTCN_EncDec.CT_JSON`.
[[decoding-3]]
==== Decoding
[source]
----
void decode(final TTCN_Typedescriptor p_td, final TTCN_Buffer p_buf,
final coding_type p_coding, final int flavour);
----
The parameter `p_coding` must be set to `TTCN_EncDec.CT_JSON`.
[[example-3]]
=== Example
Let us assume that we have a TTCN–3 module which contains a type named `ProtocolPdu`, and this module also contains two ports:
[source]
----
type port MyPort1 message
{
out ProtocolPdu;
in octetstring;
}
type port MyPort2 message
{
out octetstring;
in ProtocolPdu;
}
----
Then we can complete the port skeleton generated by the compiler:
[source]
----
void MyPort1.outgoing_send(final ProtocolPdu send_par)
{
final TTCN_Buffer buffer = new TTCN_Buffer();
send_par.encode(ProtocolPdu.ProtocolPdu_descr_, buffer, TTCN_EncDec.coding_type.CT_JSON, 0);
final TitanOctetString encodedData = new TitanOctetString();
buffer.get_string(encodedData);
incoming_message(encodedData);
}
void MyPort2.outgoing_send(final TitanOctetString send_par)
{
TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);
final TTCN_Buffer buffer = new TTCN_Buffer();
buffer.put_os(send_par);
final ProtocolPdu pdu = new ProtocolPdu();
pdu.decode(Bug.ProtocolPdu_descr_, buffer, TTCN_EncDec.coding_type.CT_JSON, 0);
incoming_message(pdu);
}
----
== OER
OER encoding and decoding is not yet supported on the Java side.
......@@ -53,11 +53,10 @@ The TEXT Encoder and Decoder is not yet supported on the Java side.
The XML Encoder and Decoder is not yet supported on the Java side.
[[JSON-Encoder-and-Decoder]]
== JSON Encoder and Decoder
The JSON Encoder and Decoder is not yet fully supported on the Java side.
Semantic checks for checking that the JSON attribute is used consistently is available, but code generation and runtime support is still missing.
The Java side supports the same RAW Encoder and Decoder features as the C side.
== OER Encoder and Decoder
......
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