import ( "bytes" "github.com/calmh/syncthing-xdr" ) func main() { // Create a bytes buffer with a sample XDR-encoded integer data data := []byte{0x00, 0x00, 0x00, 0x01} buf := bytes.NewBuffer(data) // Create an XDR reader from the buffer reader := xdr.NewReader(buf) // Read a 32-bit unsigned integer value from the reader value, err := reader.ReadUint32() if err != nil { // Handle error } // Output the value fmt.Println(value) // Output: 1 }
import ( "bytes" "github.com/calmh/syncthing-xdr" ) func main() { // Create a bytes buffer to store the XDR-encoded data buf := bytes.NewBuffer(nil) // Create an XDR writer from the buffer writer := xdr.NewWriter(buf) // Write a 32-bit unsigned integer value to the writer err := writer.WriteUint32(1234567890) if err != nil { // Handle error } // Get the XDR-encoded data from the buffer data := buf.Bytes() // Output the data fmt.Printf("%x\n", data) // Output: 49c28b36 }In this example, we create an XDR writer from a bytes buffer. The `WriteUint32()` function is used to write a 32-bit unsigned integer value to the writer. The XDR-encoded data is then stored in the buffer and outputted to the console.