forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/observe dot timestamp (#138)
* feat: load .osrm.timestamp file * refactor: load .osrm[.xxx] interfaces and process * docs: sample for .osrm.timestamp load
- Loading branch information
1 parent
e6350eb
commit 037a545
Showing
7 changed files
with
268 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package osrmfiles | ||
|
||
import "io" | ||
|
||
// ContentsOperator is the interfaces that wraps Contents' methods. | ||
type ContentsOperator interface { | ||
|
||
// PrintSummary prints summary and head lines of contents. | ||
PrintSummary(head int) | ||
|
||
// Validate checks whether the contents valid or not. | ||
Validate() error | ||
|
||
// FindWriter find io.Writer for the specified name, contents can be filled in by the found io.Writer. | ||
FindWriter(name string) (io.Writer, bool) | ||
|
||
// FilePath returns the file path that stores the contents. | ||
FilePath() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package dotosrmdottimestamp | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/Telenav/osrm-backend/integration/osrmfiles/fingerprint" | ||
"github.com/Telenav/osrm-backend/integration/osrmfiles/meta" | ||
"github.com/golang/glog" | ||
) | ||
|
||
// Contents represents `.osrm.timestamp` file structure. | ||
type Contents struct { | ||
Fingerprint fingerprint.Fingerprint | ||
TimestampMeta meta.Num | ||
Timestamp bytes.Buffer | ||
|
||
// for internal implementation | ||
writers map[string]io.Writer | ||
filePath string | ||
} | ||
|
||
// New creates an empty Contents for `.osrm.timestamp`. | ||
func New(file string) *Contents { | ||
c := Contents{} | ||
|
||
c.filePath = file | ||
|
||
// init writers | ||
c.writers = map[string]io.Writer{} | ||
c.writers["osrm_fingerprint.meta"] = &c.Fingerprint | ||
c.writers["/common/timestamp.meta"] = &c.TimestampMeta | ||
c.writers["/common/timestamp"] = &c.Timestamp | ||
|
||
return &c | ||
} | ||
|
||
// Validate checks whether the contents valid or not. | ||
func (c *Contents) Validate() error { | ||
if !c.Fingerprint.IsValid() { | ||
return fmt.Errorf("invalid fingerprint %v", c.Fingerprint) | ||
} | ||
if uint64(c.TimestampMeta) != uint64(c.Timestamp.Len()) { | ||
return fmt.Errorf("timestamp meta not match, count in meta %d, but actual timestamp bytse count %d", c.TimestampMeta, c.Timestamp.Len()) | ||
} | ||
return nil | ||
} | ||
|
||
// PrintSummary prints summary and head lines of contents. | ||
func (c *Contents) PrintSummary(head int) { | ||
glog.Infof("Loaded from %s\n", c.filePath) | ||
glog.Infof(" %s\n", &c.Fingerprint) | ||
|
||
glog.Infof(" timestamp(a.k.a. data_version) meta %d count %d\n", c.TimestampMeta, c.Timestamp.Len()) | ||
if head > 0 { | ||
glog.Infof(" timestamp(a.k.a. data_version) %v\n", c.Timestamp.String()) | ||
} | ||
} | ||
|
||
// FindWriter find io.Writer for the specified name. | ||
func (c *Contents) FindWriter(name string) (io.Writer, bool) { | ||
w, b := c.writers[name] | ||
return w, b | ||
} | ||
|
||
// FilePath returns the file path that stores the contents. | ||
func (c *Contents) FilePath() string { | ||
return c.filePath | ||
} |
Oops, something went wrong.