![](/img/trans.png)
[英]c# MessagePack-CSharp all public members must mark KeyAttribute or IgnoreMemberAttribute. MyType member:
[英]Why C++ msgpack-c adds number 13 (0x0D) before number 10 (0x0A), but C# MessagePack-CSharp does not?
我试图使用MessagePack在C ++和Windows中的C#中将0到127之间的整数序列化,但是结果不一样。 msgpack-c在0x09和0x0A之间插入0x0D,但MessagePack-CSharp不插入。 这是为什么?
作业系统:Windows 10
IDE:Visual Studio 2019
C#
图书馆:
https://github.com/neuecc/MessagePack-CSharp
码:
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
using (FileStream fileStream = new FileStream("CSharp.msgpack", FileMode.Create, FileAccess.Write))
{
List<int> list = new List<int>();
for (int i = 0; i < 128; ++i)
{
list.Add(i);
}
MessagePackSerializer.Serialize(fileStream, list);
}
}
}
结果:
C ++
图书馆:
https://github.com/msgpack/msgpack-c
码:
#include <msgpack.hpp>
#include <vector>
#include <iostream>
#include <fstream>
int main(void)
{
std::ofstream OutputFileStream;
std::vector<int> list;
for (int i = 0; i < 128; ++i)
{
list.push_back(i);
}
OutputFileStream.open("Cpp.msgpack");
msgpack::pack(OutputFileStream, list);
OutputFileStream.close();
}
结果:
由于您是在C ++中以文本模式打开文件的,因此,如果Windows中不存在\\n
(ASCII 10),则每个\\n
(ASCII 10)都会带有\\r
(ASCII 13)。 您需要以二进制模式打开文件,以免发生这种情况。
OutputFileStream.open("Cpp.msgpack", std::ofstream::binary);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.