Пример #1
0
        private void VerifyEncodeDecode(EsfNode node, bool withoutCodec = true)
        {
            if (withoutCodec)
            {
                // encode only the single node
                ICodecNode codecNode = node as ICodecNode;
                if (codecNode != null)
                {
                    byte[] bytes;
                    using (var stream = new MemoryStream()) {
                        using (var writer = new BinaryWriter(stream)) {
                            codecNode.Encode(writer);
                        }
                        bytes = stream.ToArray();
                    }
                    EsfNode decoded = node.CreateCopy();
                    ((ICodecNode)decoded).Decode(new BinaryReader(new MemoryStream(bytes, 1, bytes.Length - 1)), node.TypeCode);
                    assertEqual(node, decoded);
                }
            }

            // now the test with the full file codec
            List <EsfNode> singleNode = new List <EsfNode>();

            singleNode.Add(node);
            VerifyEncodeDecode(singleNode);
        }
Пример #2
0
 private byte[] Encode(ICodecNode node)
 {
     byte[] result;
     using (var stream = new MemoryStream()) {
         using (var writer = new BinaryWriter(stream)) {
             node.Encode(writer);
         }
         result = stream.ToArray();
     }
     return(result);
 }