mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-06 05:17:49 +00:00
fa0101bd60
This changes the BEP protocol to use protocol buffer serialization instead of XDR, and therefore also the database format. The local discovery protocol is also updated to be protocol buffer format. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3276 LGTM: AudriusButkevicius
45 lines
862 B
Go
Executable File
45 lines
862 B
Go
Executable File
// Copyright (C) 2014 The Protocol Authors.
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrNoError error
|
|
ErrGeneric = errors.New("generic error")
|
|
ErrNoSuchFile = errors.New("no such file")
|
|
ErrInvalid = errors.New("file is invalid")
|
|
)
|
|
|
|
var lookupError = map[ErrorCode]error{
|
|
ErrorCodeNoError: ErrNoError,
|
|
ErrorCodeGeneric: ErrGeneric,
|
|
ErrorCodeNoSuchFile: ErrNoSuchFile,
|
|
ErrorCodeInvalidFile: ErrInvalid,
|
|
}
|
|
|
|
var lookupCode = map[error]ErrorCode{
|
|
ErrNoError: ErrorCodeNoError,
|
|
ErrGeneric: ErrorCodeGeneric,
|
|
ErrNoSuchFile: ErrorCodeNoSuchFile,
|
|
ErrInvalid: ErrorCodeInvalidFile,
|
|
}
|
|
|
|
func codeToError(code ErrorCode) error {
|
|
err, ok := lookupError[code]
|
|
if !ok {
|
|
return ErrGeneric
|
|
}
|
|
return err
|
|
}
|
|
|
|
func errorToCode(err error) ErrorCode {
|
|
code, ok := lookupCode[err]
|
|
if !ok {
|
|
return ErrorCodeGeneric
|
|
}
|
|
return code
|
|
}
|