25#include <com/sun/star/uno/RuntimeException.hpp>
26#include <com/sun/star/uno/Sequence.hxx>
28#include <rtl/byteseq.hxx>
29#include <rtl/string.hxx>
30#include <rtl/textcvt.h>
31#include <rtl/textenc.h>
32#include <rtl/ustring.h>
33#include <rtl/ustring.hxx>
35#include <typelib/typeclass.h>
36#include <typelib/typedescription.h>
37#include <typelib/typedescription.hxx>
38#include <uno/dispatcher.hxx>
50void write64(std::vector< unsigned char > * buffer, sal_uInt64 value) {
61void writeCompressed(std::vector< unsigned char > * buffer, sal_uInt32 value) {
71 std::vector< unsigned char > * buffer, OUString
const & value)
73 assert(buffer !=
nullptr);
75 if (!
value.convertToString(
76 &v, RTL_TEXTENCODING_UTF8,
77 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
78 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
80 throw css::uno::RuntimeException(
81 "UNO string contains invalid UTF-16 sequence");
83 writeCompressed(buffer,
static_cast< sal_uInt32
>(
v.getLength()));
84 buffer->insert(buffer->end(),
v.getStr(),
v.getStr() +
v.getLength());
90 bridge_(bridge), state_(state)
98 assert(buffer !=
nullptr);
99 buffer->push_back(
value);
115 std::vector< unsigned char > * buffer,
116 css::uno::TypeDescription
const & type,
BinaryAny const & value)
120 (
type.get()->eTypeClass == typelib_TypeClass_ANY ||
121 value.getType().equals(type)));
126 std::vector< unsigned char > * buffer,
127 css::uno::TypeDescription
const & value)
129 value.makeComplete();
131 typelib_TypeClass tc =
value.get()->eTypeClass;
132 if (tc <= typelib_TypeClass_ANY) {
149 std::vector< unsigned char > * buffer, OUString
const & oid)
153 if ( oid.isEmpty() ) {
168 std::vector< unsigned char > * buffer, rtl::ByteSequence
const & tid)
178 css::uno::TypeDescription(
185 std::vector< unsigned char > * buffer,
186 css::uno::TypeDescription
const & type,
void const * value)
188 assert(buffer !=
nullptr &&
type.is());
190 switch (
type.get()->eTypeClass) {
191 case typelib_TypeClass_VOID:
193 case typelib_TypeClass_BOOLEAN:
194 assert(*
static_cast< sal_uInt8 const *
>(value) <= 1);
196 case typelib_TypeClass_BYTE:
199 case typelib_TypeClass_SHORT:
200 case typelib_TypeClass_UNSIGNED_SHORT:
201 case typelib_TypeClass_CHAR:
202 write16(buffer, *
static_cast< sal_uInt16
const *
>(value));
204 case typelib_TypeClass_LONG:
205 case typelib_TypeClass_UNSIGNED_LONG:
206 case typelib_TypeClass_FLOAT:
207 case typelib_TypeClass_ENUM:
208 write32(buffer, *
static_cast< sal_uInt32
const *
>(value));
210 case typelib_TypeClass_HYPER:
211 case typelib_TypeClass_UNSIGNED_HYPER:
212 case typelib_TypeClass_DOUBLE:
213 write64(buffer, *
static_cast< sal_uInt64
const *
>(value));
215 case typelib_TypeClass_STRING:
218 OUString(*
static_cast< rtl_uString *
const *
>(value)));
220 case typelib_TypeClass_TYPE:
223 css::uno::TypeDescription(
224 *
static_cast< typelib_TypeDescriptionReference *
const *
>(
227 case typelib_TypeClass_ANY:
230 css::uno::TypeDescription
t(
p->pType);
235 case typelib_TypeClass_SEQUENCE:
238 writeCompressed(buffer,
static_cast< sal_uInt32
>(
p->nElements));
239 css::uno::TypeDescription ctd(
240 reinterpret_cast< typelib_IndirectTypeDescription *
>(
244 if (ctd.get()->eTypeClass == typelib_TypeClass_BYTE) {
246 buffer->end(),
p->elements,
p->elements +
p->nElements);
248 for (sal_Int32 i = 0;
i !=
p->nElements; ++
i) {
249 writeValue(buffer, ctd,
p->elements + i * ctd.get()->nSize);
254 case typelib_TypeClass_STRUCT:
255 case typelib_TypeClass_EXCEPTION:
258 case typelib_TypeClass_INTERFACE:
261 bridge_->registerOutgoingInterface(
262 css::uno::UnoInterfaceReference(
263 *
static_cast< uno_Interface *
const *
>(value)),
273 std::vector< unsigned char > * buffer,
274 css::uno::TypeDescription
const & type,
void const * aggregateValue)
278 (
type.get()->eTypeClass == typelib_TypeClass_STRUCT ||
279 type.get()->eTypeClass == typelib_TypeClass_EXCEPTION) &&
280 aggregateValue !=
nullptr);
282 typelib_CompoundTypeDescription * ctd =
283 reinterpret_cast< typelib_CompoundTypeDescription *
>(
type.get());
284 if (ctd->pBaseTypeDescription !=
nullptr) {
287 css::uno::TypeDescription(&ctd->pBaseTypeDescription->aBase),
290 for (sal_Int32
i = 0;
i != ctd->nMembers; ++
i) {
292 buffer, css::uno::TypeDescription(ctd->ppTypeRefs[
i]),
293 (
static_cast< char const *
>(aggregateValue) +
294 ctd->pMemberOffsets[
i]));
IdxType add(const T &rContent, bool *pbFound)
static void write16(std::vector< unsigned char > *buffer, sal_uInt16 value)
void writeType(std::vector< unsigned char > *buffer, com::sun::star::uno::TypeDescription const &value)
void writeValue(std::vector< unsigned char > *buffer, com::sun::star::uno::TypeDescription const &type, BinaryAny const &value)
rtl::Reference< Bridge > bridge_
void writeTid(std::vector< unsigned char > *buffer, rtl::ByteSequence const &tid)
void writeOid(std::vector< unsigned char > *buffer, OUString const &oid)
Marshal(rtl::Reference< Bridge > const &bridge, WriterState &state)
static void write32(std::vector< unsigned char > *buffer, sal_uInt32 value)
static void write8(std::vector< unsigned char > *buffer, sal_uInt8 value)
void writeMemberValues(std::vector< unsigned char > *buffer, com::sun::star::uno::TypeDescription const &type, void const *aggregateValue)
css::uno::UnoInterfaceReference get()
sal_uInt32 writeString(sal_uInt8 *buffer, const sal_Unicode *v)
Cache< rtl::ByteSequence > tidCache
Cache< OUString > oidCache
Cache< com::sun::star::uno::TypeDescription > typeCache