Example #1
0
/**
 * inherit from {@link uv_alloc_cb}
 */
static void tcp_client_alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf)
{
//	CL_DEBUG("read freame alloc.\n");
	if (size > 0) {
		abstract_tcp_client_t *client = (abstract_tcp_client_t*) handle->data;
		client_read_tmp_buf_t *packet = &client->recv_tmp_buf;
		if (packet->offset < PACKET_LEN_FIELD_SIZE) {
			buf->base = (char*) &packet->packet_len + packet->offset;
			buf->len = PACKET_LEN_FIELD_SIZE - packet->offset;
		} else if (packet->offset == PACKET_LEN_FIELD_SIZE) {
			// read packet body.
			int32_t packet_len = decode_int32(buf->base);
			if (packet_len <= PACKET_LEN_FIELD_SIZE || packet_len > MAX_PACKET_LEN) {
				// packet invalid, close handle in read_cb.
				CL_ERROR("invalide packet len:%d.\n", packet_len);
				packet->packet_len = PACKET_INVALID;
				buf->base = NULL;
				buf->len = 0;
			} else {
				packet->packet_len = packet_len;
				packet->buf.base = (char*) malloc(packet->packet_len);
				packet->buf.len = packet_len;
				encode_int32(packet->buf.base, 0, packet_len);
				buf->base = packet->buf.base + PACKET_LEN_FIELD_SIZE;
				buf->len = packet_len - PACKET_LEN_FIELD_SIZE;
			}
		} else {
			//continue read body.
			buf->base = packet->buf.base + packet->offset;
			buf->len = packet->packet_len - packet->offset;
		}
	}
}
Example #2
0
 size_t encode_bytes(size_t offset, const char* value, int32_t size) {
   size_t pos = encode_int32(offset, size);
   if (size > 0) {
     return copy(pos, value, size);
   }
   return pos;
 }
Example #3
0
void Collection::encode_items_int32(char* buf) const {
  for (BufferVec::const_iterator i = items_.begin(),
       end = items_.end(); i != end; ++i) {
    encode_int32(buf, i->size());
    buf += sizeof(int32_t);
    memcpy(buf, i->data(), i->size());
    buf += i->size();
  }
}
Example #4
0
/*
 *	struct nlm_lockargs {
 *		netobj cookie;
 *		bool block;
 *		bool exclusive;
 *		struct nlm_lock alock;
 *		bool reclaim;
 *		int state;
 *	};
 */
static void nlm_xdr_enc_lockargs(struct rpc_rqst *req,
				 struct xdr_stream *xdr,
				 const struct nlm_args *args)
{
	const struct nlm_lock *lock = &args->lock;

	encode_cookie(xdr, &args->cookie);
	encode_bool(xdr, args->block);
	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
	encode_nlm_lock(xdr, lock);
	encode_bool(xdr, args->reclaim);
	encode_int32(xdr, args->state);
}
Example #5
0
int32_t _encode(char** out, _t* info)
{
	int16_t size = 0;
	char* ptmp = *out;
	int32_t out_len = 0;
	int32_t encode_len = 0;

	*out += sizeof(int16_t);
	encode_len = encode_int32(out, info->gold_ingot_chg);
	size += encode_len;
	for(i = 0; i < OOO; ++i)
	{
		encode_len = budokai_info_encode(out, &info->budokai_info[i]);
		size += encode_len;
	}
	encode_len = encode_int32(out, info->battle_froce_chg);
	size += encode_len;
	*out -= (size + sizeof(int16_t));
	encode_len = encode_int16(out, size);
	out_len = size + encode_len;
	*out = ptmp + out_len;
	return out_len;
}
Example #6
0
/*
 *	struct nlm_holder {
 *		bool exclusive;
 *		int uppid;
 *		netobj oh;
 *		unsigned l_offset;
 *		unsigned l_len;
 *	};
 */
static void encode_nlm_holder(struct xdr_stream *xdr,
			      const struct nlm_res *result)
{
	const struct nlm_lock *lock = &result->lock;
	u32 l_offset, l_len;
	__be32 *p;

	encode_bool(xdr, lock->fl.fl_type == F_RDLCK);
	encode_int32(xdr, lock->svid);
	encode_netobj(xdr, lock->oh.data, lock->oh.len);

	p = xdr_reserve_space(xdr, 4 + 4);
	nlm_compute_offsets(lock, &l_offset, &l_len);
	*p++ = cpu_to_be32(l_offset);
	*p   = cpu_to_be32(l_len);
}
Example #7
0
 size_t encode_long_string(size_t offset, const char* value, int32_t size) {
   size_t pos = encode_int32(offset, size);
   return copy(pos, value, size);
 }
Example #8
0
void FileReader::append_int32(std::string &buffer, uint32_t value)
{
  char tmp[sizeof(uint32_t)];
  encode_int32(tmp, value);
  buffer.append(tmp, sizeof(uint32_t));
}