How to convert IStream(C++) to System::IO::Stream(c#) and vice versa

  • Thread starter Thread starter Sowmya Dantuluri
  • Start date Start date
S

Sowmya Dantuluri

Guest
I have 2 libraries one is written in c++ and the other one is written in c#.

Name of C++ library ->LibA

Name of C# library ->LibB

In LibA, 2 main APIs will be there:

  1. Serialize-> Serialize API will generate IStream as output with the given inputs.
  2. Deserialize-> Deserialize API will take IStream as input and deserializes the stream and gets actual data from it.

struct GPosition
{
double x;
double y;
double z;
};
struct GUnitVector
{
double x;
double y;
double z;
};
struct GLine
{
GPosition m_rootPoint; /* Point on the line, should be in region of interest */
GUnitVector m_direction; /* Gradient */
double m_start; /* Parameter of start point, must be <= m_end */
double m_end; /* Parameter of end point */
};



class GraphicSerializer
{
public:

GUID objectID;

uint32_t aspectID;
uint32_t controlFlag;
vector<const GLine *> geomVector;

void Serialize(IStream &pStream);
void Deserialize(IStream* pStream);
};


In LibB, 4 APIs will be there:

  1. Object GetObjectFromStream(Stream s)-> Takes stream as input and deserializes it and returns Objects
  2. PutToDB(Object A)-> persists the given object to DB
  3. Stream GetStreamFromObject(Object a)-> Takes object as input serializes it and returns it.
  4. Object GetFromDB(objectID)-> Gets the object from DB based on id

public class CommonBase
{
public Guid id { get; set; };
public byte[] Bytes { get; set; } //contains aspect, control flag, vector<GLine>
};

public interface IGraphicRepository
{
CommonBase Get(Guid guid);
bool Put(CommonBase graphic);
}

public static class GraphicStreamUtility
{
public static CommonBase GetCommonBaseFromStream(Stream stream);
public static void SerializeCommonBaseToStream(CommonBase obj, Stream stream);
}

Now I'm writing C++/CLI to use stream generated by libA in libB and vice versa. So that I can persist and retrieve the objects to and from DB.

Can anyone please let me know how to convert IStream to .Net Stream and .Net stream to IStream.

Continue reading...
 
Back
Top