Compare commits

..

No commits in common. "f49c9770528e73b67fb3a0727c72afea19716889" and "69f3d4973bcbe41092b49a318fc999955e26c325" have entirely different histories.

2 changed files with 13 additions and 1 deletions

View File

@ -221,7 +221,7 @@ func (this *Protocol) unmarshalMessage(out io.Writer, message Message) error {
fmt.Fprintf(out, "\t}\n")
if requiredTotal > 0 {
fmt.Fprintf(out,
"\tif foundRequired != %d { return hopp.ErrTablePairMissing }\n",
"\tif foundRequired != %d { return hopp.ErrPairMissing }\n",
requiredTotal)
}
fmt.Fprintf(out, "\treturn nil\n")

View File

@ -50,3 +50,15 @@ func (this *MessageData) UnmarshalBinary(buffer []byte) error {
}
return nil
}
// Protocol maps methods to functions that create messages. The messages must be
// passed by reference, and the functions must return a new object every time.
type Protocol map[uint16] func() Message
// Add adds messages to the protocol. Messages with conflicting methods will
// be replaced.
func (this Protocol) Add(messages ...func() Message) {
for _, message := range messages {
this[message().Method()] = message
}
}