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:
Sat Jun 14 15:55:57 2014 +0000
Revision:
75:2a18df0ef111
Parent:
71:855020258513
Child:
83:d46aa580722a
MiMicCore r360???; mbed???????

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