static void encode_fallocate(struct xdr_stream *xdr, struct nfs42_falloc_args *args) { encode_nfs4_stateid(xdr, &args->falloc_stateid); encode_uint64(xdr, args->falloc_offset); encode_uint64(xdr, args->falloc_length); }
void FileAccessNetworkClient::put_64(int64_t p_64) { uint8_t buf[8]; encode_uint64(p_64, buf); client->put_data(buf, 8); DEBUG_PRINT("put64: " + itos(p_64)); }
static void encode_copy(struct xdr_stream *xdr, struct nfs42_copy_args *args, struct compound_hdr *hdr) { encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr); encode_nfs4_stateid(xdr, &args->src_stateid); encode_nfs4_stateid(xdr, &args->dst_stateid); encode_uint64(xdr, args->src_pos); encode_uint64(xdr, args->dst_pos); encode_uint64(xdr, args->count); encode_uint32(xdr, 1); /* consecutive = true */ encode_uint32(xdr, 1); /* synchronous = true */ encode_uint32(xdr, 0); /* src server list */ }
void StreamPeer::put_64(int64_t p_val) { if (big_endian) { p_val = BSWAP64(p_val); } uint8_t buf[8]; encode_uint64(p_val, buf); put_data(buf, 8); }
static void encode_seek(struct xdr_stream *xdr, struct nfs42_seek_args *args, struct compound_hdr *hdr) { encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr); encode_nfs4_stateid(xdr, &args->sa_stateid); encode_uint64(xdr, args->sa_offset); encode_uint32(xdr, args->sa_what); }
void encode_recur(DBusMessageIter *iter, int *err, const alarm_recur_t *rec) { encode_uint64 (iter, err, &rec->mask_min); encode_uint32 (iter, err, &rec->mask_hour); encode_uint32 (iter, err, &rec->mask_mday); encode_uint32 (iter, err, &rec->mask_wday); encode_uint32 (iter, err, &rec->mask_mon); encode_uint32 (iter, err, &rec->special); }
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "theme") { r_ret = get_theme(); } else if (name == "cell_size") { r_ret = get_cell_size(); } else if (name == "cell_octant_size") { r_ret = get_octant_size(); } else if (name == "cell_center_x") { r_ret = get_center_x(); } else if (name == "cell_center_y") { r_ret = get_center_y(); } else if (name == "cell_center_z") { r_ret = get_center_z(); } else if (name == "cell_scale") { r_ret = cell_scale; } else if (name == "data") { Dictionary d; PoolVector<int> cells; cells.resize(cell_map.size() * 3); { PoolVector<int>::Write w = cells.write(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } } d["cells"] = cells; r_ret = d; } else if (name.begins_with("areas/")) { int which = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "bounds") r_ret = area_get_bounds(which); else if (what == "name") r_ret = area_get_name(which); else if (what == "disable_distance") r_ret = area_get_portal_disable_distance(which); else if (what == "exterior_portal") r_ret = area_is_exterior_portal(which); else return false; } else return false; return true; }
int encode_int < uint64_t > ( uint64_t val, uint8_t * start, uint8_t * end ) { int ret = encode_uint64 ( val, start, end ); if ( ret > 0 ) { uint64_t val2; int ret2 = decode_uint64 ( start, start + ret, & val2 ); assert ( ret == ret2 && val == val2 ); } return ret; }
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "theme") { r_ret = get_theme(); } else if (name == "cell_size") { r_ret = get_cell_size(); } else if (name == "cell_octant_size") { r_ret = get_octant_size(); } else if (name == "cell_center_x") { r_ret = get_center_x(); } else if (name == "cell_center_y") { r_ret = get_center_y(); } else if (name == "cell_center_z") { r_ret = get_center_z(); } else if (name == "cell_scale") { r_ret = cell_scale; } else if (name == "data") { Dictionary d; PoolVector<int> cells; cells.resize(cell_map.size() * 3); { PoolVector<int>::Write w = cells.write(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } } d["cells"] = cells; r_ret = d; } else return false; return true; }
void EditorFileServer::_subthread_start(void *s) { ClientData *cd = (ClientData *)s; cd->connection->set_nodelay(true); uint8_t buf4[8]; Error err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int passlen = decode_uint32(buf4); if (passlen > 512) { _close_client(cd); ERR_FAIL_COND(passlen > 512); } else if (passlen > 0) { Vector<char> passutf8; passutf8.resize(passlen + 1); err = cd->connection->get_data((uint8_t *)passutf8.ptr(), passlen); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } passutf8[passlen] = 0; String s; s.parse_utf8(passutf8.ptr()); if (s != cd->efs->password) { encode_uint32(ERR_INVALID_DATA, buf4); cd->connection->put_data(buf4, 4); OS::get_singleton()->delay_usec(1000000); _close_client(cd); ERR_PRINT("CLIENT PASSWORD MISMATCH"); ERR_FAIL(); } } else { if (cd->efs->password != "") { encode_uint32(ERR_INVALID_DATA, buf4); cd->connection->put_data(buf4, 4); OS::get_singleton()->delay_usec(1000000); _close_client(cd); ERR_PRINT("CLIENT PASSWORD MISMATCH (should be empty!)"); ERR_FAIL(); } } encode_uint32(OK, buf4); cd->connection->put_data(buf4, 4); while (!cd->quit) { //wait for ID err = cd->connection->get_data(buf4, 4); //#define DEBUG_PRINT(m_p) print_line(m_p) DEBUG_TIME("get_data") if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int id = decode_uint32(buf4); //wait for command err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int cmd = decode_uint32(buf4); switch (cmd) { case FileAccessNetwork::COMMAND_FILE_EXISTS: case FileAccessNetwork::COMMAND_GET_MODTIME: case FileAccessNetwork::COMMAND_OPEN_FILE: { DEBUG_TIME("open_file") err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int namelen = decode_uint32(buf4); Vector<char> fileutf8; fileutf8.resize(namelen + 1); err = cd->connection->get_data((uint8_t *)fileutf8.ptr(), namelen); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } fileutf8[namelen] = 0; String s; s.parse_utf8(fileutf8.ptr()); if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) { print_line("FILE EXISTS: " + s); } if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) { print_line("MOD TIME: " + s); } if (cmd == FileAccessNetwork::COMMAND_OPEN_FILE) { print_line("OPEN: " + s); } if (!s.begins_with("res://")) { _close_client(cd); ERR_FAIL_COND(!s.begins_with("res://")); } ERR_CONTINUE(cd->files.has(id)); if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) { encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_FILE_EXISTS, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccess::exists(s), buf4); cd->connection->put_data(buf4, 4); DEBUG_TIME("open_file_end") break; } if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) { encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_GET_MODTIME, buf4); cd->connection->put_data(buf4, 4); encode_uint64(FileAccess::get_modified_time(s), buf4); cd->connection->put_data(buf4, 8); DEBUG_TIME("open_file_end") break; } FileAccess *fa = FileAccess::open(s, FileAccess::READ); if (!fa) { //not found, continue encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4); cd->connection->put_data(buf4, 4); encode_uint32(ERR_FILE_NOT_FOUND, buf4); cd->connection->put_data(buf4, 4); DEBUG_TIME("open_file_end") break; } encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4); cd->connection->put_data(buf4, 4); encode_uint32(OK, buf4); cd->connection->put_data(buf4, 4); encode_uint64(fa->get_len(), buf4); cd->connection->put_data(buf4, 8); cd->files[id] = fa; DEBUG_TIME("open_file_end") } break;
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { uint8_t *buf = r_buffer; r_len = 0; uint32_t flags = 0; switch (p_variant.get_type()) { case Variant::INT: { int64_t val = p_variant; if (val > 0x7FFFFFFF || val < -0x80000000) { flags |= ENCODE_FLAG_64; } } break; case Variant::REAL: { double d = p_variant; float f = d; if (double(f) != d) { flags |= ENCODE_FLAG_64; //always encode real as double } } break; } if (buf) { encode_uint32(p_variant.get_type() | flags, buf); buf += 4; } r_len += 4; switch (p_variant.get_type()) { case Variant::NIL: { //nothing to do } break; case Variant::BOOL: { if (buf) { encode_uint32(p_variant.operator bool(), buf); } r_len += 4; } break; case Variant::INT: { int64_t val = p_variant; if (val > 0x7FFFFFFF || val < -0x80000000) { //64 bits if (buf) { encode_uint64(val, buf); } r_len += 8; } else { if (buf) { encode_uint32(int32_t(val), buf); } r_len += 4; } } break; case Variant::REAL: { double d = p_variant; float f = d; if (double(f) != d) { if (buf) { encode_double(p_variant.operator double(), buf); } r_len += 8; } else { if (buf) { encode_float(p_variant.operator float(), buf); } r_len += 4; } } break; case Variant::NODE_PATH: { NodePath np = p_variant; if (buf) { encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format encode_uint32(np.get_subname_count(), buf + 4); uint32_t flags = 0; if (np.is_absolute()) flags |= 1; if (np.get_property() != StringName()) flags |= 2; encode_uint32(flags, buf + 8); buf += 12; } r_len += 12; int total = np.get_name_count() + np.get_subname_count(); if (np.get_property() != StringName()) total++; for (int i = 0; i < total; i++) { String str; if (i < np.get_name_count()) str = np.get_name(i); else if (i < np.get_name_count() + np.get_subname_count()) str = np.get_subname(i - np.get_subname_count()); else str = np.get_property(); CharString utf8 = str.utf8(); int pad = 0; if (utf8.length() % 4) pad = 4 - utf8.length() % 4; if (buf) { encode_uint32(utf8.length(), buf); buf += 4; copymem(buf, utf8.get_data(), utf8.length()); buf += pad + utf8.length(); } r_len += 4 + utf8.length() + pad; } } break; case Variant::STRING: { CharString utf8 = p_variant.operator String().utf8(); if (buf) { encode_uint32(utf8.length(), buf); buf += 4; copymem(buf, utf8.get_data(), utf8.length()); } r_len += 4 + utf8.length(); while (r_len % 4) r_len++; //pad } break; // math types case Variant::VECTOR2: { if (buf) { Vector2 v2 = p_variant; encode_float(v2.x, &buf[0]); encode_float(v2.y, &buf[4]); } r_len += 2 * 4; } break; // 5 case Variant::RECT2: { if (buf) { Rect2 r2 = p_variant; encode_float(r2.position.x, &buf[0]); encode_float(r2.position.y, &buf[4]); encode_float(r2.size.x, &buf[8]); encode_float(r2.size.y, &buf[12]); } r_len += 4 * 4; } break; case Variant::VECTOR3: { if (buf) { Vector3 v3 = p_variant; encode_float(v3.x, &buf[0]); encode_float(v3.y, &buf[4]); encode_float(v3.z, &buf[8]); } r_len += 3 * 4; } break; case Variant::TRANSFORM2D: { if (buf) { Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } } r_len += 6 * 4; } break; case Variant::PLANE: { if (buf) { Plane p = p_variant; encode_float(p.normal.x, &buf[0]); encode_float(p.normal.y, &buf[4]); encode_float(p.normal.z, &buf[8]); encode_float(p.d, &buf[12]); } r_len += 4 * 4; } break; case Variant::QUAT: { if (buf) { Quat q = p_variant; encode_float(q.x, &buf[0]); encode_float(q.y, &buf[4]); encode_float(q.z, &buf[8]); encode_float(q.w, &buf[12]); } r_len += 4 * 4; } break; case Variant::RECT3: { if (buf) { Rect3 aabb = p_variant; encode_float(aabb.position.x, &buf[0]); encode_float(aabb.position.y, &buf[4]); encode_float(aabb.position.z, &buf[8]); encode_float(aabb.size.x, &buf[12]); encode_float(aabb.size.y, &buf[16]); encode_float(aabb.size.z, &buf[20]); } r_len += 6 * 4; } break; case Variant::BASIS: { if (buf) { Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } } r_len += 9 * 4; } break; case Variant::TRANSFORM: { if (buf) { Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } encode_float(val.origin.x, &buf[36]); encode_float(val.origin.y, &buf[40]); encode_float(val.origin.z, &buf[44]); } r_len += 12 * 4; } break; // misc types case Variant::COLOR: { if (buf) { Color c = p_variant; encode_float(c.r, &buf[0]); encode_float(c.g, &buf[4]); encode_float(c.b, &buf[8]); encode_float(c.a, &buf[12]); } r_len += 4 * 4; } break; /*case Variant::RESOURCE: { ERR_EXPLAIN("Can't marshallize resources"); ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go } break;*/ case Variant::_RID: case Variant::OBJECT: { } break; case Variant::DICTIONARY: { Dictionary d = p_variant; if (buf) { encode_uint32(uint32_t(d.size()), buf); buf += 4; } r_len += 4; List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { /* CharString utf8 = E->->utf8(); if (buf) { encode_uint32(utf8.length()+1,buf); buf+=4; copymem(buf,utf8.get_data(),utf8.length()+1); } r_len+=4+utf8.length()+1; while (r_len%4) r_len++; //pad */ int len; encode_variant(E->get(), buf, len); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) buf += len; encode_variant(d[E->get()], buf, len); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) buf += len; } } break; case Variant::ARRAY: { Array v = p_variant; if (buf) { encode_uint32(uint32_t(v.size()), buf); buf += 4; } r_len += 4; for (int i = 0; i < v.size(); i++) { int len; encode_variant(v.get(i), buf, len); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) buf += len; } } break; // arrays case Variant::POOL_BYTE_ARRAY: { PoolVector<uint8_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(uint8_t); if (buf) { encode_uint32(datalen, buf); buf += 4; PoolVector<uint8_t>::Read r = data.read(); copymem(buf, &r[0], datalen * datasize); } r_len += 4 + datalen * datasize; while (r_len % 4) r_len++; } break; case Variant::POOL_INT_ARRAY: { PoolVector<int> data = p_variant; int datalen = data.size(); int datasize = sizeof(int32_t); if (buf) { encode_uint32(datalen, buf); buf += 4; PoolVector<int>::Read r = data.read(); for (int i = 0; i < datalen; i++) encode_uint32(r[i], &buf[i * datasize]); } r_len += 4 + datalen * datasize; } break; case Variant::POOL_REAL_ARRAY: { PoolVector<real_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(real_t); if (buf) { encode_uint32(datalen, buf); buf += 4; PoolVector<real_t>::Read r = data.read(); for (int i = 0; i < datalen; i++) encode_float(r[i], &buf[i * datasize]); } r_len += 4 + datalen * datasize; } break; case Variant::POOL_STRING_ARRAY: { PoolVector<String> data = p_variant; int len = data.size(); if (buf) { encode_uint32(len, buf); buf += 4; } r_len += 4; for (int i = 0; i < len; i++) { CharString utf8 = data.get(i).utf8(); if (buf) { encode_uint32(utf8.length() + 1, buf); buf += 4; copymem(buf, utf8.get_data(), utf8.length() + 1); buf += utf8.length() + 1; } r_len += 4 + utf8.length() + 1; while (r_len % 4) { r_len++; //pad if (buf) buf++; } } } break; case Variant::POOL_VECTOR2_ARRAY: { PoolVector<Vector2> data = p_variant; int len = data.size(); if (buf) { encode_uint32(len, buf); buf += 4; } r_len += 4; if (buf) { for (int i = 0; i < len; i++) { Vector2 v = data.get(i); encode_float(v.x, &buf[0]); encode_float(v.y, &buf[4]); buf += 4 * 2; } } r_len += 4 * 2 * len; } break; case Variant::POOL_VECTOR3_ARRAY: { PoolVector<Vector3> data = p_variant; int len = data.size(); if (buf) { encode_uint32(len, buf); buf += 4; } r_len += 4; if (buf) { for (int i = 0; i < len; i++) { Vector3 v = data.get(i); encode_float(v.x, &buf[0]); encode_float(v.y, &buf[4]); encode_float(v.z, &buf[8]); buf += 4 * 3; } } r_len += 4 * 3 * len; } break; case Variant::POOL_COLOR_ARRAY: { PoolVector<Color> data = p_variant; int len = data.size(); if (buf) { encode_uint32(len, buf); buf += 4; } r_len += 4; if (buf) { for (int i = 0; i < len; i++) { Color c = data.get(i); encode_float(c.r, &buf[0]); encode_float(c.g, &buf[4]); encode_float(c.b, &buf[8]); encode_float(c.a, &buf[12]); buf += 4 * 4; } } r_len += 4 * 4 * len; } break; default: { ERR_FAIL_V(ERR_BUG); } } return OK; }