-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
916 additions
and
427 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package store | ||
package lani | ||
|
||
import "errors" | ||
|
||
|
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,33 @@ | ||
/* | ||
Lani is sky or heavens in Hawaiian and also sounds like line; we've chosen this word to | ||
represent Honu's byte serialization format for data storage; encoding in a serial or | ||
single skyward direction and decoding in a landward direction. | ||
*/ | ||
package lani | ||
|
||
// Specifies the interface for objects that can be encoded using lani. | ||
type Encodable interface { | ||
Size() int | ||
Encode(*Encoder) (int, error) | ||
} | ||
|
||
// Specifies the interface for objects that can be decoded using lani. | ||
type Decodable interface { | ||
Decode(*Decoder) error | ||
} | ||
|
||
// Marshal an encodable type into a byte slice for storage or serialization. | ||
func Marshal(v Encodable) (_ []byte, err error) { | ||
encoder := &Encoder{} | ||
encoder.Grow(v.Size()) | ||
if _, err = v.Encode(encoder); err != nil { | ||
return nil, err | ||
} | ||
return encoder.Bytes(), nil | ||
} | ||
|
||
// Unmarshal a decodable type from a byte slice for deserialization. | ||
func Unmarshal(data []byte, v Decodable) (err error) { | ||
decoder := NewDecoder(data) | ||
return v.Decode(decoder) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package store | ||
package lani | ||
|
||
import "encoding/binary" | ||
|
||
|
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,50 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/oklog/ulid/v2" | ||
"github.com/rotationalio/honu/pkg/store/lani" | ||
) | ||
|
||
//=========================================================================== | ||
// Access Control List | ||
//=========================================================================== | ||
|
||
type AccessControl struct { | ||
ClientID ulid.ULID `json:"client_id" msg:"client_id"` | ||
Permissions uint8 `json:"permissions" msg:"permissions"` | ||
} | ||
|
||
var _ lani.Encodable = &AccessControl{} | ||
var _ lani.Decodable = &AccessControl{} | ||
|
||
func (o *AccessControl) Size() int { | ||
// ULID + 1 byte for the permissions | ||
return 17 | ||
} | ||
|
||
func (o *AccessControl) Encode(e *lani.Encoder) (n int, err error) { | ||
var m int | ||
if m, err = e.EncodeULID(o.ClientID); err != nil { | ||
return n + m, err | ||
} | ||
n += m | ||
|
||
if m, err = e.EncodeUint8(o.Permissions); err != nil { | ||
return n + m, err | ||
} | ||
n += m | ||
|
||
return | ||
} | ||
|
||
func (o *AccessControl) Decode(d *lani.Decoder) (err error) { | ||
if o.ClientID, err = d.DecodeULID(); err != nil { | ||
return err | ||
} | ||
|
||
if o.Permissions, err = d.DecodeUint8(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.