packagerlpimport("fmt""io")typeMyCoolTypestruct{Namestringa,buint}// EncodeRLP writes x as RLP list [a, b] that omits the Name field.func(x*MyCoolType)EncodeRLP(wio.Writer)(errerror){// Note: the receiver can be a nil pointer. This allows you to// control the encoding of nil, but it also means that you have to// check for a nil receiver.ifx==nil{err=Encode(w,[]uint{0,0})}else{err=Encode(w,[]uint{x.a,x.b})}returnerr}funcExampleEncoder(){vart*MyCoolType// t is nil pointer to MyCoolTypebytes,_:=EncodeToBytes(t)fmt.Printf("%v → %X\n",t,bytes)t=&MyCoolType{Name:"foobar",a:5,b:6}bytes,_=EncodeToBytes(t)fmt.Printf("%v → %X\n",t,bytes)// Output:// <nil> → C28080// &{foobar 5 6} → C20506}