예제 #1
0
        public void Write(BinaryWriter writer, int depth = 0)
        {
            if (Count >= 0x1F)
            {
                writer.Write((byte)((int)Type | 0x1F));
                writer.Write7BitInt(Count);
            }
            else
            {
                writer.Write((byte)((int)Type | Count));
            }

            if (depth < Micheline.MaxRecursionDepth)
            {
                foreach (var item in this)
                {
                    item.Write(writer, depth + 1);
                }
            }
            else
            {
                foreach (var item in this)
                {
                    MichelineBinaryConverter.WriteFlat(writer, item);
                }
            }
        }
예제 #2
0
        public void Write(BinaryWriter writer, int depth = 0)
        {
            var argsCount   = false;
            var annotsCount = false;

            var tag = (int)Type;

            if (Args?.Count > 0)
            {
                if (Args.Count >= 0x07)
                {
                    tag      |= 0x70;
                    argsCount = true;
                }
                else
                {
                    tag |= Args.Count << 4;
                }
            }

            if (Annots?.Count > 0)
            {
                if (Annots.Count >= 0x0F)
                {
                    tag        |= 0x0F;
                    annotsCount = true;
                }
                else
                {
                    tag |= Annots.Count;
                }
            }

            writer.Write((byte)tag);
            writer.Write((byte)Prim);

            if (Args != null)
            {
                if (argsCount)
                {
                    writer.Write7BitInt(Args.Count);
                }

                if (depth < Micheline.MaxRecursionDepth)
                {
                    foreach (var arg in Args)
                    {
                        arg.Write(writer, depth + 1);
                    }
                }
                else
                {
                    foreach (var arg in Args)
                    {
                        MichelineBinaryConverter.WriteFlat(writer, arg);
                    }
                }
            }

            if (Annots != null)
            {
                if (annotsCount)
                {
                    writer.Write7BitInt(Annots.Count);
                }

                foreach (var annot in Annots)
                {
                    WriteAnnotation(writer, annot);
                }
            }
        }