Qpid .NET Messaging API  0.22
QpidMarshal.h
Go to the documentation of this file.
00001 /*
00002 * Licensed to the Apache Software Foundation (ASF) under one
00003 * or more contributor license agreements.  See the NOTICE file
00004 * distributed with this work for additional information
00005 * regarding copyright ownership.  The ASF licenses this file
00006 * to you under the Apache License, Version 2.0 (the
00007 * "License"); you may not use this file except in compliance
00008 * with the License.  You may obtain a copy of the License at
00009 *
00010 *   http://www.apache.org/licenses/LICENSE-2.0
00011 *
00012 * Unless required by applicable law or agreed to in writing,
00013 * software distributed under the License is distributed on an
00014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015 * KIND, either express or implied.  See the License for the
00016 * specific language governing permissions and limitations
00017 * under the License.
00018 */
00019 
00020 #pragma once
00021 
00022 using namespace System;
00023 using namespace System::Text;
00024 
00025 namespace Org {
00026 namespace Apache {
00027 namespace Qpid {
00028 namespace Messaging {
00029 
00030 
00031 
00032 // Helper functions for marshaling.
00033 
00034 private ref class QpidMarshal
00035 {
00036 private:
00037     QpidMarshal::QpidMarshal() {}
00038 
00039 public:
00040 
00045 
00046     static std::string ToNative (System::String^ managed)
00047     {
00048         if (managed->Length == 0)
00049         {
00050             return std::string();
00051         }
00052 
00053         array<unsigned char>^ mbytes = Encoding::UTF8->GetBytes(managed);
00054         if (mbytes->Length == 0)
00055         {
00056             return std::string();
00057         }
00058 
00059         pin_ptr<unsigned char> pinnedBuf = &mbytes[0];
00060         std::string native((char *) pinnedBuf, mbytes->Length);
00061         return native;
00062     }
00063 };
00064 
00065 }}}}