package httpsfv
import (
"encoding/base64"
"errors"
"strings"
)
var ErrInvalidBinaryFormat = errors .New ("invalid binary format" )
func marshalBinary(b *strings .Builder , bs []byte ) error {
if err := b .WriteByte (':' ); err != nil {
return err
}
buf := make ([]byte , base64 .StdEncoding .EncodedLen (len (bs )))
base64 .StdEncoding .Encode (buf , bs )
if _ , err := b .Write (buf ); err != nil {
return err
}
return b .WriteByte (':' )
}
func parseBinary(s *scanner ) ([]byte , error ) {
if s .eof () || s .data [s .off ] != ':' {
return nil , &UnmarshalError {s .off , ErrInvalidBinaryFormat }
}
s .off ++
start := s .off
for !s .eof () {
c := s .data [s .off ]
if c == ':' {
decoded , err := base64 .StdEncoding .DecodeString (s .data [start :s .off ])
if err != nil {
return nil , &UnmarshalError {s .off , err }
}
s .off ++
return decoded , nil
}
if !isAlpha (c ) && !isDigit (c ) && c != '+' && c != '/' && c != '=' {
return nil , &UnmarshalError {s .off , ErrInvalidBinaryFormat }
}
s .off ++
}
return nil , &UnmarshalError {s .off , ErrInvalidBinaryFormat }
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .