encode

Encodes a set of 9P / Styx protocol objects into byte representation (array of unsigned bytes)

encode
(
StyxObject[] msg
)

Parameters

msg StyxObject[]

Array of 9P / Styx protocol objects that represents message.

Typical usage:

import std.stdio;
// Example of server message (R_STAT)

// initially, zero size of message
Size size = new Size;
// tag (mark foir message)
Tag tag = new Tag(1);
// R-message, type: stat
Type type = new Type(STYX_MESSAGE_TYPE.R_STAT);
// unique server object
Qid qid = new Qid(STYX_QID_TYPE.QTDIR, 0, 0);

// chmod 775 (drwxrwxr-x)
Perm perm = new Perm;
perm.setPerm(
	STYX_FILE_PERMISSION.DMDIR | STYX_FILE_PERMISSION.OWNER_EXEC | STYX_FILE_PERMISSION.OWNER_READ | STYX_FILE_PERMISSION.OWNER_WRITE |
	STYX_FILE_PERMISSION.GROUP_READ | STYX_FILE_PERMISSION.GROUP_WRITE | STYX_FILE_PERMISSION.GROUP_EXEC | 
	STYX_FILE_PERMISSION.OTHER_READ | STYX_FILE_PERMISSION.OTHER_EXEC 
);
	
// construct stat	
Stat stat = new Stat(
	// type and dev for kernel use 
	77, 4,
	qid,
	// permissions
	perm,
	// access time (as unix timestamp)
	0,
	// modification time (as unix timestamp)
	0,
	// conventional length for all directories is 0
	0,
	// file name (this, directory name)
	"test",
	// user name (owner of file)
	"duser",
	// user group name
	"d_user",
	// others group name
	""
);

// all 9P object in one array with general type
StyxObject[] msg = cast(StyxObject[]) [size, type, tag, stat];
msg.encode.writeln;

Meta