WSPutRawSize (C 函数)

int WSPutRawSize(WSLINK link, int s)

准备接受 s 字节长的原始字符数据或数值数据的 link.

更多信息

  • WSPutRawSize()WSPutType()WSPutRawData() 一起使用可以手工将数据写入某链接,而不是像 WSPutInteger32()WSPutUTF8String() 一样使用指定类型的 API 函数.
  • 若发生错误,则 WSPutRawSize() 返回0;若函数成功,则返回非零值.
  • WSPutRawSize() 失败,则使用 WSError() 检索错误代码.
  • WSTP 的标头文件 wstp.h 已对 WSPutRawSize() 作出声明.

范例

基本范例  (1)

#include "wstp.h"

/* send a function as raw data to a link */

void f(WSLINK lp)
{
    int a = 2, b = 3;

    if(! WSPutType(lp, WSTKFUNC))
        { return; /* unable to put the function type to lp */ }

    if(! WSPutArgCount(lp, 2))
        { return; /* unable to put the number of arguments to lp */ }

    if(! WSPutType(lp, WSTKOLDSYM))
        { return; /* unable to put function head type to lp */ }
    
    if(! WSPutRawSize(lp, 4))
        { return; /* unable to put the size of the symbol to lp */ }

    if(! WSPutRawData(lp, (const unsigned char *)"Plus", 4))
        { return; /* unable to put the raw bytes to lp */ }

    if(! WSPutType(lp, WSTK_CINT))
        { return; /* unable to put the argument type to lp */ }

    if(! WSPutRawSize(lp, sizeof(int)))
        { return; /* unable to put the size of the integer to lp */ }

    if(! WSPutRawData(lp, (const unsigned char *)&a, sizeof(a)))
        { return; /* unable to put the raw bytes of a to lp */ }

    if(! WSPutType(lp, WSTK_CINT))
        { return; /* unable to put the second argument type to lp */ }

    if(! WSPutRawSize(lp, sizeof(int)))
        { return; /* unable to put the size of the integer to lp */ }

    if(! WSPutRawData(lp, (const unsigned char *)&b, sizeof(b)))
        { return; /* unable to put the raw bytes of b to lp */ }
}