Converting back a Byte Array

I have a java method that sends a czml file through a socket to the Cesium server. The czml gets encoded into a byte array for transfer, and upon arrival in Cesium is decoded with String.fromCharCode() and saved to a variable. Putting this output to the log gives the correct czml formatting and data as the original, so I know that I’m getting the expected data types in the socket.
After this the Cesium server sends the previously mentioned variable through a websocket to CesiumViewer.js, where I want to add it as a data source and display it. I know everything is getting passed through the sockets correctly because if I log the data received by the client websocket I also get the correct czml formatting as an output. The problem is that trying to process it with the usual cesium calls does nothing, and the error I get is:
uncaught exception: RuntimeError: The first CZML packet is required to be the document object.

I am using czmlDataSource.process(msg) to try and add the data sent through the socket, where msg is the data sent through the websocket. I assume this is probably the wrong way to be going about this, but I haven’t been able to find another way to do this. I think this exception is being thrown because the msg being sent through the socket isn’t an actual .czml file, just a long string that is formatted as a czml.

Should I be trying to write the msg to a temporary file before processing it, or maybe there’s another Cesium function that I have overlooked? Thanks for any advice you may have, I’m looking forward to figuring this last little bit out.


I was able to figure out my missing bit of code. I’m posting for anyone to use as a reference in the future.

The bit I was missing was to use JSON.parse(msg) after receiving the data through the websocket. My client code for the websocket is as follows:

socket.on(‘data’, function(msg) {
var czml = JSON.parse(msg);