简体   繁体   中英

The best way to handle serialized object from C# client in Node.js server env

What's the correct/mainstream way to handle byte arrays sent from C# client code to Node.js server environment?

Now I'm using standard C# serialization through BinaryWriter (client-side) and streambuf npm-package (server-side).

But I'm pretty sure that there is a more straightforward/native/mainstream/efficient way to do it.

What I have to do?

Thank you for your advices!

The mainstream way to convert an object to a serialized representation would be to use a serialization framework. If you are using node.js I would assume json would be most appropriate. I'm not familiar with Node.js, but my understanding is that it handles json natively. See also newtonsoft json for another very popular library.

If you need more a more compact serialization format you might take a look at protobuf since that serializes to a binary format. It looks like there are protobuf packages available for Node.js, but again, I have no familiarity with javascript.

Using an existing serialization format tend to make it easier to share objects between different systems since there are usually libraries available for most popular formats for the most common platforms. It usually also makes compatibility easier since many formats allow some flexibility for things like optional fields. So if you find that you need to add some more data you can often do so in the confidence that it will not break existing users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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