Created
September 7, 2015 15:05
-
-
Save strich/e9af82584ef8186afa21 to your computer and use it in GitHub Desktop.
Unity binary file deserialization.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //The current format is stored in the endianess of the platform that records it, and then swizzled into place in the editor strings are then handled specially | |
| //Here are some sniplets from the current deserialization: | |
| int dataIsLittleEndian = *((*bitstream)++); | |
| bool shouldswap = UNITY_LITTLE_ENDIAN ? dataIsLittleEndian == 0 : dataIsLittleEndian != 0; | |
| if(shouldswap) | |
| { | |
| int* ptr = *bitstream; | |
| while(ptr < endBuffer) | |
| SwapEndianBytes(*(ptr++)); | |
| } | |
| int version = *((*bitstream)++); | |
| if(version != kProfilerDataStreamVersion) | |
| return false; | |
| frame->Deserialize(bitstream, shouldswap); | |
| //Frame::Deserialize: | |
| frameIndex = *((*bitstream)++); | |
| realFrame = *((*bitstream)++); | |
| m_StartTimeUS = *((*bitstream)++); | |
| m_TotalCPUTimeInMicroSec = *((*bitstream)++); | |
| m_TotalGPUTimeInMicroSec = *((*bitstream)++); | |
| allStats.Deserialize(bitstream, swapdata); | |
| ReadArray(bitstream, m_AudioInstanceInfo); | |
| ReadArray(bitstream, m_AudioInstanceNames); | |
| if(swapdata) | |
| SwapBufferU32((UInt32*)&m_AudioInstanceNames[0], m_AudioInstanceNames.size() / 4); | |
| int threadCount = *((*bitstream)++); | |
| for (int t = 0; t < m_ThreadCount; ++t) | |
| { | |
| tdata.m_GroupName = DeserializeString (bitstream, swapdata); | |
| tdata.m_ThreadName = DeserializeString (bitstream, swapdata); | |
| tdata.m_AllSamples.resize_uninitialized(*((*bitstream)++)); | |
| for(size_t i = 0; i < tdata.m_AllSamples.size(); i++) | |
| { | |
| tdata.m_AllSamples[i].timeUS = *((*bitstream)++); | |
| tdata.m_AllSamples[i].startTimeUS = *((*bitstream)++); | |
| tdata.m_AllSamples[i].nbChildren = *((*bitstream)++); | |
| tdata.m_AllSamples[i].information = NULL; | |
| } | |
| tdata.m_GPUTimeSamples.resize_uninitialized(*((*bitstream)++)); | |
| for(size_t i = 0; i < tdata.m_GPUTimeSamples.size(); i++) | |
| { | |
| tdata.m_GPUTimeSamples[i].gpuTimeInMicroSec = *((*bitstream)++); | |
| tdata.m_GPUTimeSamples[i].relatedSampleIndex = *((*bitstream)++); | |
| tdata.m_GPUTimeSamples[i].gpuSection = (GpuSection)(*((*bitstream)++)); | |
| tdata.m_GPUTimeSamples[i].timerQuery = NULL; | |
| } | |
| // m_InstanceIDSamples are not written, since the IDs are not portable | |
| tdata.m_InstanceIDSamples.resize_uninitialized(0); | |
| ReadArray(bitstream, tdata.m_AllocatedGCMemorySamples); | |
| for(size_t i = 0; i < tdata.m_AllSamples.size(); i++) | |
| ReadConditionaly(bitstream, tdata.m_AllSamples[i].information, swapdata); | |
| ReadArray(bitstream, tdata.m_WarningSamples); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment