WSBytesToPut (C Function)

int WSBytesToPut(WSLINK link,int *n)

calculates the number of bytes remaining to be written in the textual representation of the current data, and stores the result in n.

Details

  • WSTP provides functions such as WSPutString(), WSPutSymbol(), WSPutInteger32(), and WSPutReal64() for sending strings, symbols, integers, and floating-point numbers. However, it is sometimes convenient to send these types using a character string representation. WSBytesToPut() works with WSPutType(), WSPutRawSize() and WSPutRawData() to send a type using a character string representation.
  • WSBytesToPut() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use WSError() to retrieve the error code if WSBytesToPut() fails.
  • WSBytesToPut() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include <string.h>
#include "wstp.h"

/* send an approximation of Pi across a link */

void f(WSLINK lp)
{
    char *Pi = "3.141592654";
    int bytes_left, i;

    if(! WSPutType(lp, WSTKOLDREAL))
        { /* unable to send the data type to lp */ }

    if(! WSPutRawSize(lp, strlen(Pi))
        { /* unable to send the length of Pi to lp */ }

    if(! WSBytesToPut(lp, &bytes_left))
        { /* unable to get the remaining bytes to send from lp */ }

    i = 0;
    while(bytes_left > 0)
    {
        /* send the data one byte at a time */
        if(! WSPutRawData(lp, Pi + i, 1))
            { /* unable to send a character of Pi to lp */ }

        if(! WSBytesToPut(lp, &bytes_left))
            { /* unable to get the remaining bytes to send from lp */ }

        i++;
    }
}