Updated to current version
This commit is contained in:
parent
2a470ee856
commit
43a19d7c61
1 changed files with 11 additions and 13 deletions
24
README.md
24
README.md
|
@ -5,32 +5,30 @@ multiaddr for IPFS in C.
|
||||||
# Usage:
|
# Usage:
|
||||||
#### All you need to include is multiaddr.h
|
#### All you need to include is multiaddr.h
|
||||||
## Maddr struct:
|
## Maddr struct:
|
||||||
* char string[]; // String that contains addresses such as /ip4/192.168.1.1/
|
* char * string; // String that contains addresses such as /ip4/192.168.1.1/
|
||||||
* uint8_t bytes; //String that contains the enecoded address
|
* uint8_t bytes; //String that contains the enecoded address
|
||||||
* int bsize[]; //int[1] that contains the real bytes size (Use it whenever using the bytes so you don't input trash!)
|
* size_t bsize; //int[1] that contains the real bytes size (Use it whenever using the bytes so you don't input trash!)
|
||||||
|
|
||||||
## New Multi Address From String(new_maddr_fs)
|
## New Multi Address From String(multiaddress_new_from_string)
|
||||||
char addrstr[] = "/ip4/192.168.1.1/"
|
struct MultiAddress* a = multiaddress_new_from_string("/ip4/127.0.0.1/tcp/8080/");
|
||||||
struct maddr a;
|
|
||||||
a=new_maddr_fs(addrstr);
|
|
||||||
## Obtaining the byte buffer(.bytes, .bsize[0]):
|
## Obtaining the byte buffer(.bytes, .bsize[0]):
|
||||||
printf("TEST BYTES: %s\n",Var_To_Hex(a.bsize[0], a.bytes));
|
printf("TEST BYTES: %s\n",Var_To_Hex(a->bsize, a->bytes));
|
||||||
Var_To_Hex = Byte Buffer to Hex String
|
Var_To_Hex = Byte Buffer to Hex String
|
||||||
Hex_To_Var = Hex String to Byte Buffer
|
Hex_To_Var = Hex String to Byte Buffer
|
||||||
## Encapsulation & Decapsulation(m_encapsulate, m_decapsulate)
|
## Encapsulation & Decapsulation(m_encapsulate, m_decapsulate)
|
||||||
#### Remember, Decapsulation happens from right to left, never in reverse, if you have /ip4/udp/ipfs/ if you decapsulate "udp" you will also take out ipfs!
|
#### Remember, Decapsulation happens from right to left, never in reverse, if you have /ip4/udp/ipfs/ if you decapsulate "udp" you will also take out ipfs!
|
||||||
* Now the string is: /ip4/192.168.1.1/
|
* Now the string is: /ip4/192.168.1.1/
|
||||||
* m_encapsulate(&a,"/udp/3333/"); //Adds udp/3333/ to char addrstr
|
* multiaddress_encapsulate(a,"/udp/3333/"); //Adds udp/3333/ to char addrstr
|
||||||
* Now the string is: /ip4/192.168.1.1/udp/3333/
|
* Now the string is: /ip4/192.168.1.1/udp/3333/
|
||||||
* m_decapsulate(&a,"udp"); //Removes udp protocol and its address
|
* multiaddress_decapsulate(a,"udp"); //Removes udp protocol and its address
|
||||||
* Now the string is: /ip4/192.168.1.1/
|
* Now the string is: /ip4/192.168.1.1/
|
||||||
* m_encapsulate(&a,"/tcp/8080");
|
* multiaddress_encapsulate(a,"/tcp/8080");
|
||||||
* Now the string is: /ip4/192.168.1.1/tcp/8080/
|
* Now the string is: /ip4/192.168.1.1/tcp/8080/
|
||||||
|
|
||||||
# Constructing a multiaddress from bytes:
|
# Constructing a multiaddress from bytes:
|
||||||
|
|
||||||
* struct maddr beta;
|
* struct MultiAddress* beta;
|
||||||
* beta=new_maddr_fb(a.bytes,a.bsize[0]); //This will already construct back to the string too!
|
* beta = multiaddress_new_from_bytes(a->bytes,a->bsize); //This will already construct back to the string too!
|
||||||
* printf("B STRING: %s\n",beta.string); //So after encapsulation and decapsulation atm this string would
|
* printf("B STRING: %s\n",beta->string); //So after encapsulation and decapsulation atm this string would
|
||||||
* contain: /ip4/192.168.1.1/tcp/8080/
|
* contain: /ip4/192.168.1.1/tcp/8080/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue