Ah, I see. This has been coming up several times now. @CalvinGu has been looking for an easier way for awhile now, and @mwestphal has also been trying to solve the more general version (I think) of what you’re trying to do (more general because if you are flattening the stage before serializing it, the “references to external layers” problem doesn’t arise).
You can get the latest guidance we have in that latter forum thread. You are asking only about getting the usdc encoding of a layer into a buffer without passing through any filesystem. But can I ask what your expectation is on the other side of your network transmission? Is it the same as @mwestphal in that you then want to reconstitute a layer and put it on a stage? If so, what would your expectation be if that layer has references to other layers that may not exist on the other side, or textures, etc? I ask because the “export to buffer” seems easier and less fraught for us to support in a core way, but like I described in the other thread, we think there’s potential for breakage and confusion if we facilitate just creating an SdfLayer (even anonymous) from just a buffer.