* limitations under the License.
*/
+#include <glib.h>
+
#include "parcel/common.hh"
#include "parcel/log_private.hh"
#include "parcel/parcel.hh"
namespace tizen_base {
-Parcel::Impl::Impl(Parcel* parent) : parent_(parent) {
+Parcel::Impl::Impl(Parcel* parent, bool big_endian)
+ : parent_(parent), big_endian_(big_endian) {
}
Parcel::Impl::~Impl() = default;
}
void Parcel::Impl::WriteSize(uint32_t size) {
+ if (IsBigEndian())
+ size = GUINT32_TO_BE(size);
+
auto* p = reinterpret_cast<uint8_t*>(&size);
std::copy(p, p + sizeof(size), std::back_inserter(data_));
}
auto* p = reinterpret_cast<uint8_t*>(size);
std::copy(&data_[reader_], &data_[reader_] + sizeof(uint32_t), p);
reader_ += sizeof(uint32_t);
+
+ if (IsBigEndian())
+ *size = GUINT32_FROM_BE(*size);
+
return TIZEN_ERROR_NONE;
}
return TIZEN_ERROR_NONE;
}
-Parcel::Parcel() : impl_(new Impl(this)) {
+void Parcel::Impl::SetByteOrder(bool big_endian) {
+ big_endian_ = big_endian;
}
-Parcel::Parcel(const void* buf, uint32_t size) : impl_(new Impl(this)) {
+bool Parcel::Impl::IsBigEndian() {
+ return big_endian_;
+}
+
+Parcel::Parcel(bool big_endian) : impl_(new Impl(this, big_endian)) {
+}
+
+Parcel::Parcel(const void* buf, uint32_t size, bool big_endian)
+ : impl_(new Impl(this, big_endian)) {
impl_->Write(buf, size);
}
Parcel::Parcel(const Parcel& p)
: impl_(new Impl(this)) {
+ impl_->big_endian_ = p.impl_->big_endian_;
std::copy(p.impl_->data_.begin(), p.impl_->data_.end(),
std::back_inserter(impl_->data_));
impl_->reader_ = p.impl_->reader_;
Parcel& Parcel::operator = (const Parcel& p) {
if (this != &p) {
+ impl_->big_endian_ = p.impl_->big_endian_;
std::copy(p.impl_->data_.begin(), p.impl_->data_.end(),
std::back_inserter(impl_->data_));
impl_->reader_ = p.impl_->reader_;
Parcel& Parcel::operator = (Parcel&& p) noexcept {
if (this != &p) {
+ impl_->big_endian_ = p.impl_->big_endian_;
impl_->data_ = std::move(p.impl_->data_);
impl_->reader_ = p.impl_->reader_;
p.impl_->reader_ = 0;
}
void Parcel::WriteUInt16(uint16_t val) {
+ if (impl_->IsBigEndian())
+ val = GUINT16_TO_BE(val);
+
impl_->Write<uint16_t>(val);
}
void Parcel::WriteUInt32(uint32_t val) {
+ if (impl_->IsBigEndian())
+ val = GUINT32_TO_BE(val);
+
impl_->Write<uint32_t>(val);
}
void Parcel::WriteUInt64(uint64_t val) {
+ if (impl_->IsBigEndian())
+ val = GUINT64_TO_BE(val);
+
impl_->Write<uint64_t>(val);
}
void Parcel::WriteInt16(int16_t val) {
+ if (impl_->IsBigEndian())
+ val = GINT16_TO_BE(val);
+
impl_->Write<int16_t>(val);
}
void Parcel::WriteInt32(int32_t val) {
+ if (impl_->IsBigEndian())
+ val = GINT32_TO_BE(val);
+
impl_->Write<int32_t>(val);
}
void Parcel::WriteInt64(int64_t val) {
+ if (impl_->IsBigEndian())
+ val = GINT64_TO_BE(val);
+
impl_->Write<int64_t>(val);
}
void Parcel::WriteFloat(float val) {
+ if (impl_->IsBigEndian())
+ val = static_cast<float>(GINT32_TO_BE(val));
+
impl_->Write<float>(val);
}
void Parcel::WriteDouble(double val) {
+ if (impl_->IsBigEndian())
+ val = static_cast<double>(GINT64_TO_BE(val));
+
impl_->Write<double>(val);
}
}
int Parcel::ReadUInt16(uint16_t* val) {
- return impl_->Read<uint16_t>(val);
+ int ret = impl_->Read<uint16_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GUINT16_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadUInt32(uint32_t* val) {
- return impl_->Read<uint32_t>(val);
+ int ret = impl_->Read<uint32_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GUINT32_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadUInt64(uint64_t* val) {
- return impl_->Read<uint64_t>(val);
+ int ret = impl_->Read<uint64_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GUINT64_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadInt16(int16_t* val) {
- return impl_->Read<int16_t>(val);
+ int ret = impl_->Read<int16_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GINT16_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadInt32(int32_t* val) {
- return impl_->Read<int32_t>(val);
+ int ret = impl_->Read<int32_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GINT32_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadInt64(int64_t* val) {
- return impl_->Read<int64_t>(val);
+ int ret = impl_->Read<int64_t>(val);
+ if (impl_->IsBigEndian())
+ *val = GINT64_FROM_BE(*val);
+
+ return ret;
}
int Parcel::ReadFloat(float* val) {
- return impl_->Read<float>(val);
+ int ret = impl_->Read<float>(val);
+ if (impl_->IsBigEndian())
+ *val = static_cast<float>(GINT32_FROM_BE(*val));
+
+ return ret;
}
int Parcel::ReadDouble(double* val) {
- return impl_->Read<double>(val);
+ int ret = impl_->Read<double>(val);
+ if (impl_->IsBigEndian())
+ *val = static_cast<double>(GINT64_FROM_BE(*val));
+
+ return ret;
}
std::string Parcel::ReadString() {
return TIZEN_ERROR_NONE;
}
+void Parcel::SetByteOrder(bool big_endian) {
+ impl_->SetByteOrder(big_endian);
+}
+
} // naemspace tizen_base