Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendBytes ¶ added in v0.0.13
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 Encoder ¶ added in v0.0.8
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶ added in v0.0.9
type IsZeroValue ¶ added in v0.0.4
type IsZeroValue interface { // IsZeroBencodeValue enable support for omitempty feature. // if it's being used as struct field, and it returns true, this field will be skipped. IsZeroBencodeValue() bool }
IsZeroValue add support type implements Marshaler and omitempty
var s struct { Field T `bencode:"field,omitempty"` }
if `T` implements Marshaler, it can implement IsZeroValue so bencode know if it's
type RawBytes ¶ added in v0.0.3
type RawBytes []byte
func (RawBytes) IsZeroBencodeValue ¶ added in v0.0.4
func (RawBytes) MarshalBencode ¶ added in v0.0.3
func (*RawBytes) UnmarshalBencode ¶ added in v0.0.3
type Unmarshaler ¶
Click to show internal directories.
Click to hide internal directories.