My Project
Public Member Functions | Static Public Attributes | List of all members
NPL::CNPLMsgOut_gen Class Reference

for generating raw NPL output message. More...

#include <NPLMsgOut.h>

Inheritance diagram for NPL::CNPLMsgOut_gen:

Public Member Functions

 CNPLMsgOut_gen (NPLMsgOut &msg, int nReservedSize=-1)
 the internal buffer reserved size. More...
 
void AddFirstLine (const char *method, const char *uri)
 
void AddFirstLine (const NPLFileName &file_name, int file_id=-1)
 
void AddHeaderPair (const char *name, const char *value)
 add a header name value pair to the message. More...
 
void AddBody (const char *pData, int nSize=-1, int nCompressionlevel=0)
 add binary data to the message body. More...
 
void AddMsgBody (const char *pMsg, int nSize=-1, int nCompressionlevel=0)
 Add a message string to the message body. More...
 

Static Public Attributes

static bool g_enable_ansi_mode = true
 whether the first line of the NPL protocol is in ansi code page. More...
 

Detailed Description

for generating raw NPL output message.

It generates the messages like below. <verbatim> A (g1)script/hello.lua NPL/1.0 rts:r1 User-Agent:NPL

14:"hello world!" </verbatim> CNPLMsgOut_gen writer; writer.AddFirstLine(filename); writer.AddHeaderPair("rts", "r1"); writer.AddHeaderPair("User-Agent", "NPL"); writer.AddMsgBody("msg={\"hello world!"}"); writer.AddBody(""hello world!""); const string& msg_str = writer.ToString();

Constructor & Destructor Documentation

§ CNPLMsgOut_gen()

NPL::CNPLMsgOut_gen::CNPLMsgOut_gen ( NPLMsgOut msg,
int  nReservedSize = -1 
)
inline

the internal buffer reserved size.

Member Function Documentation

§ AddBody()

void NPL::CNPLMsgOut_gen::AddBody ( const char *  pData,
int  nSize = -1,
int  nCompressionlevel = 0 
)

add binary data to the message body.

Parameters
pDatathe binary data
nSizenumber of bytes in data. if -1, pData is considered as a string,and strlen() is used.
nCompressionlevelcompression level, which is an integer in the range of -1 to 9. default to 0, which means no compression. We usually choose to compress using -1, when data is larger than a given threshold value. Lower compression levels result in faster execution, but less compression. Higher levels result in greater compression, but slower execution. The zlib constant Z_DEFAULT_COMPRESSION, equal to -1, provides a good compromise between compression and speed and is equivalent to level 6. Level 0 actually does no compression at all, and in fact expands the data slightly to produce the zlib format (it is not a byte-for-byte copy of the input).

§ AddFirstLine()

void NPL::CNPLMsgOut_gen::AddFirstLine ( const NPLFileName file_name,
int  file_id = -1 
)
Parameters
file_idif not -1, the filename will be sent as id

§ AddHeaderPair()

void NPL::CNPLMsgOut_gen::AddHeaderPair ( const char *  name,
const char *  value 
)

add a header name value pair to the message.

§ AddMsgBody()

void NPL::CNPLMsgOut_gen::AddMsgBody ( const char *  pMsg,
int  nSize = -1,
int  nCompressionlevel = 0 
)

Add a message string to the message body.

Parameters
pMsgif should be in the format "msg={some_data_here}" when transmitted, only "some_data_here" is added to the message body.
nSizenumber of bytes in msg. if -1, msg is considered as a string,and strlen() is used.
nCompressionlevelcompression level, which is an integer in the range of -1 to 9. default to 0, which means no compression. We usually choose to compress using -1, when data is larger than a given threshold value. Lower compression levels result in faster execution, but less compression. Higher levels result in greater compression, but slower execution. The zlib constant Z_DEFAULT_COMPRESSION, equal to -1, provides a good compromise between compression and speed and is equivalent to level 6. Level 0 actually does no compression at all, and in fact expands the data slightly to produce the zlib format (it is not a byte-for-byte copy of the input).

Member Data Documentation

§ g_enable_ansi_mode

bool NPL::CNPLMsgOut_gen::g_enable_ansi_mode = true
static

whether the first line of the NPL protocol is in ansi code page.

because NPL protocol is compatible with HTTP protocol in ansi mode, some interception web cache servers may cache request even the port number is not 80, so client side applications are encouraged to disable ansi mode.


The documentation for this class was generated from the following files: