MCPcopy Create free account
hub / github.com/blues/note / parseORIGTemplate

Function parseORIGTemplate

lib/bulk.go:955–1079  ·  view source on GitHub ↗

In the case of the ORIG format, get parameters about bin records from the template because in that format the bin records were not yet self-describing.

(ctx context.Context, tmplContext *BulkTemplateContext)

Source from the content-addressed store, hash-verified

953// In the case of the ORIG format, get parameters about bin records from the template
954// because in that format the bin records were not yet self-describing.
955func parseORIGTemplate(ctx context.Context, tmplContext *BulkTemplateContext) (err error) {
956 // All templates begin with time and location
957 binLength := 0
958 binLength += 8 // time
959 binLength += 8 // location
960
961 jsonReader := strings.NewReader(tmplContext.Template)
962 dec := jsonxt.NewDecoder(jsonReader)
963 dec.UseNumber()
964 boolPresent := false
965
966 for err == nil {
967 t, err2 := dec.Token()
968 if err2 == io.EOF {
969 break
970 }
971 // If invalid token (such as garbage in the template), bail
972 if err2 != nil {
973 err = err2
974 break
975 }
976 switch tt := t.(type) {
977 case jsonxt.Delim:
978 if debugJSONBin {
979 logDebug(ctx, "TEMPLATE DELIM %s", fmt.Sprintf("%v", t))
980 }
981 case string:
982 str := fmt.Sprintf("%s", t)
983 if debugJSONBin {
984 logDebug(ctx, "TEMPLATE string %s", str)
985 }
986 if !strings.HasPrefix(str, "\"") {
987 i, err2 := strconv.Atoi(str)
988 if err2 == nil && i > 0 {
989 binLength += i
990 } else {
991 binLength += len(str)
992 }
993 }
994 case jsonxt.Number:
995 if debugJSONBin {
996 logDebug(ctx, "TEMPLATE number")
997 }
998 numberType, errInt := tt.Int64()
999 if errInt == nil {
1000 // Integer
1001 switch numberType {
1002 case 11:
1003 binLength++
1004 case 12:
1005 binLength += 2
1006 case 13:
1007 binLength += 3
1008 case 1:
1009 fallthrough
1010 case 14:
1011 binLength += 4
1012 case 15:

Callers 1

BulkDecodeTemplateFunction · 0.85

Calls 7

UseNumberMethod · 0.95
TokenMethod · 0.95
NewDecoderFunction · 0.92
logDebugFunction · 0.85
isPointOneFunction · 0.85
Int64Method · 0.80
Float64Method · 0.80

Tested by

no test coverage detected