example_test.go raw

   1  package base58_test
   2  
   3  import (
   4  	"fmt"
   5  	
   6  	"github.com/p9c/p9/pkg/base58"
   7  )
   8  
   9  // This example demonstrates how to decode modified base58 encoded data.
  10  func ExampleDecode() {
  11  	// Decode example modified base58 encoded data.
  12  	encoded := "25JnwSn7XKfNQ"
  13  	decoded := base58.Decode(encoded)
  14  	// Show the decoded data.
  15  	fmt.Println("Decoded Data:", string(decoded))
  16  	// Output:
  17  	// Decoded Data: Test data
  18  }
  19  
  20  // This example demonstrates how to encode data using the modified base58 encoding scheme.
  21  func ExampleEncode() {
  22  	// Encode example data with the modified base58 encoding scheme.
  23  	data := []byte("Test data")
  24  	encoded := base58.Encode(data)
  25  	// Show the encoded data.
  26  	fmt.Println("Encoded Data:", encoded)
  27  	// Output:
  28  	// Encoded Data: 25JnwSn7XKfNQ
  29  }
  30  
  31  // This example demonstrates how to decode Base58Check encoded data.
  32  func ExampleCheckDecode() {
  33  	// Decode an example Base58Check encoded data.
  34  	encoded := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
  35  	decoded, version, e := base58.CheckDecode(encoded)
  36  	if e != nil {
  37  		fmt.Println(e)
  38  		return
  39  	}
  40  	// Show the decoded data.
  41  	fmt.Printf("Decoded data: %x\n", decoded)
  42  	fmt.Println("Version Byte:", version)
  43  	// Output:
  44  	// Decoded data: 62e907b15cbf27d5425399ebf6f0fb50ebb88f18
  45  	// Version Byte: 0
  46  }
  47  
  48  // This example demonstrates how to encode data using the Base58Check encoding scheme.
  49  func ExampleCheckEncode() {
  50  	// Encode example data with the Base58Check encoding scheme.
  51  	data := []byte("Test data")
  52  	encoded := base58.CheckEncode(data, 0)
  53  	// Show the encoded data.
  54  	fmt.Println("Encoded Data:", encoded)
  55  	// Output:
  56  	// Encoded Data: 182iP79GRURMp7oMHDU
  57  }
  58