Hide Builder, StringValue, and StringValueArray types.

No need to export these types.
This commit is contained in:
Jack Palevich 2012-09-15 19:46:44 -07:00
parent 9b44363a13
commit 5c36da2622
3 changed files with 21 additions and 21 deletions

View File

@ -60,7 +60,7 @@ func (j *decoder) Array() { j.value = make([]interface{}, 0, 8) }
func (j *decoder) Map() { j.value = make(map[string]interface{}) }
func (j *decoder) Elem(i int) Builder {
func (j *decoder) Elem(i int) builder {
v, ok := j.value.([]interface{})
if !ok {
v = make([]interface{}, 0, 8)
@ -80,7 +80,7 @@ func (j *decoder) Elem(i int) Builder {
return newDecoder(v, i)
}
func (j *decoder) Key(s string) Builder {
func (j *decoder) Key(s string) builder {
m, ok := j.value.(map[string]interface{})
if !ok {
m = make(map[string]interface{})

View File

@ -18,8 +18,8 @@ import (
// Parser
//
// Implements parsing but not the actions. Those are
// carried out by the implementation of the Builder interface.
// A Builder represents the object being created.
// carried out by the implementation of the builder interface.
// A builder represents the object being created.
// Calling a method like Int64(i) sets that object to i.
// Calling a method like Elem(i) or Key(s) creates a
// new builder for a subpiece of the object (logically,
@ -32,10 +32,10 @@ import (
// nested data structure, using the "map keys"
// as struct field names.
// A Builder is an interface implemented by clients and passed
// A builder is an interface implemented by clients and passed
// to the bencode parser. It gives clients full control over the
// eventual representation returned by the parser.
type Builder interface {
type builder interface {
// Set value
Int64(i int64)
Uint64(i uint64)
@ -44,10 +44,10 @@ type Builder interface {
Map()
// Create sub-Builders
Elem(i int) Builder
Key(s string) Builder
Elem(i int) builder
Key(s string) builder
// Flush changes to parent Builder if necessary.
// Flush changes to parent builder if necessary.
Flush()
}
@ -97,7 +97,7 @@ func decodeString(r *bufio.Reader) (data string, err error) {
return
}
func parseFromReader(r *bufio.Reader, build Builder) (err error) {
func parseFromReader(r *bufio.Reader, build builder) (err error) {
c, err := r.ReadByte()
if err != nil {
goto exit
@ -195,6 +195,6 @@ exit:
// Parse parses the bencode stream and makes calls to
// the builder to construct a parsed representation.
func parse(r io.Reader, builder Builder) (err error) {
func parse(r io.Reader, builder builder) (err error) {
return parseFromReader(bufio.NewReader(r), builder)
}

View File

@ -145,7 +145,7 @@ func (b *structBuilder) Array() {
}
}
func (b *structBuilder) Elem(i int) Builder {
func (b *structBuilder) Elem(i int) builder {
if b == nil || i < 0 {
return nobuilder
}
@ -194,7 +194,7 @@ func (b *structBuilder) Map() {
}
}
func (b *structBuilder) Key(k string) Builder {
func (b *structBuilder) Key(k string) builder {
if b == nil {
return nobuilder
}
@ -332,22 +332,22 @@ func writeArrayOrSlice(w io.Writer, val reflect.Value) (err error) {
return nil
}
type StringValue struct {
type stringValue struct {
key string
value reflect.Value
}
type StringValueArray []StringValue
type stringValueArray []stringValue
// Satisfy sort.Interface
func (a StringValueArray) Len() int { return len(a) }
func (a stringValueArray) Len() int { return len(a) }
func (a StringValueArray) Less(i, j int) bool { return a[i].key < a[j].key }
func (a stringValueArray) Less(i, j int) bool { return a[i].key < a[j].key }
func (a StringValueArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a stringValueArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func writeSVList(w io.Writer, svList StringValueArray) (err error) {
func writeSVList(w io.Writer, svList stringValueArray) (err error) {
sort.Sort(svList)
for _, sv := range svList {
@ -381,7 +381,7 @@ func writeMap(w io.Writer, val reflect.Value) (err error) {
// Sort keys
svList := make(StringValueArray, len(keys))
svList := make(stringValueArray, len(keys))
for i, key := range keys {
svList[i].key = key.String()
svList[i].value = val.MapIndex(key)
@ -408,7 +408,7 @@ func writeStruct(w io.Writer, val reflect.Value) (err error) {
typ := val.Type()
numFields := val.NumField()
svList := make(StringValueArray, numFields)
svList := make(stringValueArray, numFields)
for i := 0; i < numFields; i++ {
field := typ.Field(i)