简体   繁体   English

从 std::string 创建 OssBitString?

[英]Creating a OssBitString from a std::string?

The OssBitString takes in string length (in bits) and a const unsigned char* as parameters. OssBitString 接受字符串长度(以位为单位)和一个 const unsigned char* 作为参数。 However, when I convert the input std::string to const unsigned char* and pass it to OssBitString, the contents of the string get modified and contains weird characters.但是,当我将输入的 std::string 转换为 const unsigned char* 并将其传递给 OssBitString 时,字符串的内容会被修改并包含奇怪的字符。 The following is the conversion function from std::string to OssBitString:下面是std::string到OssBitString的转换函数:

inline const OssBitString converter(const std::string&s, int size)
{ 
return OssBitString(size, reinterpret_cast<const unsigned char*>(s.c_str()))
}

I am not sure how to proceed.我不知道如何继续。 Also,I tried to convert the string into binary format and then convert as a OssBitString as well.另外,我尝试将字符串转换为二进制格式,然后也转换为 OssBitString。 But it did not work.但它没有用。 How to convert std::string to OssBitString then?那么如何将 std::string 转换为 OssBitString 呢?

Since you seem to be asking a question about a particular commercial ASN.1 Tool vendor's product, you should send your question directly to them.由于您似乎在询问有关特定商业 ASN.1 工具供应商产品的问题,因此您应该直接将您的问题发送给他们。 To reach OSS Nokalva's technical support, send an email to support@oss.com rather than asking your question here.要联系 OSS Nokalva 的技术支持,请发送电子邮件至 support@oss.com 而不是在这里提问。

Like such:像这样:

std::string my_str;

OssBitString my_bit_str;

my_bit_str.set(my_str.length(), my_str.data());

https://www.oss.com/asn1/products/documentation/asn1_cpp_6.7/asn1cpp-runtime-representation-classes.html#OssBitString_set_length_char https://www.oss.com/asn1/products/documentation/asn1_cpp_6.7/asn1cpp-runtime-representation-classes.html#OssBitString_set_length_char

The poor interface of OSS was a good motivator for my to write my own ASN.1 library. OSS 糟糕的界面是我编写自己的 ASN.1 库的一个很好的动力。 In fast_ber any string like type can be assigned to directly.在 fast_ber 中,可以直接分配任何类似类型的字符串。 Example of usage in fast_ber: fast_ber 中的用法示例:

https://github.com/Samuel-Tyler/fast_ber/blob/master/sample/encode/main.cpp https://github.com/Samuel-Tyler/fast_ber/blob/master/sample/encode/main.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM