peekBox2DLength peeks to look at the length of a box2d encoding.
(b []byte)
| 1947 | |
| 1948 | // peekBox2DLength peeks to look at the length of a box2d encoding. |
| 1949 | func peekBox2DLength(b []byte) (int, error) { |
| 1950 | length := 0 |
| 1951 | curr := b |
| 1952 | for i := 0; i < 4; i++ { |
| 1953 | if len(curr) == 0 { |
| 1954 | return 0, errors.Newf("slice too short for box2d") |
| 1955 | } |
| 1956 | switch curr[0] { |
| 1957 | case floatNaN, floatNaNDesc, floatZero: |
| 1958 | length++ |
| 1959 | curr = curr[1:] |
| 1960 | case floatNeg, floatPos: |
| 1961 | length += 9 |
| 1962 | curr = curr[9:] |
| 1963 | default: |
| 1964 | return 0, errors.Newf("unexpected marker for box2d: %x", curr[0]) |
| 1965 | } |
| 1966 | } |
| 1967 | return length, nil |
| 1968 | } |
| 1969 | |
| 1970 | // PeekLength returns the length of the encoded value at the start of b. Note: |
| 1971 | // if this function succeeds, it's not a guarantee that decoding the value will |
no outgoing calls
no test coverage detected
searching dependent graphs…