-
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.
Support fixed-length encoding for integers in JAM codec (#226)
- Loading branch information
Showing
8 changed files
with
254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package jam | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func IntLength(in any) (uint, error) { | ||
switch in.(type) { | ||
case uint8, int8: | ||
return 1, nil | ||
case uint16, int16: | ||
return 2, nil | ||
case uint32, int32: | ||
return 4, nil | ||
case uint64, int64: | ||
return 8, nil | ||
default: | ||
return 0, fmt.Errorf(ErrUnsupportedType, in) | ||
} | ||
} | ||
|
||
func parseTag(tag string) map[string]string { | ||
result := make(map[string]string) | ||
pairs := strings.Split(tag, ",") | ||
for _, pair := range pairs { | ||
kv := strings.Split(pair, "=") | ||
if len(kv) == 2 { | ||
result[kv[0]] = kv[1] | ||
} | ||
} | ||
return result | ||
} |
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
Oops, something went wrong.