--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <cstring>
+
+#include "parcel-internal.h"
+
+namespace rpc_port {
+
+Parcel::Parcel(const unsigned char* buf, unsigned int size)
+ : data_(buf, buf + size) {
+ reader_ = data_.begin();
+}
+
+void Parcel::WriteByte(char b) {
+ Write<char>(b);
+}
+
+void Parcel::WriteInt16(short i) {
+ Write<short>(i);
+}
+
+void Parcel::WriteInt32(int i) {
+ Write<int>(i);
+}
+
+void Parcel::WriteInt64(long long i) {
+ Write<long long>(i);
+}
+
+void Parcel::WriteFloat(float f) {
+ Write<float>(f);
+}
+
+void Parcel::WriteDouble(double d) {
+ Write<double>(d);
+}
+
+void Parcel::WriteString(const char* str) {
+ int l = std::strlen(str) + 1;
+
+ Write<int>(l);
+ std::copy(str, str + l, std::back_inserter(data_));
+}
+
+void Parcel::WriteBool(bool b) {
+ Write<bool>(b);
+}
+
+void Parcel::WriteBundle(bundle* b) {
+ bundle_raw *r;
+ int len;
+ bundle_encode(b, &r, &len);
+ unsigned char* c = reinterpret_cast<unsigned char*>(r);
+
+ Write<int>(len + 1);
+ std::copy(c, c + len + 1, std::back_inserter(data_));
+}
+
+void Parcel::WriteArrayCount(int count) {
+ Write<int>(count);
+}
+
+char Parcel::ReadByte() {
+ return Read<char>();
+}
+
+short Parcel::ReadInt16() {
+ return Read<short>();
+}
+
+int Parcel::ReadInt32() {
+ return Read<int>();
+}
+
+long long Parcel::ReadInt64() {
+ return Read<long long>();
+}
+
+float Parcel::ReadFloat() {
+ return Read<float>();
+}
+
+double Parcel::ReadDouble() {
+ return Read<double>();
+}
+
+std::string Parcel::ReadString() {
+ int l = Read<int>();
+
+ std::string str(reader_, reader_ + l);
+ reader_ += l;
+
+ return str;
+}
+
+bool Parcel::ReadBool() {
+ return Read<bool>();
+}
+
+bundle* Parcel::ReadBundle() {
+ int l = Read<int>();
+
+ std::string str(reader_, reader_ + l);
+ reader_ += l;
+
+ bundle* b = bundle_decode(
+ reinterpret_cast<const bundle_raw*>(str.c_str()), l - 1);
+
+ return b;
+}
+
+int Parcel::ReadArrayCount() {
+ return Read<int>();
+}
+
+const std::vector<unsigned char>& Parcel::GetRaw() {
+ return data_;
+}
+
+} // namespace rpc_port
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PARCEL_INTERNAL_H__
+#define __PARCEL_INTERNAL_H__
+
+#include <bundle.h>
+
+#include <vector>
+#include <iterator>
+#include <algorithm>
+#include <string>
+
+namespace rpc_port {
+
+class Parcel {
+ public:
+ Parcel() = default;
+ Parcel(const unsigned char* buf, unsigned int size);
+
+ void WriteByte(char b);
+ void WriteInt16(short i);
+ void WriteInt32(int i);
+ void WriteInt64(long long i);
+ void WriteFloat(float f);
+ void WriteDouble(double d);
+ void WriteString(const char* str);
+ void WriteBool(bool b);
+ void WriteBundle(bundle* b);
+ void WriteArrayCount(int count);
+ char ReadByte();
+ short ReadInt16();
+ int ReadInt32();
+ long long ReadInt64();
+ float ReadFloat();
+ double ReadDouble();
+ std::string ReadString();
+ bool ReadBool();
+ bundle* ReadBundle();
+ int ReadArrayCount();
+ const std::vector<unsigned char>& GetRaw();
+
+ private:
+ template<typename T>
+ void Write(T d) {
+ unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+ std::copy(p, p + sizeof(T), std::back_inserter(data_));
+ }
+
+ template<typename T>
+ T Read() {
+ T d;
+ unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+ std::copy(reader_, reader_ + sizeof(T), p);
+ reader_ += sizeof(T);
+ return d;
+ }
+
+ private:
+ std::vector<unsigned char> data_;
+ std::vector<unsigned char>::iterator reader_;
+};
+
+}
+
+#endif // __PARCEL_INTERNAL_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "rpc-port-parcel.h"
+
+#undef RPC_API
+#define RPC_API extern "C" __attribute__((visibility("default")))
+
+RPC_API int rpc_port_parcel_create(rpc_port_parcel_h *h) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h,
+ rpc_port_h port) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_send(rpc_port_parcel_h *h, rpc_port_h port) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h,
+ rpc_port_parcelable_t *parcelable, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count) {
+ return 0;
+}
+
+RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h,
+ rpc_port_parcelable_t *parcelable, void *data) {
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include "rpc-port.h"
+
+#undef RPC_API
+#define RPC_API extern "C" __attribute__((visibility("default")))
+
+RPC_API int rpc_port_open(int fd, rpc_port_h *h) {
+ return 0;
+}
+
+RPC_API int rpc_port_close(rpc_port_h h) {
+ return 0;
+}
+
+RPC_API int rpc_port_read(rpc_port_h h, char *buf, unsigned int size) {
+ return 0;
+}
+
+RPC_API int rpc_port_write(rpc_port_h h, char *buf, unsigned int size) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_create(rpc_port_proxy_h *h) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid,
+ const char *port) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
+ rpc_port_proxy_connected_event_cb cb, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
+ rpc_port_proxy_disconnected_event_cb cb, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
+ rpc_port_proxy_rejected_event_cb cb, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
+ rpc_port_stub_connected_event_cb cb, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
+ rpc_port_stub_disconnected_event_cb cb, void *data) {
+ return 0;
+}
+
+RPC_API int rpc_port_stub_add_recevied_event_cb(rpc_port_stub_h h,
+ rpc_port_stub_received_event_cb cb, void *data) {
+ return 0;
+}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-
-#include "rpc-port.h"
-
-#undef RPC_API
-#define RPC_API extern "C" __attribute__((visibility("default")))
-
-RPC_API int rpc_port_open(int fd, rpc_port_h *h) {
- return 0;
-}
-
-RPC_API int rpc_port_close(rpc_port_h h) {
- return 0;
-}
-
-RPC_API int rpc_port_read(rpc_port_h h, char *buf, unsigned int size) {
- return 0;
-}
-
-RPC_API int rpc_port_write(rpc_port_h h, char *buf, unsigned int size) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_create(rpc_port_proxy_h *h) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid,
- const char *port) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
- rpc_port_proxy_connected_event_cb cb, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
- rpc_port_proxy_disconnected_event_cb cb, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
- rpc_port_proxy_rejected_event_cb cb, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
- rpc_port_stub_connected_event_cb cb, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
- rpc_port_stub_disconnected_event_cb cb, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_stub_add_recevied_event_cb(rpc_port_stub_h h,
- rpc_port_stub_received_event_cb cb, void *data) {
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rpc-port-parcel.h"
-
-#undef RPC_API
-#define RPC_API extern "C" __attribute__((visibility("default")))
-
-RPC_API int rpc_port_parcel_create(rpc_port_parcel_h *h) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h,
- rpc_port_h port) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_send(rpc_port_parcel_h *h, rpc_port_h port) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h,
- rpc_port_parcelable_t *parcelable, void *data) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count) {
- return 0;
-}
-
-RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h,
- rpc_port_parcelable_t *parcelable, void *data) {
- return 0;
-}