This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Committer:
nyatla
Date:
Tue Jun 10 03:30:41 2014 +0000
Revision:
71:855020258513
Child:
75:2a18df0ef111
MiMic-core ?358???; modJsonRPC???????????;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 71:855020258513 1 #include "NyLPC_cJsonRpcParser.h"
nyatla 71:855020258513 2
nyatla 71:855020258513 3 //
nyatla 71:855020258513 4 // NyLPC_TJsonRpcParserResult
nyatla 71:855020258513 5 //
nyatla 71:855020258513 6
nyatla 71:855020258513 7
nyatla 71:855020258513 8 NyLPC_TBool NyLPC_TJsonRpcParserResult_getUInt32(const union NyLPC_TJsonRpcParserResult* i_struct,NyLPC_TInt16 i_idx,NyLPC_TUInt32* o_val)
nyatla 71:855020258513 9 {
nyatla 71:855020258513 10 if(i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx]!=NyLPC_cJsonRpcParser_TYPE_UINT32){
nyatla 71:855020258513 11 return NyLPC_TBool_FALSE;
nyatla 71:855020258513 12 }
nyatla 71:855020258513 13 *o_val = *((NyLPC_TUInt32*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]));
nyatla 71:855020258513 14 return NyLPC_TBool_TRUE;
nyatla 71:855020258513 15 }
nyatla 71:855020258513 16 NyLPC_TBool NyLPC_TJsonRpcParserResult_getInt32(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TInt32* o_val)
nyatla 71:855020258513 17 {
nyatla 71:855020258513 18 if (i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx] != NyLPC_cJsonRpcParser_TYPE_INT32){
nyatla 71:855020258513 19 return NyLPC_TBool_FALSE;
nyatla 71:855020258513 20 }
nyatla 71:855020258513 21 *o_val = *((NyLPC_TInt32*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]));
nyatla 71:855020258513 22 return NyLPC_TBool_TRUE;
nyatla 71:855020258513 23 }
nyatla 71:855020258513 24 NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val)
nyatla 71:855020258513 25 {
nyatla 71:855020258513 26 if (i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx] != NyLPC_cJsonRpcParser_TYPE_STRING){
nyatla 71:855020258513 27 return NyLPC_TBool_FALSE;
nyatla 71:855020258513 28 }
nyatla 71:855020258513 29 *o_val = ((NyLPC_TChar*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]));
nyatla 71:855020258513 30 return NyLPC_TBool_TRUE;
nyatla 71:855020258513 31 }
nyatla 71:855020258513 32 NyLPC_TBool NyLPC_TJsonRpcParserResult_getByte(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TUInt8* o_val)
nyatla 71:855020258513 33 {
nyatla 71:855020258513 34 if (i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx] != NyLPC_cJsonRpcParser_TYPE_BYTE){
nyatla 71:855020258513 35 return NyLPC_TBool_FALSE;
nyatla 71:855020258513 36 }
nyatla 71:855020258513 37 *o_val = *(i_struct->method.param_buf + i_struct->method.param_index[i_idx]);
nyatla 71:855020258513 38 return NyLPC_TBool_TRUE;
nyatla 71:855020258513 39 }
nyatla 71:855020258513 40
nyatla 71:855020258513 41
nyatla 71:855020258513 42 //
nyatla 71:855020258513 43 // NyLPC_cJsonRpcParser
nyatla 71:855020258513 44 //
nyatla 71:855020258513 45
nyatla 71:855020258513 46
nyatla 71:855020258513 47
nyatla 71:855020258513 48 #define NAME_ID_UNKNOWN 0
nyatla 71:855020258513 49 #define NAME_ID_VERSION 1
nyatla 71:855020258513 50 #define NAME_ID_METHOD 2
nyatla 71:855020258513 51 #define NAME_ID_RESULT 3
nyatla 71:855020258513 52 #define NAME_ID_PARAMS 4
nyatla 71:855020258513 53 #define NAME_ID_ID 5
nyatla 71:855020258513 54
nyatla 71:855020258513 55 const struct NyLPC_TTextIdTbl method_name_tbl[]=
nyatla 71:855020258513 56 {
nyatla 71:855020258513 57 {"version",NAME_ID_VERSION},
nyatla 71:855020258513 58 {"method",NAME_ID_METHOD},
nyatla 71:855020258513 59 {"params",NAME_ID_PARAMS},
nyatla 71:855020258513 60 {"id",NAME_ID_ID},
nyatla 71:855020258513 61 {NULL,NAME_ID_UNKNOWN}
nyatla 71:855020258513 62 };
nyatla 71:855020258513 63
nyatla 71:855020258513 64
nyatla 71:855020258513 65 static const struct NyLPC_TJsonRpcClassDef* findFunction(const struct NyLPC_TJsonRpcClassDef** i_tbl, const NyLPC_TChar* i_method_path, NyLPC_TUInt8* o_function_idx);
nyatla 71:855020258513 66 static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c);
nyatla 71:855020258513 67 static NyLPC_TUInt8 valTerminator2St(NyLPC_TChar i_c);
nyatla 71:855020258513 68
nyatla 71:855020258513 69
nyatla 71:855020258513 70 void NyLPC_cJsonRpcParser_initialize(
nyatla 71:855020258513 71 NyLPC_TcJsonRpcParser_t* i_inst,
nyatla 71:855020258513 72 const struct NyLPC_TJsonRpcClassDef** i_class_def)
nyatla 71:855020258513 73 {
nyatla 71:855020258513 74 i_inst->_class_def=i_class_def;
nyatla 71:855020258513 75 }
nyatla 71:855020258513 76 void NyLPC_cJsonRpcParser_initParser(NyLPC_TcJsonRpcParser_t* i_inst,union NyLPC_TJsonRpcParserResult* i_result)
nyatla 71:855020258513 77 {
nyatla 71:855020258513 78 i_inst->_result=i_result;
nyatla 71:855020258513 79 i_result->type=NyLPC_TJsonRpcParserResult_TYPE_UNKNOWN;
nyatla 71:855020258513 80 i_inst->_st = NyLPC_TcJsonRpcParser_ST_START;
nyatla 71:855020258513 81 i_inst->_pcounter = 0;
nyatla 71:855020258513 82 memset(i_result->raw.param_index, 0xff, NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX);
nyatla 71:855020258513 83 }
nyatla 71:855020258513 84
nyatla 71:855020258513 85
nyatla 71:855020258513 86
nyatla 71:855020258513 87 static const struct NyLPC_TJsonRpcClassDef* findFunction(const struct NyLPC_TJsonRpcClassDef** i_tbl,const NyLPC_TChar* i_method_path,NyLPC_TUInt8* o_function_idx)
nyatla 71:855020258513 88 {
nyatla 71:855020258513 89 const NyLPC_TChar* ns;
nyatla 71:855020258513 90 const NyLPC_TChar* class_;
nyatla 71:855020258513 91 const NyLPC_TChar* method;
nyatla 71:855020258513 92 NyLPC_TUInt8 fidx;
nyatla 71:855020258513 93 int l;
nyatla 71:855020258513 94 //namespaceの抽出
nyatla 71:855020258513 95 ns=i_method_path;
nyatla 71:855020258513 96 class_=strchr(i_method_path,':');
nyatla 71:855020258513 97 if(class_==NULL){
nyatla 71:855020258513 98 return NULL;
nyatla 71:855020258513 99 }
nyatla 71:855020258513 100 class_++;
nyatla 71:855020258513 101 //functionの抽出
nyatla 71:855020258513 102 method=strchr(class_,':');
nyatla 71:855020258513 103 if(method==NULL){
nyatla 71:855020258513 104 return NULL;
nyatla 71:855020258513 105 }
nyatla 71:855020258513 106 method++;
nyatla 71:855020258513 107 while((*i_tbl)!=NULL){
nyatla 71:855020258513 108 l=class_-ns-1;
nyatla 71:855020258513 109 if(strncmp((*i_tbl)->names_pace,ns,l)!=0 || (*(ns+l))!=':'){
nyatla 71:855020258513 110 i_tbl++;
nyatla 71:855020258513 111 continue;
nyatla 71:855020258513 112 }
nyatla 71:855020258513 113 l=method-class_-1;
nyatla 71:855020258513 114 if(strncmp((*i_tbl)->class_name,class_,l)!=0 || (*(class_+l))!=':'){
nyatla 71:855020258513 115 i_tbl++;
nyatla 71:855020258513 116 continue;
nyatla 71:855020258513 117 }
nyatla 71:855020258513 118 fidx=0;
nyatla 71:855020258513 119 while(((*i_tbl)->functions+fidx)->name!=NULL){
nyatla 71:855020258513 120 if(strcmp(((*i_tbl)->functions+fidx)->name,method)!=0){
nyatla 71:855020258513 121 fidx++;
nyatla 71:855020258513 122 continue;
nyatla 71:855020258513 123 }
nyatla 71:855020258513 124 *o_function_idx=fidx;
nyatla 71:855020258513 125 return (*i_tbl);
nyatla 71:855020258513 126 }
nyatla 71:855020258513 127 break;
nyatla 71:855020258513 128 }
nyatla 71:855020258513 129 return NULL;
nyatla 71:855020258513 130 }
nyatla 71:855020258513 131 #define PARAM_ST_START 1
nyatla 71:855020258513 132 #define PARAM_ST_VAL 2
nyatla 71:855020258513 133 #define PARAM_ST_INT 3
nyatla 71:855020258513 134 #define PARAM_ST_UINT 4
nyatla 71:855020258513 135 #define PARAM_ST_STR 5
nyatla 71:855020258513 136 #define PARAM_ST_NEXT 6
nyatla 71:855020258513 137 #define PARAM_ST_BYTE 7
nyatla 71:855020258513 138
nyatla 71:855020258513 139 static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
nyatla 71:855020258513 140 {
nyatla 71:855020258513 141
nyatla 71:855020258513 142 switch (i_inst->_pst){
nyatla 71:855020258513 143 case PARAM_ST_START:
nyatla 71:855020258513 144 if (i_c == '['){
nyatla 71:855020258513 145 //パース開始
nyatla 71:855020258513 146 i_inst->_work.str.n = 0;
nyatla 71:855020258513 147 i_inst->_pst = PARAM_ST_VAL;
nyatla 71:855020258513 148 return;
nyatla 71:855020258513 149 }
nyatla 71:855020258513 150 if (strchr(" ", i_c) != NULL){
nyatla 71:855020258513 151 //無視
nyatla 71:855020258513 152 return;
nyatla 71:855020258513 153 }
nyatla 71:855020258513 154 //エラー
nyatla 71:855020258513 155 goto ERROR;
nyatla 71:855020258513 156 case PARAM_ST_VAL:
nyatla 71:855020258513 157 if (i_inst->_pcounter >= NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX){
nyatla 71:855020258513 158 goto ERROR;
nyatla 71:855020258513 159 }
nyatla 71:855020258513 160 if (strchr(" ", i_c) != NULL){
nyatla 71:855020258513 161 //無視
nyatla 71:855020258513 162 return;
nyatla 71:855020258513 163 }
nyatla 71:855020258513 164 if (strchr("]", i_c) != NULL){
nyatla 71:855020258513 165 i_inst->_st = NyLPC_TcJsonRpcParser_ST_NEXT;
nyatla 71:855020258513 166 i_inst->_pcounter = 0xff;
nyatla 71:855020258513 167 return;
nyatla 71:855020258513 168 }
nyatla 71:855020258513 169 switch (i_inst->_result->method.class_def->functions[i_inst->_result->method.func_number].param_patt[i_inst->_pcounter]){
nyatla 71:855020258513 170 case NyLPC_cJsonRpcParser_TYPE_INT32:
nyatla 71:855020258513 171 if (strchr("-0123456789", i_c) == NULL){
nyatla 71:855020258513 172 goto ERROR;
nyatla 71:855020258513 173 }
nyatla 71:855020258513 174 i_inst->_pst = PARAM_ST_INT;
nyatla 71:855020258513 175 i_inst->_work.int32.s = i_c == '-' ? -1 : 1;
nyatla 71:855020258513 176 i_inst->_work.int32.v = i_c == '-' ? 0 : (i_c - '0');
nyatla 71:855020258513 177 i_inst->_work.str.n = ((i_inst->_work.str.n + 3) / 4) * 4;
nyatla 71:855020258513 178 break;
nyatla 71:855020258513 179 case NyLPC_cJsonRpcParser_TYPE_UINT32:
nyatla 71:855020258513 180 if (strchr("0123456789", i_c) == NULL){
nyatla 71:855020258513 181 goto ERROR;
nyatla 71:855020258513 182 }
nyatla 71:855020258513 183 i_inst->_pst = PARAM_ST_UINT;
nyatla 71:855020258513 184 i_inst->_work.uint32 = (i_c - '0');
nyatla 71:855020258513 185 //開始位置を4バイト境界に
nyatla 71:855020258513 186 i_inst->_work.str.n = ((i_inst->_work.str.n + 3) / 4) * 4;
nyatla 71:855020258513 187 break;
nyatla 71:855020258513 188 case NyLPC_cJsonRpcParser_TYPE_BYTE:
nyatla 71:855020258513 189 if (strchr("0123456789", i_c) == NULL){
nyatla 71:855020258513 190 goto ERROR;
nyatla 71:855020258513 191 }
nyatla 71:855020258513 192 i_inst->_pst = PARAM_ST_BYTE;
nyatla 71:855020258513 193 i_inst->_work.uint32 = (i_c - '0');
nyatla 71:855020258513 194 break;
nyatla 71:855020258513 195 case NyLPC_cJsonRpcParser_TYPE_STRING:
nyatla 71:855020258513 196 if (i_c != '"'){
nyatla 71:855020258513 197 goto ERROR;
nyatla 71:855020258513 198 }
nyatla 71:855020258513 199 i_inst->_pst = PARAM_ST_STR;
nyatla 71:855020258513 200 break;
nyatla 71:855020258513 201 default:
nyatla 71:855020258513 202 goto ERROR;
nyatla 71:855020258513 203 }
nyatla 71:855020258513 204 i_inst->_result->method.param_index[i_inst->_pcounter] = i_inst->_work.str.n;
nyatla 71:855020258513 205 i_inst->_pcounter++;
nyatla 71:855020258513 206 return;
nyatla 71:855020258513 207 case PARAM_ST_STR:
nyatla 71:855020258513 208 if (i_c == '"'){
nyatla 71:855020258513 209 //完了
nyatla 71:855020258513 210 if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){
nyatla 71:855020258513 211 goto ERROR;
nyatla 71:855020258513 212 }
nyatla 71:855020258513 213 i_inst->_result->method.param_buf[i_inst->_work.str.n] = '\0';
nyatla 71:855020258513 214 i_inst->_work.str.n++;
nyatla 71:855020258513 215 i_inst->_pst = PARAM_ST_NEXT;
nyatla 71:855020258513 216 return;
nyatla 71:855020258513 217 }
nyatla 71:855020258513 218 else{
nyatla 71:855020258513 219 if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){
nyatla 71:855020258513 220 goto ERROR;
nyatla 71:855020258513 221 }
nyatla 71:855020258513 222 i_inst->_result->method.param_buf[i_inst->_work.str.n] = i_c;
nyatla 71:855020258513 223 i_inst->_work.str.n++;
nyatla 71:855020258513 224 }
nyatla 71:855020258513 225 return;
nyatla 71:855020258513 226 case PARAM_ST_INT:
nyatla 71:855020258513 227 if (strchr("0123456789", i_c) != NULL){
nyatla 71:855020258513 228 i_inst->_work.int32.v = i_inst->_work.int32.v * 10 + (i_c - '0');
nyatla 71:855020258513 229 return;
nyatla 71:855020258513 230 }
nyatla 71:855020258513 231 switch (i_c){
nyatla 71:855020258513 232 case ' ':
nyatla 71:855020258513 233 i_inst->_pst = PARAM_ST_NEXT; break;
nyatla 71:855020258513 234 case ',':
nyatla 71:855020258513 235 i_inst->_pst = PARAM_ST_VAL; break;
nyatla 71:855020258513 236 case ']':
nyatla 71:855020258513 237 i_inst->_st = NyLPC_TcJsonRpcParser_ST_NEXT; break;
nyatla 71:855020258513 238 default:
nyatla 71:855020258513 239 goto ERROR;
nyatla 71:855020258513 240 }
nyatla 71:855020258513 241 //4バイト境界に揃える
nyatla 71:855020258513 242 i_inst->_work.str.n += 4;
nyatla 71:855020258513 243 if (i_inst->_work.str.n > NyLPC_TJsonRpcParserResult_PARAM_BUF){
nyatla 71:855020258513 244 goto ERROR;
nyatla 71:855020258513 245 }
nyatla 71:855020258513 246 *((NyLPC_TInt32*)&(i_inst->_result->method.param_buf[i_inst->_work.str.n - 4])) = i_inst->_work.int32.v*i_inst->_work.int32.s;
nyatla 71:855020258513 247 return;
nyatla 71:855020258513 248 case PARAM_ST_UINT:
nyatla 71:855020258513 249 if (strchr("0123456789", i_c) != NULL){
nyatla 71:855020258513 250 i_inst->_work.uint32 = i_inst->_work.uint32 * 10 + (i_c - '0');
nyatla 71:855020258513 251 return;
nyatla 71:855020258513 252 }
nyatla 71:855020258513 253 switch (i_c){
nyatla 71:855020258513 254 case ' ':
nyatla 71:855020258513 255 i_inst->_pst = PARAM_ST_NEXT; break;
nyatla 71:855020258513 256 case ',':
nyatla 71:855020258513 257 i_inst->_pst = PARAM_ST_VAL; break;
nyatla 71:855020258513 258 case ']':
nyatla 71:855020258513 259 i_inst->_st = NyLPC_TcJsonRpcParser_ST_NEXT; break;
nyatla 71:855020258513 260 default:
nyatla 71:855020258513 261 goto ERROR;
nyatla 71:855020258513 262 }
nyatla 71:855020258513 263 i_inst->_work.str.n += 4;
nyatla 71:855020258513 264 if (i_inst->_work.str.n > NyLPC_TJsonRpcParserResult_PARAM_BUF){
nyatla 71:855020258513 265 goto ERROR;
nyatla 71:855020258513 266 }
nyatla 71:855020258513 267 *((NyLPC_TUInt32*)&(i_inst->_result->method.param_buf[i_inst->_work.str.n - 4])) = i_inst->_work.uint32;
nyatla 71:855020258513 268 return;
nyatla 71:855020258513 269 case PARAM_ST_BYTE:
nyatla 71:855020258513 270 if (strchr("0123456789", i_c) != NULL){
nyatla 71:855020258513 271 i_inst->_work.uint32 = i_inst->_work.uint32 * 10 + (i_c - '0');
nyatla 71:855020258513 272 return;
nyatla 71:855020258513 273 }
nyatla 71:855020258513 274 switch (i_c){
nyatla 71:855020258513 275 case ' ':
nyatla 71:855020258513 276 i_inst->_pst = PARAM_ST_NEXT; break;
nyatla 71:855020258513 277 case ',':
nyatla 71:855020258513 278 i_inst->_pst = PARAM_ST_VAL; break;
nyatla 71:855020258513 279 case ']':
nyatla 71:855020258513 280 i_inst->_st = NyLPC_TcJsonRpcParser_ST_NEXT; break;
nyatla 71:855020258513 281 default:
nyatla 71:855020258513 282 goto ERROR;
nyatla 71:855020258513 283 }
nyatla 71:855020258513 284 i_inst->_work.str.n ++;
nyatla 71:855020258513 285 if (i_inst->_work.str.n > NyLPC_TJsonRpcParserResult_PARAM_BUF){
nyatla 71:855020258513 286 goto ERROR;
nyatla 71:855020258513 287 }
nyatla 71:855020258513 288 *((NyLPC_TUInt8*)&(i_inst->_result->method.param_buf[i_inst->_work.str.n - 1])) = (NyLPC_TUInt8)(i_inst->_work.uint32&0xff);
nyatla 71:855020258513 289 return;
nyatla 71:855020258513 290 case PARAM_ST_NEXT:
nyatla 71:855020258513 291 switch (i_c){
nyatla 71:855020258513 292 case ' ':break;
nyatla 71:855020258513 293 case ',':
nyatla 71:855020258513 294 i_inst->_pst = PARAM_ST_VAL; break;
nyatla 71:855020258513 295 case ']':
nyatla 71:855020258513 296 i_inst->_st = NyLPC_TcJsonRpcParser_ST_NEXT; break;
nyatla 71:855020258513 297 default:
nyatla 71:855020258513 298 goto ERROR;
nyatla 71:855020258513 299 }
nyatla 71:855020258513 300 return;
nyatla 71:855020258513 301 }
nyatla 71:855020258513 302 ERROR:
nyatla 71:855020258513 303 i_inst->_st = NyLPC_TcJsonRpcParser_ST_ERROR;
nyatla 71:855020258513 304 return;
nyatla 71:855020258513 305 }
nyatla 71:855020258513 306
nyatla 71:855020258513 307
nyatla 71:855020258513 308 /**
nyatla 71:855020258513 309 * NyLPC_cJsonRpcParser_putCharのサブ関数
nyatla 71:855020258513 310 */
nyatla 71:855020258513 311 static NyLPC_TUInt8 valTerminator2St(NyLPC_TChar i_c)
nyatla 71:855020258513 312 {
nyatla 71:855020258513 313 switch (i_c){
nyatla 71:855020258513 314 case ' ':
nyatla 71:855020258513 315 return NyLPC_TcJsonRpcParser_ST_NEXT;
nyatla 71:855020258513 316 case '}':
nyatla 71:855020258513 317 return NyLPC_TcJsonRpcParser_ST_END;
nyatla 71:855020258513 318 case ',':
nyatla 71:855020258513 319 return NyLPC_TcJsonRpcParser_ST_NAME_Q;
nyatla 71:855020258513 320 default:
nyatla 71:855020258513 321 //ないはず
nyatla 71:855020258513 322 return NyLPC_TcJsonRpcParser_ST_ERROR;
nyatla 71:855020258513 323 }
nyatla 71:855020258513 324 }
nyatla 71:855020258513 325
nyatla 71:855020258513 326 /** 文字列をパーサに入力してパーサの状態を遷移させます。
nyatla 71:855020258513 327
nyatla 71:855020258513 328 */
nyatla 71:855020258513 329 void NyLPC_cJsonRpcParser_putChar(NyLPC_TcJsonRpcParser_t* i_inst,char i_c)
nyatla 71:855020258513 330 {
nyatla 71:855020258513 331 switch(i_inst->_st){
nyatla 71:855020258513 332 case NyLPC_TcJsonRpcParser_ST_PARAMS:
nyatla 71:855020258513 333 putchar_params(i_inst,i_c);
nyatla 71:855020258513 334 return;
nyatla 71:855020258513 335 case NyLPC_TcJsonRpcParser_ST_START:
nyatla 71:855020258513 336 if(i_c=='{'){
nyatla 71:855020258513 337 i_inst->_st=NyLPC_TcJsonRpcParser_ST_NAME_Q;
nyatla 71:855020258513 338 return;
nyatla 71:855020258513 339 }
nyatla 71:855020258513 340 if(strchr(" ",i_c)!=NULL){
nyatla 71:855020258513 341 //無視
nyatla 71:855020258513 342 return;
nyatla 71:855020258513 343 }
nyatla 71:855020258513 344 //エラー
nyatla 71:855020258513 345 goto ERROR;
nyatla 71:855020258513 346 case NyLPC_TcJsonRpcParser_ST_NAME_Q:
nyatla 71:855020258513 347 if(i_c=='"'){
nyatla 71:855020258513 348 i_inst->_st=NyLPC_TcJsonRpcParser_ST_NAME_STR;
nyatla 71:855020258513 349 i_inst->_work.str.n=0;
nyatla 71:855020258513 350 return;
nyatla 71:855020258513 351 }
nyatla 71:855020258513 352 if(strchr(" ",i_c)!=NULL){
nyatla 71:855020258513 353 //無視
nyatla 71:855020258513 354 return;
nyatla 71:855020258513 355 }
nyatla 71:855020258513 356 //エラー
nyatla 71:855020258513 357 goto ERROR;
nyatla 71:855020258513 358 case NyLPC_TcJsonRpcParser_ST_NAME_STR:
nyatla 71:855020258513 359 if(i_c=='"'){
nyatla 71:855020258513 360 //完了
nyatla 71:855020258513 361 i_inst->_work.str.buf[i_inst->_work.str.n]='\0';
nyatla 71:855020258513 362 //メソッドIDを記録
nyatla 71:855020258513 363 i_inst->_name_id=NyLPC_TTextIdTbl_getMatchId(i_inst->_work.str.buf,method_name_tbl);
nyatla 71:855020258513 364 i_inst->_st=NyLPC_TcJsonRpcParser_ST_NV_SEP;
nyatla 71:855020258513 365 switch(i_inst->_name_id){
nyatla 71:855020258513 366 case NAME_ID_METHOD:
nyatla 71:855020258513 367 case NAME_ID_RESULT:
nyatla 71:855020258513 368 if(i_inst->_result->type!=NyLPC_TJsonRpcParserResult_TYPE_UNKNOWN){
nyatla 71:855020258513 369 goto ERROR;
nyatla 71:855020258513 370 }
nyatla 71:855020258513 371 break;
nyatla 71:855020258513 372 case NAME_ID_PARAMS:
nyatla 71:855020258513 373 if (i_inst->_pcounter != 0){
nyatla 71:855020258513 374 goto ERROR;
nyatla 71:855020258513 375 }
nyatla 71:855020258513 376 break;
nyatla 71:855020258513 377 default:
nyatla 71:855020258513 378 break;
nyatla 71:855020258513 379 }
nyatla 71:855020258513 380 return;
nyatla 71:855020258513 381 }
nyatla 71:855020258513 382 i_inst->_work.str.n++;
nyatla 71:855020258513 383 if(i_inst->_work.str.n>=NyLPC_TcJsonRpcParser_WORK_MAX){
nyatla 71:855020258513 384 //文字列長すぎでござる。
nyatla 71:855020258513 385 goto ERROR;
nyatla 71:855020258513 386 }
nyatla 71:855020258513 387 i_inst->_work.str.buf[i_inst->_work.str.n-1]=i_c;
nyatla 71:855020258513 388 return;
nyatla 71:855020258513 389 case NyLPC_TcJsonRpcParser_ST_NV_SEP:
nyatla 71:855020258513 390 if(i_c==':'){
nyatla 71:855020258513 391 if (i_inst->_name_id == NAME_ID_PARAMS){
nyatla 71:855020258513 392 i_inst->_pst = PARAM_ST_START;
nyatla 71:855020258513 393 i_inst->_st = NyLPC_TcJsonRpcParser_ST_PARAMS;
nyatla 71:855020258513 394 }
nyatla 71:855020258513 395 else{
nyatla 71:855020258513 396 i_inst->_st = NyLPC_TcJsonRpcParser_ST_VAL;
nyatla 71:855020258513 397 i_inst->_work.str.n = 0;
nyatla 71:855020258513 398 }
nyatla 71:855020258513 399 return;
nyatla 71:855020258513 400 }
nyatla 71:855020258513 401 if(strchr(" ",i_c)!=NULL){
nyatla 71:855020258513 402 //無視
nyatla 71:855020258513 403 return;
nyatla 71:855020258513 404 }
nyatla 71:855020258513 405 //エラー
nyatla 71:855020258513 406 goto ERROR;
nyatla 71:855020258513 407 case NyLPC_TcJsonRpcParser_ST_VAL:
nyatla 71:855020258513 408 if(i_c=='"'){
nyatla 71:855020258513 409 i_inst->_st=NyLPC_TcJsonRpcParser_ST_VAL_STR;
nyatla 71:855020258513 410 i_inst->_work.str.n=0;
nyatla 71:855020258513 411 return;
nyatla 71:855020258513 412 }
nyatla 71:855020258513 413 if(strchr(" ",i_c)!=NULL){
nyatla 71:855020258513 414 //無視
nyatla 71:855020258513 415 return;
nyatla 71:855020258513 416 }
nyatla 71:855020258513 417 if(strchr("0123456789",i_c)!=NULL){
nyatla 71:855020258513 418 i_inst->_work.uint32=(i_c-'0');
nyatla 71:855020258513 419 i_inst->_st=NyLPC_TcJsonRpcParser_ST_VAL_UINT;
nyatla 71:855020258513 420 return;
nyatla 71:855020258513 421 }
nyatla 71:855020258513 422 //エラー
nyatla 71:855020258513 423 goto ERROR;
nyatla 71:855020258513 424 case NyLPC_TcJsonRpcParser_ST_VAL_UINT:
nyatla 71:855020258513 425 if(strchr("0123456789",i_c)!=NULL){
nyatla 71:855020258513 426 i_inst->_work.uint32=i_inst->_work.uint32*10+(i_c-'0');
nyatla 71:855020258513 427 return;
nyatla 71:855020258513 428 }
nyatla 71:855020258513 429 if(strchr(" ,}",i_c)!=NULL){
nyatla 71:855020258513 430 //確定
nyatla 71:855020258513 431 switch(i_inst->_name_id){
nyatla 71:855020258513 432 case NAME_ID_ID:
nyatla 71:855020258513 433 i_inst->_result->method.id=i_inst->_work.uint32;
nyatla 71:855020258513 434 break;
nyatla 71:855020258513 435 case NAME_ID_UNKNOWN:
nyatla 71:855020258513 436 //知らないIDは無視
nyatla 71:855020258513 437 break;
nyatla 71:855020258513 438 default:
nyatla 71:855020258513 439 //数値を受け入れないパラメータ
nyatla 71:855020258513 440 goto ERROR;
nyatla 71:855020258513 441 }
nyatla 71:855020258513 442 i_inst->_st=valTerminator2St(i_c);
nyatla 71:855020258513 443 return;
nyatla 71:855020258513 444 }
nyatla 71:855020258513 445 goto ERROR;
nyatla 71:855020258513 446 case NyLPC_TcJsonRpcParser_ST_VAL_STR:
nyatla 71:855020258513 447 if(i_c=='"'){
nyatla 71:855020258513 448 i_inst->_work.str.buf[i_inst->_work.str.n]='\0';
nyatla 71:855020258513 449 //確定
nyatla 71:855020258513 450 switch(i_inst->_name_id){
nyatla 71:855020258513 451 case NAME_ID_VERSION:
nyatla 71:855020258513 452 if(strcmp(i_inst->_work.str.buf,"2.0")!=0){
nyatla 71:855020258513 453 goto ERROR;
nyatla 71:855020258513 454 }
nyatla 71:855020258513 455 break;
nyatla 71:855020258513 456 case NAME_ID_METHOD:
nyatla 71:855020258513 457 i_inst->_result->method._type=NyLPC_TJsonRpcParserResult_TYPE_METHOD;
nyatla 71:855020258513 458 i_inst->_result->method.class_def=findFunction(i_inst->_class_def,i_inst->_work.str.buf,&(i_inst->_result->method.func_number));
nyatla 71:855020258513 459 if(i_inst->_result->method.class_def==NULL){
nyatla 71:855020258513 460 goto ERROR;
nyatla 71:855020258513 461 }
nyatla 71:855020258513 462 break;
nyatla 71:855020258513 463 case NAME_ID_UNKNOWN:
nyatla 71:855020258513 464 //知らないIDは無視
nyatla 71:855020258513 465 break;
nyatla 71:855020258513 466 default:
nyatla 71:855020258513 467 //文字列を受け入れないパラメータ
nyatla 71:855020258513 468 goto ERROR;
nyatla 71:855020258513 469 }
nyatla 71:855020258513 470 i_inst->_st=NyLPC_TcJsonRpcParser_ST_NEXT;
nyatla 71:855020258513 471 return;
nyatla 71:855020258513 472 }
nyatla 71:855020258513 473 i_inst->_work.str.n++;
nyatla 71:855020258513 474 if(i_inst->_work.str.n>=NyLPC_TcJsonRpcParser_WORK_MAX){
nyatla 71:855020258513 475 //文字列長すぎでござる。
nyatla 71:855020258513 476 goto ERROR;
nyatla 71:855020258513 477 }
nyatla 71:855020258513 478 i_inst->_work.str.buf[i_inst->_work.str.n-1]=i_c;
nyatla 71:855020258513 479 return;
nyatla 71:855020258513 480 case NyLPC_TcJsonRpcParser_ST_NEXT:
nyatla 71:855020258513 481 if(i_c==','){
nyatla 71:855020258513 482 i_inst->_st=NyLPC_TcJsonRpcParser_ST_NAME_Q;
nyatla 71:855020258513 483 }else if(i_c=='}'){
nyatla 71:855020258513 484 i_inst->_st=NyLPC_TcJsonRpcParser_ST_END;
nyatla 71:855020258513 485 }else if(strchr(" ",i_c)!=NULL){
nyatla 71:855020258513 486 //nothing to do
nyatla 71:855020258513 487 }else{
nyatla 71:855020258513 488 goto ERROR;
nyatla 71:855020258513 489 }
nyatla 71:855020258513 490 return;
nyatla 71:855020258513 491 default:
nyatla 71:855020258513 492 goto ERROR;
nyatla 71:855020258513 493 }
nyatla 71:855020258513 494 ERROR:
nyatla 71:855020258513 495 i_inst->_st = NyLPC_TcJsonRpcParser_ST_ERROR;
nyatla 71:855020258513 496 return;
nyatla 71:855020258513 497 }
nyatla 71:855020258513 498
nyatla 71:855020258513 499 #define COMMENT_DEBUG
nyatla 71:855020258513 500 #ifndef COMMENT_DEBUG
nyatla 71:855020258513 501
nyatla 71:855020258513 502 const struct NyLPC_TJsonRpcMethodDef test_method[]=
nyatla 71:855020258513 503 {
nyatla 71:855020258513 504 { "func" , ""},
nyatla 71:855020258513 505 { "func1", "d" },
nyatla 71:855020258513 506 { "func2", "dd" },
nyatla 71:855020258513 507 { "func3", "u" },
nyatla 71:855020258513 508 { "func4", "uu" },
nyatla 71:855020258513 509 { "func5", "uss" },
nyatla 71:855020258513 510 { "func5", "uss" },
nyatla 71:855020258513 511 { "func6", "s" },
nyatla 71:855020258513 512 { "func7", "sd" },
nyatla 71:855020258513 513 { "func8", "su" },
nyatla 71:855020258513 514 { "func9", "ss" },
nyatla 71:855020258513 515 { "f10", "suu" },
nyatla 71:855020258513 516 { "f11", "bbbb" },
nyatla 71:855020258513 517 { NULL, "" }
nyatla 71:855020258513 518 };
nyatla 71:855020258513 519
nyatla 71:855020258513 520 const struct NyLPC_TJsonRpcClassDef test_def=
nyatla 71:855020258513 521 {
nyatla 71:855020258513 522 "ns","class",
nyatla 71:855020258513 523 test_method
nyatla 71:855020258513 524 };
nyatla 71:855020258513 525
nyatla 71:855020258513 526 /**
nyatla 71:855020258513 527 * テスト用のアレイ
nyatla 71:855020258513 528 */
nyatla 71:855020258513 529 const struct NyLPC_TJsonRpcClassDef* test_def_array[]=
nyatla 71:855020258513 530 {
nyatla 71:855020258513 531 &test_def,
nyatla 71:855020258513 532 NULL
nyatla 71:855020258513 533 };
nyatla 71:855020258513 534
nyatla 71:855020258513 535 void NyLPC_cJsonRpcParser_putText(NyLPC_TcJsonRpcParser_t* i_inst, const NyLPC_TChar* i_text,NyLPC_TUInt16 i_size)
nyatla 71:855020258513 536 {
nyatla 71:855020258513 537 NyLPC_TUInt16 i;
nyatla 71:855020258513 538 NyLPC_TUInt32 u32;
nyatla 71:855020258513 539 NyLPC_TInt32 i32;
nyatla 71:855020258513 540 NyLPC_TChar* c;
nyatla 71:855020258513 541 NyLPC_TUInt8 u8;
nyatla 71:855020258513 542
nyatla 71:855020258513 543
nyatla 71:855020258513 544 for (i = 0; i < i_size; i++){
nyatla 71:855020258513 545 NyLPC_cJsonRpcParser_putChar(i_inst,i_text[i]);
nyatla 71:855020258513 546 if (i_inst->_st == NyLPC_TcJsonRpcParser_ST_ERROR){
nyatla 71:855020258513 547 break;
nyatla 71:855020258513 548 }
nyatla 71:855020258513 549 else if (i_inst->_st == NyLPC_TcJsonRpcParser_ST_END){
nyatla 71:855020258513 550 break;
nyatla 71:855020258513 551 }
nyatla 71:855020258513 552 }
nyatla 71:855020258513 553 if (i_inst->_st == NyLPC_TcJsonRpcParser_ST_ERROR){
nyatla 71:855020258513 554 printf("ERROR!\n");
nyatla 71:855020258513 555 }
nyatla 71:855020258513 556 else if (i_inst->_st == NyLPC_TcJsonRpcParser_ST_END){
nyatla 71:855020258513 557 printf("OK!\n");
nyatla 71:855020258513 558 for (int i = 0; i_inst->_result->method.param_index[i] != 0xff && i<i_inst->_pcounter; i++){
nyatla 71:855020258513 559 switch (i_inst->_result->method.class_def->functions[i_inst->_result->method.func_number].param_patt[i]){
nyatla 71:855020258513 560 case 'u':NyLPC_TJsonRpcParserResult_getUInt32(i_inst->_result,i, &u32); printf("%u,", u32); break;
nyatla 71:855020258513 561 case 'd':NyLPC_TJsonRpcParserResult_getInt32(i_inst->_result, i, &i32); printf("%d,", i32); break;
nyatla 71:855020258513 562 case 's':NyLPC_TJsonRpcParserResult_getStr(i_inst->_result, i, &c); printf("%s,", c); break;
nyatla 71:855020258513 563 case 'b':NyLPC_TJsonRpcParserResult_getByte(i_inst->_result, i, &u8); printf("%u,", u8); break;
nyatla 71:855020258513 564 }
nyatla 71:855020258513 565 }
nyatla 71:855020258513 566 printf("\n");
nyatla 71:855020258513 567 }
nyatla 71:855020258513 568 else{
nyatla 71:855020258513 569 printf("CONTINUE...\n");
nyatla 71:855020258513 570 }
nyatla 71:855020258513 571 }
nyatla 71:855020258513 572
nyatla 71:855020258513 573 void main(void)
nyatla 71:855020258513 574 {
nyatla 71:855020258513 575 NyLPC_TcJsonRpcParser_t inst;
nyatla 71:855020258513 576 union NyLPC_TJsonRpcParserResult ret;
nyatla 71:855020258513 577
nyatla 71:855020258513 578 //JSONCORE
nyatla 71:855020258513 579 //#define JSONCORE 1
nyatla 71:855020258513 580 #ifdef JSONCORE
nyatla 71:855020258513 581 const char* t[] = {
nyatla 71:855020258513 582 "{\"0123\"\"2.0\"}",//NO
nyatla 71:855020258513 583 "{\"01234567890123456789\":\"2.0\"}",//NO
nyatla 71:855020258513 584 "{\"0123\":\"01234567890123456789\"}",//NO
nyatla 71:855020258513 585 "{\"version\":\"2.0\"}",//YES
nyatla 71:855020258513 586 "{\"version\":\"2.1\"}",//NO
nyatla 71:855020258513 587 " { \"version\" : \"2.0\" }",//YES
nyatla 71:855020258513 588 "{\"version\":\"2.0\",}",//NO
nyatla 71:855020258513 589 "{\"version\":\"2.0\" \"test\":\"t\"}",//NO
nyatla 71:855020258513 590 "{\"version\":\"2.0\",\"method\":}",//NO
nyatla 71:855020258513 591 "{\"version\":\"2.0\",\"method\":\"ns:class:func\"}",//YES
nyatla 71:855020258513 592 "{\"version\":\"2.0\",\"method\":\"ns2:class:func\"}",//NO
nyatla 71:855020258513 593 "{\"version\":\"2.0\",\"method\":\"ns:class2:func\"}",//NO
nyatla 71:855020258513 594 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\"}",//NO
nyatla 71:855020258513 595 "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"method\":\"\"}",//NO
nyatla 71:855020258513 596 "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"id\":0}",//YES
nyatla 71:855020258513 597 "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"id\":\"123\"}",//YES
nyatla 71:855020258513 598 "{\"version\":\"2.0\",\"method\":123}",//NO
nyatla 71:855020258513 599 "{\"version\":\"2.0\",\"test\":123}",//YES
nyatla 71:855020258513 600 "{\"version\":\"2.0\",\"test\":123, \"test\":123 }",//YES
nyatla 71:855020258513 601 "{\"version\":\"2.0\",\"test\":123 ,\"test\":123 }",//YES
nyatla 71:855020258513 602 NULL
nyatla 71:855020258513 603 };
nyatla 71:855020258513 604 #else
nyatla 71:855020258513 605 const char* t[] = {
nyatla 71:855020258513 606 "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"params\":[]}",//YES
nyatla 71:855020258513 607 "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"params\": [] }",//YES
nyatla 71:855020258513 608 "{\"version\":\"2.0\",\"method\":\"ns:class:func1\",\"params\": [-123] }",//YES
nyatla 71:855020258513 609 "{\"version\":\"2.0\",\"method\":\"ns:class:func1\",\"params\": [\"123\"] }",//NG
nyatla 71:855020258513 610 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\",\"params\": [ 1 , 456 ] }",//YES
nyatla 71:855020258513 611 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\",\"params\": [ 123 , 456 a] }",//NG
nyatla 71:855020258513 612 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\",\"params\": [ 123a] }",//NG
nyatla 71:855020258513 613 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\",\"params\": [ 123,456] }",//OK
nyatla 71:855020258513 614 "{\"version\":\"2.0\",\"method\":\"ns:class:func2\",\"params\": [123,456] }",//YES
nyatla 71:855020258513 615 "{\"version\":\"2.0\",\"method\":\"ns:class:func3\",\"params\": [123] }",//YES
nyatla 71:855020258513 616 "{\"version\":\"2.0\",\"method\":\"ns:class:func3\",\"params\": [\"123\"] }",//NG
nyatla 71:855020258513 617 "{\"version\":\"2.0\",\"method\":\"ns:class:func4\",\"params\": [ 123 , 456 ] }",//YES
nyatla 71:855020258513 618 "{\"version\":\"2.0\",\"method\":\"ns:class:func4\",\"params\": [ 123 , 456 a] }",//NG
nyatla 71:855020258513 619 "{\"version\":\"2.0\",\"method\":\"ns:class:func4\",\"params\": [ 123a] }",//NG
nyatla 71:855020258513 620 "{\"version\":\"2.0\",\"method\":\"ns:class:func4\",\"params\": [ 123,456] }",//OK
nyatla 71:855020258513 621 "{\"version\":\"2.0\",\"method\":\"ns:class:func5\",\"params\": [123, \"abc\" , \"abc\"] }",//OK
nyatla 71:855020258513 622 "{\"version\":\"2.0\",\"method\":\"ns:class:func6\",\"params\": [\"01234567890123456789012\"] }",//OK
nyatla 71:855020258513 623 "{\"version\":\"2.0\",\"method\":\"ns:class:func6\",\"params\": [1] }",//NG
nyatla 71:855020258513 624 "{\"version\":\"2.0\",\"method\":\"ns:class:func8\",\"params\": [\"012345678901234567\",1,1] }",//OK
nyatla 71:855020258513 625 "{\"version\":\"2.0\",\"method\":\"ns:class:func8\",\"params\": [\"012345678901234567\",1] }",//OK
nyatla 71:855020258513 626 "{\"version\":\"2.0\",\"method\":\"ns:class:func7\",\"params\": [\"012345678901234567\",1] }",//OK
nyatla 71:855020258513 627 "{\"version\":\"2.0\",\"method\":\"ns:class:f10\",\"params\": [\"01234567890123\",22,33] }",//OK
nyatla 71:855020258513 628 "{\"version\":\"2.0\",\"method\":\"ns:class:f11\",\"params\": [ 0 , 1 ,2,3] }",//OK
nyatla 71:855020258513 629 "{\"version\":\"2.0\",\"method\":\"ns:class:f11\",\"params\": [ 15 , 1 ,2,3a] }",//NG
nyatla 71:855020258513 630 NULL
nyatla 71:855020258513 631 };
nyatla 71:855020258513 632 #endif
nyatla 71:855020258513 633 int i;
nyatla 71:855020258513 634
nyatla 71:855020258513 635 for (i = 0;t[i]!=NULL; i++){
nyatla 71:855020258513 636 NyLPC_cJsonRpcParser_initialize(&inst, test_def_array);
nyatla 71:855020258513 637 NyLPC_cJsonRpcParser_initParser(&inst, &ret);
nyatla 71:855020258513 638 NyLPC_cJsonRpcParser_putText(&inst, t[i], strlen(t[i]));
nyatla 71:855020258513 639 }
nyatla 71:855020258513 640 printf("end\n");
nyatla 71:855020258513 641 return;
nyatla 71:855020258513 642
nyatla 71:855020258513 643 }
nyatla 71:855020258513 644 #endif
nyatla 71:855020258513 645