cleanly separate version handling
This commit is contained in:
parent
bdb8c87a30
commit
5b8941ed37
|
@ -46,10 +46,18 @@ func splitHeader(header []byte, names []string) (map[string]string, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//ReadMessage -
|
// ReadMessage checks the protocol and switches accordingly
|
||||||
func ReadMessage(b []byte) (*Packer, error) {
|
func ReadMessage(b []byte) (*Packer, error) {
|
||||||
// Detect protocol in use
|
// Detect protocol in use
|
||||||
if b[0] == packerV1 {
|
if b[0] == packerV1 {
|
||||||
|
return ReadV1Message(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("Version %d not supported", 255-b[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadV1Message parses a v1-formatted message
|
||||||
|
func ReadV1Message(b []byte) (*Packer, error) {
|
||||||
// Separate the header and body using the header length in the second byte.
|
// Separate the header and body using the header length in the second byte.
|
||||||
p := NewPacker(nil)
|
p := NewPacker(nil)
|
||||||
header := b[2 : b[1]+2]
|
header := b[2 : b[1]+2]
|
||||||
|
@ -100,9 +108,6 @@ func ReadMessage(b []byte) (*Packer, error) {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("Version %d not supported", 255-b[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
//PackV1 -- Outputs version 1 of packer
|
//PackV1 -- Outputs version 1 of packer
|
||||||
func (p *Packer) PackV1() bytes.Buffer {
|
func (p *Packer) PackV1() bytes.Buffer {
|
||||||
header := strings.Join([]string{
|
header := strings.Join([]string{
|
||||||
|
|
Loading…
Reference in New Issue