Write() 공개 메소드

Writes the binary representation to the specified CodedOutputStream.
The binary representation is a 1-byte HashingAlgorithm.Code, 1-byte HashingAlgorithm.DigestSize followed by the Digest.
public Write ( CodedOutputStream stream ) : void
stream Google.Protobuf.CodedOutputStream /// The to write to. ///
리턴 void
예제 #1
0
        /// <summary>
        ///   Converts the CID to its equivalent string representation.
        /// </summary>
        /// <returns>
        ///   The string representation of the <see cref="Cid"/>.
        /// </returns>
        /// <remarks>
        ///   For <see cref="Version"/> 0, this is equalivalent to the
        ///   <see cref="MultiHash.ToBase58()">base58btc encoding</see>
        ///   of the <see cref="Hash"/>.
        /// </remarks>
        /// <seealso cref="Decode"/>
        public string Encode()
        {
            if (Version == 0)
            {
                return(Hash.ToBase58());
            }

            using (var ms = new MemoryStream())
            {
                ms.WriteVarint(Version);
                ms.WriteMultiCodec(ContentType);
                Hash.Write(ms);
                return(MultiBase.Encode(ms.ToArray(), Encoding));
            }
        }
예제 #2
0
 /// <summary>
 ///   Converts the CID to its equivalent string representation.
 /// </summary>
 /// <returns>
 ///   The string representation of the <see cref="Cid"/>.
 /// </returns>
 /// <remarks>
 ///   For <see cref="Version"/> 0, this is equalivalent to the
 ///   <see cref="MultiHash.ToBase58()">base58btc encoding</see>
 ///   of the <see cref="Hash"/>.
 /// </remarks>
 /// <seealso cref="Decode"/>
 public string Encode()
 {
     if (encodedValue != null)
     {
         return(encodedValue);
     }
     if (Version == 0)
     {
         encodedValue = Hash.ToBase58();
     }
     else
     {
         using (var ms = new MemoryStream())
         {
             ms.WriteVarint(Version);
             ms.WriteMultiCodec(ContentType);
             Hash.Write(ms);
             encodedValue = MultiBase.Encode(ms.ToArray(), Encoding);
         }
     }
     return(encodedValue);
 }
예제 #3
0
        /// <summary>
        ///   Writes the binary representation of the link to the specified <see cref="CodedOutputStream"/>.
        /// </summary>
        /// <param name="stream">
        ///   The <see cref="CodedOutputStream"/> to write to.
        /// </param>
        public void Write(CodedOutputStream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            stream.WriteTag(1, WireFormat.WireType.LengthDelimited);
            var mh = new MultiHash(Hash);

            stream.WriteLength(mh.Algorithm.DigestSize + 2); // + 2 bytes for digest size
            mh.Write(stream);

            if (Name != null)
            {
                stream.WriteTag(2, WireFormat.WireType.LengthDelimited);
                stream.WriteString(Name);
            }

            stream.WriteTag(3, WireFormat.WireType.Varint);
            stream.WriteInt64(Size);
        }
예제 #4
0
        public void Write_Null_Stream()
        {
            var mh = new MultiHash("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");

            ExceptionAssert.Throws <ArgumentNullException>(() => mh.Write((CodedOutputStream)null));
        }