diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 15:38:05 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 15:38:05 -0500 |
commit | 902bb1cc2a0a8644e160f303be1a2e0ad354bfd5 (patch) | |
tree | e6ddce8d0bc8664a99ffc346ef38c65d39a76dae /read.go |
initial commit
Diffstat (limited to 'read.go')
-rw-r--r-- | read.go | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -0,0 +1,65 @@ +package libfastimport + +type UnsupportedCommand string + +func (e UnsupportedCommand) Error() string { + return "Unsupported command: "+string(e) +} + +type Parser struct { + fir *FIReader + + cmd chan Cmd +} + +func (p *Parser) GetCmd() (Cmd, error) { + for p.cmd == nil { + slice, err := p.fir.ReadSlice() + if err != nil { + return nil, err + } + err = p.putSlice(slice) + if err != nil { + return nil, err + } + } + return p.cmd, nil +} + +func (p *Parser) putSlice(slice []byte) error { +} + +func utSlice(fir *FIReader) (Cmd, error) { + slice, err := fir.PeekSlice() + if err != nil { + return nil, err + } + if len(slice) < 1 { + return nil, UnsupportedCommand(slice) + } + switch slice[0] { + case '#': // comment + case 'b': // blob + case 'c': + if len(slice) < 2 { + return nil, UnsupportedCommand(slice) + } + switch slice[1] { + case 'o': // commit + case 'h': // checkpoint + case 'a': // cat-blob + default: + return nil, UnsupportedCommand(slice) + } + case 'd': // done + case 'f': // feature + case 'g': // get-mark + case 'l': // ls + case 'o': // option + case 'p': // progress + case 'r': // reset + case 't': // tag + default: + return nil, UnsupportedCommand(slice) + } +} |