Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Restrict source.Filter values to *describedType
Browse files Browse the repository at this point in the history
  • Loading branch information
vcabbage committed Feb 12, 2018
1 parent fa8dbbf commit 71bfa64
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,9 @@ func LinkSelectorFilter(filter string) LinkOption {
l.source = new(source)
}
if l.source.Filter == nil {
l.source.Filter = make(map[symbol]interface{})
l.source.Filter = make(map[symbol]*describedType)
}
l.source.Filter[name] = describedType{
l.source.Filter[name] = &describedType{
descriptor: code,
value: filter,
}
Expand Down
12 changes: 12 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ func writeMap(wr *buffer, m interface{}) error {
return err
}
}
case filter:
pairs = len(m) * 2
for key, val := range m {
err := key.marshal(wr)
if err != nil {
return err
}
err = val.marshal(wr)
if err != nil {
return err
}
}
default:
return errorErrorf("unsupported map type %T", m)
}
Expand Down
14 changes: 10 additions & 4 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,11 @@ var (
"lifetime-policy": deleteOnClose,
},
DistributionMode: "some-mode",
Filter: map[symbol]interface{}{
"foo:filter": "bar value",
Filter: filter{
"foo:filter": &describedType{
descriptor: "foo:filter",
value: "bar value",
},
},
Outcomes: []symbol{"amqp:accepted:list"},
Capabilities: []symbol{"barCap"},
Expand Down Expand Up @@ -323,8 +326,11 @@ var (
"lifetime-policy": deleteOnClose,
},
DistributionMode: "some-mode",
Filter: map[symbol]interface{}{
"foo:filter": "bar value",
Filter: filter{
"foo:filter": &describedType{
descriptor: "foo:filter",
value: "bar value",
},
},
Outcomes: []symbol{"amqp:accepted:list"},
Capabilities: []symbol{"barCap"},
Expand Down
31 changes: 30 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,35 @@ func (u *unsettled) unmarshal(r *buffer) error {
return nil
}

type filter map[symbol]*describedType

func (f filter) marshal(wr *buffer) error {
return writeMap(wr, f)
}

func (f *filter) unmarshal(r *buffer) error {
_, count, err := readMapHeader(r)
if err != nil {
return err
}

m := make(filter, count/2)
for i := uint32(0); i < count; i += 2 {
key, err := readString(r)
if err != nil {
return err
}
var value describedType
err = unmarshal(r, &value)
if err != nil {
return err
}
m[symbol(key)] = &value
}
*f = m
return nil
}

/*
<type name="source" class="composite" source="list" provides="source">
<descriptor name="amqp:source:list" code="0x00000000:0x00000028"/>
Expand Down Expand Up @@ -696,7 +725,7 @@ type source struct {
// actually in place (including any filters defaulted at the node). The receiving
// endpoint MUST check that the filter in place meets its needs and take responsibility
// for detaching if it does not.
Filter map[symbol]interface{} // TODO: implement custom type with validation
Filter filter

// default outcome for unsettled transfers
//
Expand Down

0 comments on commit 71bfa64

Please sign in to comment.