bool GridClientObjectWrapperConvertor::wrapSimpleType(const GridClientVariant& var, ObjectWrapper& objWrapper) { objWrapper.set_type(NONE); GridClientVariantVisitorImpl visitor(objWrapper); objWrapper.set_binary((void*) NULL, 0); var.accept(visitor); return objWrapper.type() != NONE; }
static void wrapRequest(const GridClientMessageCommand& cmd, const ObjectWrapperType& type, const ::google::protobuf::Message& src, ObjectWrapper& objWrapper) { GG_LOG_DEBUG("Wrapping request: %s", src.DebugString().c_str()); ProtoRequest req; fillRequestHeader(cmd, req); objWrapper.set_type(type); int8_t * pBuffer; unsigned long bufferLength; GridClientProtobufMarshaller::marshalMsg(src, pBuffer, bufferLength); req.set_body(pBuffer, bufferLength); delete[] pBuffer; GridClientProtobufMarshaller::marshalMsg(req, pBuffer, bufferLength); objWrapper.set_binary(pBuffer, bufferLength); delete[] pBuffer; }
/** * Thread proc for marshalling specific types of messaging. * * @param messageType Type of messages to marshal. */ void run(ObjectWrapperType messageType) { using namespace org::gridgain::grid::kernal::processors::rest::client::message; iters = 0; try { bool unmarshal = vm["unmarshal"].as<bool>(); ObjectWrapper marshalledObject; int maxiterations = vm["nummessages"].as<int>(); if ((messageType > NONE && messageType <= STRING) || messageType == UUID) { GridClientVariant value; switch (messageType) { case BOOL: value = true; break; case BYTE: value = (int8_t) 42; break; case SHORT: value = (int16_t) 42; break; case INT32: value = (int32_t) 42; break; case INT64: value = (int64_t) 42; break; case FLOAT: value = (float) 0.42f; break; case DOUBLE: value = (double) 0.42f; break; case STRING: value = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; break; case UUID: { // block of code to avoid compilation error in gcc value.set(GridClientUuid("550e8400-e29b-41d4-a716-446655440000")); if (unmarshal) std::cerr << "Unmarshalling UUID is not supported yet"; } break; default: std::cerr << "Unsupported message type.\n"; return; } while (++iters != maxiterations) { GridClientObjectWrapperConvertor::wrapSimpleType(value, marshalledObject); if (unmarshal && messageType != UUID) { value.clear(); GridClientObjectWrapperConvertor::unwrapSimpleType(marshalledObject, value); } } } else { switch (messageType) { case CACHE_REQUEST: { // block of code to avoid compilation error in gcc GridCacheRequestCommand cmd = GridCacheRequestCommand( GridCacheRequestCommand::GridCacheOperation::PUT); cmd.sessionToken("Something"); cmd.setCacheName("partitioned"); cmd.setClientId(GridClientUuid("550e8400-e29b-41d4-a716-446655440000")); cmd.setDestinationId(GridClientUuid("550e8400-e29b-41d4-a716-446655440000")); cmd.setKey(42.0f); cmd.setRequestId(42); cmd.setValue(42.0f); // typical reply for cache PUT. 15 bytes length; unsigned char daReply[] = { 8, 0, 26, 5, 8, 1, 18, 1, 1, 34, 0 }; GridClientMessageCacheModifyResult resp; while (++iters != maxiterations) { GridClientProtobufMarshaller::wrap(cmd, marshalledObject); if (unmarshal) { marshalledObject.set_binary(daReply, sizeof(daReply)); marshalledObject.set_type(RESPONSE); GridClientProtobufMarshaller::unwrap(marshalledObject, resp); } } } break; case TOPOLOGY_REQUEST: { // block of code to avoid compilation error in gcc GridTopologyRequestCommand cmd; // typical reply for topology. Contains info about 2 local nodes. 185 bytes length; unsigned char daReply[] = { 8, 0, 26, 173, 1, 8, 10, 18, 168, 1, 10, 165, 1, 8, 60, 18, 160, 1, 10, 16, 6, 225, 6, 102, 61, 76, 77, 123, 129, 135, 99, 184, 120, 177, 249, 186, 18, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49, 26, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49, 32, 224, 78, 40, 144, 63, 74, 88, 10, 25, 10, 6, 8, 9, 18, 2, 116, 120, 18, 15, 8, 9, 18, 11, 80, 65, 82, 84, 73, 84, 73, 79, 78, 69, 68, 10, 28, 10, 9, 8, 9, 18, 5, 113, 117, 101, 114, 121, 18, 15, 8, 9, 18, 11, 80, 65, 82, 84, 73, 84, 73, 79, 78, 69, 68, 10, 29, 10, 10, 8, 9, 18, 6, 97, 116, 111, 109, 105, 99, 18, 15, 8, 9, 18, 11, 80, 65, 82, 84, 73, 84, 73, 79, 78, 69, 68, 104, 128, 1, 114, 19, 8, 9, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58, 52, 55, 53, 48, 48, 34, 0 }; GridClientMessageTopologyResult resp; while (++iters != maxiterations) { GridClientProtobufMarshaller::wrap(cmd, marshalledObject); if (unmarshal) { marshalledObject.set_binary(daReply, sizeof(daReply)); marshalledObject.set_type(RESPONSE); GridClientProtobufMarshaller::unwrap(marshalledObject, resp); } } } break; default: std::cerr << "Unsupported message type.\n"; return; } } } catch (GridClientException& e) { std::cerr << "GridClientException: " << e.what() << "\n"; exit(1); } catch (...) { std::cerr << "Unknown exception.\n"; exit(1); } }