Comments (4)
The documentation is actually correct as written. OP has paid attention to the
wrong part.
"The returned slice may be a sub-slice of dst if dst was large enough to hold
the entire encoded block."
In this case the encoded block has length 0. And dst (a nil slice) is large
enough to hold zero elements. So a sub-slice of dst, dst[:0], is returned.
A subslice of a nil slice is nil itself. http://play.golang.org/p/HR9EsRYhJo
The statement in question by OP is the lower precedence "Otherwise" clause
which applies only if the first one quoted here does not apply.
Original comment by [email protected]
on 5 Nov 2014 at 11:08
from snappy-go.
OP here. I suppose you're right, the nil slice is a subslice of the nil slice
which is big enough to contain 0 bytes. So the docs are correct.
Original comment by [email protected]
on 5 Nov 2014 at 11:17
from snappy-go.
Oops. I copied the docs from Encode().
Decode() has similar docs, you just have to replace "encoded block" in my
previous response with "decoded block".
Sorry for any confusion that caused.
Original comment by [email protected]
on 5 Nov 2014 at 11:19
from snappy-go.
FWIW, because of things like this you almost never want to check if a slice is
nil in Go. Instead it is generally better to check that its length is 0.
Original comment by [email protected]
on 5 Nov 2014 at 11:25
from snappy-go.
Related Issues (9)
- test uses data file that's not in the repo HOT 1
- support API for official snappy framing HOT 4
- Project front page installation instructions are outdated
- Why no io.Reader and io.Writer interface for snappy? HOT 1
- Encode appears to allocate ~10K more than it needs on a 64K block
- Decode panics when passed malformed input
- Why does Encode return an error?
- Outdated contributing instructions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snappy-go.