public void Write(Stream stream) { var bldr = new BFastBuilder(); // Add buffer bldr.Add(BufferNames.Header, Header.ToString().ToBytesUtf8().ToBuffer()); // add String table var stringLookup = ComputeStringLookup(); bldr.Add(BufferNames.Strings, ComputeStrings(stringLookup).PackStrings().ToBuffer()); // Add Assets bldr.Add(BufferNames.Assets, Assets.Select(kv => kv.Value.ToNamedBuffer(kv.Key))); // Add entity tables var entityTables = ComputeEntityTables(stringLookup); bldr.Add(BufferNames.Entities, entityTables.ToBFastBuilder()); // Write the geometry bldr.Add(BufferNames.Geometry, new BigG3dWriter(Geometries, null, UseColors)); // Add the nodes bldr.Add(BufferNames.Nodes, Nodes.ToArray().ToBuffer()); // Now we can write everything out bldr.Write(stream); }
public static BFastBuilder ToBFastBuilder(this List <SerializableEntityTable> entityTables) { var bldr = new BFastBuilder(); foreach (var et in entityTables) { bldr.Add(VimConstants.TableName + et.Name, et.ToBuffers()); } return(bldr); }
public static void Serialize(this SerializableDocument doc, Stream stream) { var bldr = new BFastBuilder(); var headerBuffer = doc.Header.ToString().ToBytesUtf8(); bldr.Add(BufferNames.Header, headerBuffer.ToBuffer()); bldr.Add(BufferNames.Assets, doc.Assets); bldr.Add(BufferNames.Entities, doc.EntityTables.ToBFastBuilder()); bldr.Add(BufferNames.Strings, doc.StringTable.PackStrings().ToBuffer()); bldr.Add(BufferNames.Geometry, doc.Geometry.ToG3DWriter()); bldr.Add(BufferNames.Nodes, doc.Nodes.ToBuffer()); bldr.Write(stream); }
public static void ValidateBFast(byte[] buffer, BFastBuilder srcBuilder) { var bfast = BFast.ReadBFast(buffer).ToArray(); var names = srcBuilder.BufferNames().ToArray(); var sizes = srcBuilder.BufferSizes().ToArray(); var numBuffers = names.Count(); // We should have the same number of buffers AssertEquals(bfast.Length, numBuffers); for (var i = 0; i < numBuffers; i++) { // Of equal size AssertEquals(bfast[i].Name, names[i]); AssertEquals(bfast[i].Data.Length, sizes[i]); // And they might be sub-buffers if (srcBuilder.Children[i].Item2 is BFastBuilder childBuilder) { ValidateBFast(bfast[i].ToBytes(), childBuilder); } } }