Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Example ¶
type User struct { ID uint32 `bencode:"id,string"` Name string `bencode:"name"` } type Inner struct { V int `bencode:"v"` S string `bencode:"a long string name replace field name"` } type With struct { Users []User `bencode:"users,omitempty"` Obj Inner `bencode:"obj"` Ignored bool `bencode:"-"` } var data = With{ Users: []User{ {ID: 1, Name: "sai"}, {ID: 2, Name: "trim21"}, }, Obj: Inner{V: 2, S: "vvv"}, } var b, err = bencode.Marshal(data) if err != nil { panic(err) } fmt.Println(string(b))
Output: d3:objd37:a long string name replace field name3:vvv1:vi2ee5:usersld2:idi1e4:name3:saied2:idi2e4:name6:trim21eee
Types ¶
type Marshaler ¶
Marshaler allow users to implement its own encoder. **it's return value will not be validated**, please make sure you return valid encoded bytes.
type RawMessage ¶
type RawMessage []byte
func (RawMessage) MarshalBencode ¶
func (b RawMessage) MarshalBencode() ([]byte, error)
func (*RawMessage) UnmarshalBencode ¶
func (b *RawMessage) UnmarshalBencode(bytes []byte) error
type Unmarshaler ¶
Click to show internal directories.
Click to hide internal directories.