Skip to content

Commit

Permalink
Implemented new Binary Encoding spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderoster committed Jun 8, 2024
1 parent b817e32 commit 2f3952c
Show file tree
Hide file tree
Showing 33 changed files with 689 additions and 205 deletions.
22 changes: 17 additions & 5 deletions Autogenerated/Bindings/C/lib3mf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,26 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_base_classtypeid(Lib3MF_Base pBase, Lib3MF_u
**************************************************************************************************************************/

/**
* Retrieves an binary streams package path.
* Retrieves an binary streams package path for the binary data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package path., may be NULL
* @param[out] pPathBuffer - buffer of binary streams package binary path., may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getpath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getbinarypath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams package path for the index data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package index path., may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getindexpath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams uuid.
Expand Down Expand Up @@ -264,11 +275,12 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_setcontentencryptioncallback(Lib3MF_W
* Creates a binary stream object. Only applicable for 3MF Writers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pPath - Package path to write into
* @param[in] pIndexPath - Package path to write the index into
* @param[in] pBinaryPath - Package path to write raw binary data into
* @param[out] pBinaryStream - Returns a package path.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pIndexPath, const char * pBinaryPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
Expand Down
18 changes: 14 additions & 4 deletions Autogenerated/Bindings/CDynamic/lib3mf_dynamic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Lib3MFResult InitLib3MFWrapperTable(sLib3MFDynamicWrapperTable * pWrapperTable)

pWrapperTable->m_LibraryHandle = NULL;
pWrapperTable->m_Base_ClassTypeId = NULL;
pWrapperTable->m_BinaryStream_GetPath = NULL;
pWrapperTable->m_BinaryStream_GetBinaryPath = NULL;
pWrapperTable->m_BinaryStream_GetIndexPath = NULL;
pWrapperTable->m_BinaryStream_GetUUID = NULL;
pWrapperTable->m_BinaryStream_DisableDiscretizedArrayCompression = NULL;
pWrapperTable->m_BinaryStream_EnableDiscretizedArrayCompression = NULL;
Expand Down Expand Up @@ -604,12 +605,21 @@ Lib3MFResult LoadLib3MFWrapperTable(sLib3MFDynamicWrapperTable * pWrapperTable,
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_GetPath = (PLib3MFBinaryStream_GetPathPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_getpath");
pWrapperTable->m_BinaryStream_GetBinaryPath = (PLib3MFBinaryStream_GetBinaryPathPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_getbinarypath");
#else // _WIN32
pWrapperTable->m_BinaryStream_GetPath = (PLib3MFBinaryStream_GetPathPtr) dlsym(hLibrary, "lib3mf_binarystream_getpath");
pWrapperTable->m_BinaryStream_GetBinaryPath = (PLib3MFBinaryStream_GetBinaryPathPtr) dlsym(hLibrary, "lib3mf_binarystream_getbinarypath");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_GetPath == NULL)
if (pWrapperTable->m_BinaryStream_GetBinaryPath == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_GetIndexPath = (PLib3MFBinaryStream_GetIndexPathPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_getindexpath");
#else // _WIN32
pWrapperTable->m_BinaryStream_GetIndexPath = (PLib3MFBinaryStream_GetIndexPathPtr) dlsym(hLibrary, "lib3mf_binarystream_getindexpath");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_GetIndexPath == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
Expand Down
25 changes: 19 additions & 6 deletions Autogenerated/Bindings/CDynamic/lib3mf_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,26 @@ typedef Lib3MFResult (*PLib3MFBase_ClassTypeIdPtr) (Lib3MF_Base pBase, Lib3MF_ui
**************************************************************************************************************************/

/**
* Retrieves an binary streams package path.
* Retrieves an binary streams package path for the binary data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package path., may be NULL
* @param[out] pPathBuffer - buffer of binary streams package binary path., may be NULL
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_GetPathPtr) (Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);
typedef Lib3MFResult (*PLib3MFBinaryStream_GetBinaryPathPtr) (Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams package path for the index data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package index path., may be NULL
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_GetIndexPathPtr) (Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams uuid.
Expand Down Expand Up @@ -251,11 +262,12 @@ typedef Lib3MFResult (*PLib3MFWriter_SetContentEncryptionCallbackPtr) (Lib3MF_Wr
* Creates a binary stream object. Only applicable for 3MF Writers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pPath - Package path to write into
* @param[in] pIndexPath - Package path to write the index into
* @param[in] pBinaryPath - Package path to write raw binary data into
* @param[out] pBinaryStream - Returns a package path.
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFWriter_CreateBinaryStreamPtr) (Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);
typedef Lib3MFResult (*PLib3MFWriter_CreateBinaryStreamPtr) (Lib3MF_Writer pWriter, const char * pIndexPath, const char * pBinaryPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
Expand Down Expand Up @@ -5146,7 +5158,8 @@ typedef Lib3MFResult (*PLib3MFGetTranslationTransformPtr) (Lib3MF_single fVector
typedef struct {
void * m_LibraryHandle;
PLib3MFBase_ClassTypeIdPtr m_Base_ClassTypeId;
PLib3MFBinaryStream_GetPathPtr m_BinaryStream_GetPath;
PLib3MFBinaryStream_GetBinaryPathPtr m_BinaryStream_GetBinaryPath;
PLib3MFBinaryStream_GetIndexPathPtr m_BinaryStream_GetIndexPath;
PLib3MFBinaryStream_GetUUIDPtr m_BinaryStream_GetUUID;
PLib3MFBinaryStream_DisableDiscretizedArrayCompressionPtr m_BinaryStream_DisableDiscretizedArrayCompression;
PLib3MFBinaryStream_EnableDiscretizedArrayCompressionPtr m_BinaryStream_EnableDiscretizedArrayCompression;
Expand Down
36 changes: 27 additions & 9 deletions Autogenerated/Bindings/CSharp/Lib3MF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,11 @@ public class Lib3MFWrapper
[DllImport("lib3mf.dll", EntryPoint = "lib3mf_base_classtypeid", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 Base_ClassTypeId (IntPtr Handle, out UInt64 AClassTypeId);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_getpath", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_GetPath (IntPtr Handle, UInt32 sizePath, out UInt32 neededPath, IntPtr dataPath);
[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_getbinarypath", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_GetBinaryPath (IntPtr Handle, UInt32 sizePath, out UInt32 neededPath, IntPtr dataPath);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_getindexpath", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_GetIndexPath (IntPtr Handle, UInt32 sizePath, out UInt32 neededPath, IntPtr dataPath);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_getuuid", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_GetUUID (IntPtr Handle, UInt32 sizeUUID, out UInt32 neededUUID, IntPtr dataUUID);
Expand Down Expand Up @@ -411,7 +414,7 @@ public class Lib3MFWrapper
public unsafe extern static Int32 Writer_SetContentEncryptionCallback (IntPtr Handle, IntPtr ATheCallback, UInt64 AUserData);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_writer_createbinarystream", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 Writer_CreateBinaryStream (IntPtr Handle, byte[] APath, out IntPtr ABinaryStream);
public unsafe extern static Int32 Writer_CreateBinaryStream (IntPtr Handle, byte[] AIndexPath, byte[] ABinaryPath, out IntPtr ABinaryStream);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_writer_assignbinarystream", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 Writer_AssignBinaryStream (IntPtr Handle, IntPtr AInstance, IntPtr ABinaryStream);
Expand Down Expand Up @@ -2255,16 +2258,30 @@ public CBinaryStream (IntPtr NewHandle) : base (NewHandle)
{
}

public String GetPath ()
public String GetBinaryPath ()
{
UInt32 sizePath = 0;
UInt32 neededPath = 0;
CheckError(Internal.Lib3MFWrapper.BinaryStream_GetBinaryPath (Handle, sizePath, out neededPath, IntPtr.Zero));
sizePath = neededPath;
byte[] bytesPath = new byte[sizePath];
GCHandle dataPath = GCHandle.Alloc(bytesPath, GCHandleType.Pinned);

CheckError(Internal.Lib3MFWrapper.BinaryStream_GetBinaryPath (Handle, sizePath, out neededPath, dataPath.AddrOfPinnedObject()));
dataPath.Free();
return Encoding.UTF8.GetString(bytesPath).TrimEnd(char.MinValue);
}

public String GetIndexPath ()
{
UInt32 sizePath = 0;
UInt32 neededPath = 0;
CheckError(Internal.Lib3MFWrapper.BinaryStream_GetPath (Handle, sizePath, out neededPath, IntPtr.Zero));
CheckError(Internal.Lib3MFWrapper.BinaryStream_GetIndexPath (Handle, sizePath, out neededPath, IntPtr.Zero));
sizePath = neededPath;
byte[] bytesPath = new byte[sizePath];
GCHandle dataPath = GCHandle.Alloc(bytesPath, GCHandleType.Pinned);

CheckError(Internal.Lib3MFWrapper.BinaryStream_GetPath (Handle, sizePath, out neededPath, dataPath.AddrOfPinnedObject()));
CheckError(Internal.Lib3MFWrapper.BinaryStream_GetIndexPath (Handle, sizePath, out neededPath, dataPath.AddrOfPinnedObject()));
dataPath.Free();
return Encoding.UTF8.GetString(bytesPath).TrimEnd(char.MinValue);
}
Expand Down Expand Up @@ -2419,12 +2436,13 @@ public void SetContentEncryptionCallback (IntPtr ATheCallback, UInt64 AUserData)
CheckError(Internal.Lib3MFWrapper.Writer_SetContentEncryptionCallback (Handle, ATheCallback, AUserData));
}

public CBinaryStream CreateBinaryStream (String APath)
public CBinaryStream CreateBinaryStream (String AIndexPath, String ABinaryPath)
{
byte[] bytePath = Encoding.UTF8.GetBytes(APath + char.MinValue);
byte[] byteIndexPath = Encoding.UTF8.GetBytes(AIndexPath + char.MinValue);
byte[] byteBinaryPath = Encoding.UTF8.GetBytes(ABinaryPath + char.MinValue);
IntPtr newBinaryStream = IntPtr.Zero;

CheckError(Internal.Lib3MFWrapper.Writer_CreateBinaryStream (Handle, bytePath, out newBinaryStream));
CheckError(Internal.Lib3MFWrapper.Writer_CreateBinaryStream (Handle, byteIndexPath, byteBinaryPath, out newBinaryStream));
return Internal.Lib3MFWrapper.PolymorphicFactory<CBinaryStream>(newBinaryStream);
}

Expand Down
22 changes: 17 additions & 5 deletions Autogenerated/Bindings/Cpp/lib3mf_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,26 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_base_classtypeid(Lib3MF_Base pBase, Lib3MF_u
**************************************************************************************************************************/

/**
* Retrieves an binary streams package path.
* Retrieves an binary streams package path for the binary data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package path., may be NULL
* @param[out] pPathBuffer - buffer of binary streams package binary path., may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getpath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getbinarypath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams package path for the index data.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nPathBufferSize - size of the buffer (including trailing 0)
* @param[out] pPathNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pPathBuffer - buffer of binary streams package index path., may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getindexpath(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nPathBufferSize, Lib3MF_uint32* pPathNeededChars, char * pPathBuffer);

/**
* Retrieves an binary streams uuid.
Expand Down Expand Up @@ -264,11 +275,12 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_setcontentencryptioncallback(Lib3MF_W
* Creates a binary stream object. Only applicable for 3MF Writers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pPath - Package path to write into
* @param[in] pIndexPath - Package path to write the index into
* @param[in] pBinaryPath - Package path to write raw binary data into
* @param[out] pBinaryStream - Returns a package path.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pIndexPath, const char * pBinaryPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
Expand Down
37 changes: 27 additions & 10 deletions Autogenerated/Bindings/Cpp/lib3mf_implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ class CBinaryStream : public CBase {
{
}

inline std::string GetPath();
inline std::string GetBinaryPath();
inline std::string GetIndexPath();
inline std::string GetUUID();
inline void DisableDiscretizedArrayCompression();
inline void EnableDiscretizedArrayCompression(const Lib3MF_double dUnits, const eBinaryStreamPredictionType ePredictionType);
Expand Down Expand Up @@ -756,7 +757,7 @@ class CWriter : public CBase {
inline Lib3MF_uint32 GetWarningCount();
inline void AddKeyWrappingCallback(const std::string & sConsumerID, const KeyWrappingCallback pTheCallback, const Lib3MF_pvoid pUserData);
inline void SetContentEncryptionCallback(const ContentEncryptionCallback pTheCallback, const Lib3MF_pvoid pUserData);
inline PBinaryStream CreateBinaryStream(const std::string & sPath);
inline PBinaryStream CreateBinaryStream(const std::string & sIndexPath, const std::string & sBinaryPath);
inline void AssignBinaryStream(classParam<CBase> pInstance, classParam<CBinaryStream> pBinaryStream);
inline void RegisterCustomNamespace(const std::string & sPrefix, const std::string & sNameSpace);
};
Expand Down Expand Up @@ -2382,16 +2383,31 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
*/

/**
* CBinaryStream::GetPath - Retrieves an binary streams package path.
* @return binary streams package path.
* CBinaryStream::GetBinaryPath - Retrieves an binary streams package path for the binary data.
* @return binary streams package binary path.
*/
std::string CBinaryStream::GetBinaryPath()
{
Lib3MF_uint32 bytesNeededPath = 0;
Lib3MF_uint32 bytesWrittenPath = 0;
CheckError(lib3mf_binarystream_getbinarypath(m_pHandle, 0, &bytesNeededPath, nullptr));
std::vector<char> bufferPath(bytesNeededPath);
CheckError(lib3mf_binarystream_getbinarypath(m_pHandle, bytesNeededPath, &bytesWrittenPath, &bufferPath[0]));

return std::string(&bufferPath[0]);
}

/**
* CBinaryStream::GetIndexPath - Retrieves an binary streams package path for the index data.
* @return binary streams package index path.
*/
std::string CBinaryStream::GetPath()
std::string CBinaryStream::GetIndexPath()
{
Lib3MF_uint32 bytesNeededPath = 0;
Lib3MF_uint32 bytesWrittenPath = 0;
CheckError(lib3mf_binarystream_getpath(m_pHandle, 0, &bytesNeededPath, nullptr));
CheckError(lib3mf_binarystream_getindexpath(m_pHandle, 0, &bytesNeededPath, nullptr));
std::vector<char> bufferPath(bytesNeededPath);
CheckError(lib3mf_binarystream_getpath(m_pHandle, bytesNeededPath, &bytesWrittenPath, &bufferPath[0]));
CheckError(lib3mf_binarystream_getindexpath(m_pHandle, bytesNeededPath, &bytesWrittenPath, &bufferPath[0]));

return std::string(&bufferPath[0]);
}
Expand Down Expand Up @@ -2599,13 +2615,14 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)

/**
* CWriter::CreateBinaryStream - Creates a binary stream object. Only applicable for 3MF Writers.
* @param[in] sPath - Package path to write into
* @param[in] sIndexPath - Package path to write the index into
* @param[in] sBinaryPath - Package path to write raw binary data into
* @return Returns a package path.
*/
PBinaryStream CWriter::CreateBinaryStream(const std::string & sPath)
PBinaryStream CWriter::CreateBinaryStream(const std::string & sIndexPath, const std::string & sBinaryPath)
{
Lib3MFHandle hBinaryStream = nullptr;
CheckError(lib3mf_writer_createbinarystream(m_pHandle, sPath.c_str(), &hBinaryStream));
CheckError(lib3mf_writer_createbinarystream(m_pHandle, sIndexPath.c_str(), sBinaryPath.c_str(), &hBinaryStream));

if (!hBinaryStream) {
CheckError(LIB3MF_ERROR_INVALIDPARAM);
Expand Down
Loading

0 comments on commit 2f3952c

Please sign in to comment.