MCPcopy Create free account
hub / github.com/dunglas/httpsfv / parseBinary

Function parseBinary

binary.go:31–59  ·  view source on GitHub ↗

parseBinary parses as defined in https://httpwg.org/specs/rfc9651.html#parse-binary.

(s *scanner)

Source from the content-addressed store, hash-verified

29// parseBinary parses as defined in
30// https://httpwg.org/specs/rfc9651.html#parse-binary.
31func parseBinary(s *scanner) ([]byte, error) {
32 if s.eof() || s.data[s.off] != ':' {
33 return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat}
34 }
35 s.off++
36
37 start := s.off
38
39 for !s.eof() {
40 c := s.data[s.off]
41 if c == ':' {
42 // base64decode
43 decoded, err := base64.StdEncoding.DecodeString(s.data[start:s.off])
44 if err != nil {
45 return nil, &UnmarshalError{s.off, err}
46 }
47 s.off++
48
49 return decoded, nil
50 }
51
52 if !isAlpha(c) && !isDigit(c) && c != '+' && c != '/' && c != '=' {
53 return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat}
54 }
55 s.off++
56 }
57
58 return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat}
59}

Callers 2

TestParseBinaryFunction · 0.85
parseBareItemFunction · 0.85

Calls 3

isAlphaFunction · 0.85
isDigitFunction · 0.85
eofMethod · 0.80

Tested by 1

TestParseBinaryFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…