Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add EOF() method to proto.Buffer #296

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group
required, reqFields := prop.reqCount, uint64(0)

var err error
for err == nil && o.index < len(o.buf) {
for err == nil && !o.EOF() {
oi := o.index
var u uint64
u, err = o.DecodeVarint()
Expand Down
17 changes: 17 additions & 0 deletions proto/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,23 @@ func (p *Buffer) SetBuf(s []byte) {
// Bytes returns the contents of the Buffer.
func (p *Buffer) Bytes() []byte { return p.buf }

// EOF returns true when there is no more data to read and decode.
func (p *Buffer) EOF() bool {
return p.index >= len(p.buf)
}

// ReaderIndex returns the current offset in Buffer for reading. Calls to the
// various Decode* methods will read and decode data starting at this index in
// the Buffer's underlying byte slice.
func (p *Buffer) ReaderIndex() int { return p.index }

// SetReaderIndex changes the current offset in Buffer for reading to the
// given value. Subsequent calls to Decode* methods will read and decode data
// starting at this index in the Buffer's underlying byte slice.
func (p *Buffer) SetReaderIndex(index int) {
p.index = index
}

/*
* Helper routines for simplifying the creation of optional fields of basic type.
*/
Expand Down