Class Cid
Identifies some content, e.g. a Content ID.
Implements
Inherited Members
Namespace: Ipfs
Assembly: Ipfs.Core.dll
Syntax
[JsonConverter(typeof(Cid.CidJsonConverter))]
public class Cid : IEquatable<Cid>
Remarks
A Cid is a self-describing content-addressed identifier for distributed systems.
Initially, IPFS used a MultiHash as the CID and this is still supported as Version 0. Version 1 adds a self describing structure to the multi-hash, see the spec.
note
The Algorithm must be "sha2-256" for a version 0 CID.
Fields
| Improve this Doc View SourceDefaultContentType
The default ContentType.
Declaration
public const string DefaultContentType = "dag-pb"
Field Value
Type | Description |
---|---|
String |
Properties
| Improve this Doc View SourceContentType
The content type or format of the data being addressed.
Declaration
public string ContentType { get; set; }
Property Value
Type | Description |
---|---|
String | dag-pb, dag-cbor, eth-block, etc. Defaults to "dag-pb". |
Remarks
Sets Version to 1, when setting a value that is not equal to "dag-pb".
See Also
| Improve this Doc View SourceEncoding
The MultiBase encoding of the CID.
Declaration
public string Encoding { get; set; }
Property Value
Type | Description |
---|---|
String | base58btc, base32, base64, etc. Defaults to DefaultAlgorithmName. |
Remarks
Sets Version to 1, when setting a value that is not equal to "base58btc".
See Also
| Improve this Doc View SourceHash
The cryptographic hash of the content being addressed.
Declaration
public MultiHash Hash { get; set; }
Property Value
Type | Description |
---|---|
MultiHash | The MultiHash of the content being addressed. |
Remarks
Sets Version to 1, when setting a hashing algorithm that is not equal to "sha2-256".
Version
The version of the CID.
Declaration
public int Version { get; set; }
Property Value
Type | Description |
---|---|
Int32 | 0 or 1. |
Remarks
When the Version is 0 and the following properties are not matched, then the version is upgraded to version 1 when any of the properties is set.
- ContentType equals "dag-pb"
- Encoding equals "base58btc"
- Hash algorithm name equals "sha2-256"
The default Encoding is "base32" when the Version is not zero.
Methods
| Improve this Doc View SourceDecode(String)
Declaration
public static Cid Decode(string input)
Parameters
Type | Name | Description |
---|---|---|
String | input | The Encode() string. |
Returns
Type | Description |
---|---|
Cid | A new Cid that is equivalent to |
Exceptions
Type | Condition |
---|---|
FormatException | When the |
See Also
| Improve this Doc View SourceEncode()
Converts the CID to its equivalent string representation.
Declaration
public string Encode()
Returns
Type | Description |
---|---|
String | The string representation of the Cid. |
Remarks
For Version 0, this is equalivalent to the ToBase58() of the Hash.
See Also
| Improve this Doc View SourceEquals(Cid)
Declaration
public bool Equals(Cid that)
Parameters
Type | Name | Description |
---|---|---|
Cid | that |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
| Improve this Doc View SourceRead(CodedInputStream)
Reads the binary representation of the CID from the specified Google.Protobuf.CodedInputStream.
Declaration
public static Cid Read(CodedInputStream stream)
Parameters
Type | Name | Description |
---|---|---|
Google.Protobuf.CodedInputStream | stream | The Google.Protobuf.CodedInputStream to read from. |
Returns
Type | Description |
---|---|
Cid | A new Cid. |
Read(Byte[])
Reads the binary representation of the CID from the specified byte array.
Declaration
public static Cid Read(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | The souce of a CID. |
Returns
Type | Description |
---|---|
Cid | A new Cid. |
Remarks
The buffer does NOT start with a varint length prefix.
Read(Stream)
Reads the binary representation of the CID from the specified Stream.
Declaration
public static Cid Read(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream to read from. |
Returns
Type | Description |
---|---|
Cid | A new Cid. |
ToArray()
Returns the binary representation of the CID as a byte array.
Declaration
public byte[] ToArray()
Returns
Type | Description |
---|---|
Byte[] | A new buffer containing the CID. |
Remarks
The buffer does NOT start with a varint length prefix.
ToString()
Returns the string representation of the CID in the general format.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | e.g. "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V" |
Overrides
| Improve this Doc View SourceToString(String)
Returns a string representation of the CID according to the provided format specifier.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format | A single format specifier that indicates how to format the value of the CID. Can be "G" or "L". |
Returns
Type | Description |
---|---|
String | The CID in the specified |
Remarks
The "G" format specifier is the same as calling Encode().
Specifier | return value |
---|---|
G | QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V |
L | base58btc cidv0 dag-pb sha2-256 Qm... |
Exceptions
Type | Condition |
---|---|
FormatException |
|
Write(CodedOutputStream)
Writes the binary representation of the CID to the specified Google.Protobuf.CodedOutputStream.
Declaration
public void Write(CodedOutputStream stream)
Parameters
Type | Name | Description |
---|---|---|
Google.Protobuf.CodedOutputStream | stream | The Google.Protobuf.CodedOutputStream to write to. |
Write(Stream)
Writes the binary representation of the CID to the specified Stream.
Declaration
public void Write(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream to write to. |
Operators
| Improve this Doc View SourceEquality(Cid, Cid)
Value equality.
Declaration
public static bool operator ==(Cid a, Cid b)
Parameters
Type | Name | Description |
---|---|---|
Cid | a | |
Cid | b |
Returns
Type | Description |
---|---|
Boolean |
Implicit(Cid to String)
Declaration
public static implicit operator string (Cid id)
Parameters
Type | Name | Description |
---|---|---|
Cid | id | A Cid. |
Returns
Type | Description |
---|---|
String | A new String. |
Remarks
Equivalent to
Cid.Encode()
Implicit(MultiHash to Cid)
Declaration
public static implicit operator Cid(MultiHash hash)
Parameters
Type | Name | Description |
---|---|---|
MultiHash | hash | A MultiHash. |
Returns
Type | Description |
---|---|
Cid | A new Cid based on the |
Implicit(String to Cid)
Declaration
public static implicit operator Cid(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s | A string encoded Cid. |
Returns
Type | Description |
---|---|
Cid | A new Cid. |
Remarks
Equivalent to
Cid.Decode(s)
Inequality(Cid, Cid)
Value inequality.
Declaration
public static bool operator !=(Cid a, Cid b)
Parameters
Type | Name | Description |
---|---|---|
Cid | a | |
Cid | b |
Returns
Type | Description |
---|---|
Boolean |