aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lunixbochs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/lunixbochs')
-rw-r--r--vendor/github.com/lunixbochs/struc/field.go1
-rw-r--r--vendor/github.com/lunixbochs/struc/fields.go17
-rw-r--r--vendor/github.com/lunixbochs/struc/parse.go22
-rw-r--r--vendor/github.com/lunixbochs/struc/struc_test.go3
4 files changed, 25 insertions, 18 deletions
diff --git a/vendor/github.com/lunixbochs/struc/field.go b/vendor/github.com/lunixbochs/struc/field.go
index 4af10a7..5ab7da6 100644
--- a/vendor/github.com/lunixbochs/struc/field.go
+++ b/vendor/github.com/lunixbochs/struc/field.go
@@ -10,7 +10,6 @@ import (
type Field struct {
Name string
- CanSet bool
Ptr bool
Index int
Type Type
diff --git a/vendor/github.com/lunixbochs/struc/fields.go b/vendor/github.com/lunixbochs/struc/fields.go
index 80e2045..5d591bf 100644
--- a/vendor/github.com/lunixbochs/struc/fields.go
+++ b/vendor/github.com/lunixbochs/struc/fields.go
@@ -12,14 +12,18 @@ type Fields []*Field
func (f Fields) SetByteOrder(order binary.ByteOrder) {
for _, field := range f {
- field.Order = order
+ if field != nil {
+ field.Order = order
+ }
}
}
func (f Fields) String() string {
fields := make([]string, len(f))
for i, field := range f {
- fields[i] = field.String()
+ if field != nil {
+ fields[i] = field.String()
+ }
}
return "{" + strings.Join(fields, ", ") + "}"
}
@@ -30,9 +34,8 @@ func (f Fields) Sizeof(val reflect.Value, options *Options) int {
}
size := 0
for i, field := range f {
- v := val.Field(i)
- if v.CanSet() {
- size += field.Size(v, options)
+ if field != nil {
+ size += field.Size(val.Field(i), options)
}
}
return size
@@ -63,7 +66,7 @@ func (f Fields) Pack(buf []byte, val reflect.Value, options *Options) (int, erro
}
pos := 0
for i, field := range f {
- if !field.CanSet {
+ if field == nil {
continue
}
v := val.Field(i)
@@ -106,7 +109,7 @@ func (f Fields) Unpack(r io.Reader, val reflect.Value, options *Options) error {
var tmp [8]byte
var buf []byte
for i, field := range f {
- if !field.CanSet {
+ if field == nil {
continue
}
v := val.Field(i)
diff --git a/vendor/github.com/lunixbochs/struc/parse.go b/vendor/github.com/lunixbochs/struc/parse.go
index 5a30d53..060f43d 100644
--- a/vendor/github.com/lunixbochs/struc/parse.go
+++ b/vendor/github.com/lunixbochs/struc/parse.go
@@ -13,12 +13,11 @@ import (
// struc:"int32,big,sizeof=Data"
-var tagWordsRe = regexp.MustCompile(`(\[|\b)[^"]+\b+$`)
-
type strucTag struct {
Type string
Order binary.ByteOrder
Sizeof string
+ Skip bool
}
func parseStrucTag(tag reflect.StructTag) *strucTag {
@@ -40,6 +39,8 @@ func parseStrucTag(tag reflect.StructTag) *strucTag {
t.Order = binary.BigEndian
} else if s == "little" {
t.Order = binary.LittleEndian
+ } else if s == "skip" {
+ t.Skip = true
} else {
t.Type = s
}
@@ -49,8 +50,8 @@ func parseStrucTag(tag reflect.StructTag) *strucTag {
var typeLenRe = regexp.MustCompile(`^\[(\d*)\]`)
-func parseField(f reflect.StructField) (fd *Field, err error) {
- tag := parseStrucTag(f.Tag)
+func parseField(f reflect.StructField) (fd *Field, tag *strucTag, err error) {
+ tag = parseStrucTag(f.Tag)
var ok bool
fd = &Field{
Name: f.Name,
@@ -124,19 +125,20 @@ func parseFieldsLocked(v reflect.Value) (Fields, error) {
return nil, errors.New("struc: Struct has no fields.")
}
sizeofMap := make(map[string][]int)
- fields := make(Fields, 0, v.NumField())
+ fields := make(Fields, v.NumField())
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
- f, err := parseField(field)
+ f, tag, err := parseField(field)
+ if tag.Skip {
+ continue
+ }
if err != nil {
return nil, err
}
- f.CanSet = v.Field(i).CanSet()
- if !f.CanSet {
+ if !v.Field(i).CanSet() {
continue
}
f.Index = i
- tag := parseStrucTag(field.Tag)
if tag.Sizeof != "" {
target, ok := t.FieldByName(tag.Sizeof)
if !ok {
@@ -166,7 +168,7 @@ func parseFieldsLocked(v reflect.Value) (Fields, error) {
return nil, err
}
}
- fields = append(fields, f)
+ fields[i] = f
}
return fields, nil
}
diff --git a/vendor/github.com/lunixbochs/struc/struc_test.go b/vendor/github.com/lunixbochs/struc/struc_test.go
index 939c3e3..4b50707 100644
--- a/vendor/github.com/lunixbochs/struc/struc_test.go
+++ b/vendor/github.com/lunixbochs/struc/struc_test.go
@@ -55,6 +55,8 @@ type Example struct {
NestedSize int `struc:"sizeof=NestedA"` // 00 00 00 02
NestedA []Nested // [00 00 00 03, 00 00 00 04]
+ Skip int `struc:"skip"`
+
CustomTypeSize Int3 `struc:"sizeof=CustomTypeSizeArr"` // 00 00 00 04
CustomTypeSizeArr []byte // "ABCD"
}
@@ -71,6 +73,7 @@ var reference = &Example{
4, []byte("5678"),
Nested{1}, &Nested{2}, &five,
6, []Nested{{3}, {4}, {5}, {6}, {7}, {8}},
+ 0,
Int3(4), []byte("ABCD"),
}