示例#1
0
func fill_slice_string(buf []byte, s string) ([]byte, int) {
	var dn int
	n := 0
	tbuf := make([]byte, 8)

	dn = dlug.FillSliceUint32(tbuf, uint32(len(s)))
	buf = append(buf, tbuf[0:dn]...)
	n += dn

	buf = append(buf, []byte(s)...)
	n += len(s)

	return buf, n

}
示例#2
0
// No path structures, so some arrays are of 0 length
//
//func cgf_default_tile_map() []byte {
func CGFDefaultTileMap() []byte {
	var n int
	tilemap_bytes := make([]byte, 0, 1024*40)
	buf := make([]byte, 16)

	for ii := 0; ii < len(DEFAULT_TILEMAP); ii++ {
		t := DEFAULT_TILEMAP[ii]

		allele_parts := strings.Split(t, ":")
		class_parts0 := strings.Split(allele_parts[0], ";")
		class_parts1 := strings.Split(allele_parts[1], ";")

		n = dlug.FillSliceUint32(buf, uint32(len(class_parts0)))
		tilemap_bytes = append(tilemap_bytes, buf[:n]...)

		n = dlug.FillSliceUint32(buf, uint32(len(class_parts1)))
		tilemap_bytes = append(tilemap_bytes, buf[:n]...)

		for i := 0; i < len(class_parts0); i++ {
			parts := strings.Split(class_parts0[i], "+")
			span := 1
			if len(parts) > 1 {
				span_, e := strconv.ParseInt(parts[1], 16, 64)
				if e != nil {
					log.Fatal(e)
				}
				span = int(span_)

			}

			tilevar_, e := strconv.ParseInt(parts[0], 16, 64)
			if e != nil {
				log.Fatal(e)
			}
			tilevar := int(tilevar_)

			n = dlug.FillSliceUint32(buf, uint32(tilevar))
			tilemap_bytes = append(tilemap_bytes, buf[:n]...)

			n = dlug.FillSliceUint32(buf, uint32(span))
			tilemap_bytes = append(tilemap_bytes, buf[:n]...)

		}

		for i := 0; i < len(class_parts1); i++ {
			parts := strings.Split(class_parts1[i], "+")
			span := 1
			if len(parts) > 1 {
				span_, e := strconv.ParseInt(parts[1], 16, 64)
				if e != nil {
					log.Fatal(e)
				}
				span = int(span_)

			}

			tilevar_, e := strconv.ParseInt(parts[0], 16, 64)
			if e != nil {
				log.Fatal(e)
			}
			tilevar := int(tilevar_)

			n = dlug.FillSliceUint32(buf, uint32(tilevar))
			tilemap_bytes = append(tilemap_bytes, buf[:n]...)

			n = dlug.FillSliceUint32(buf, uint32(span))
			tilemap_bytes = append(tilemap_bytes, buf[:n]...)

		}

	}

	return tilemap_bytes
}
示例#3
0
// ctx holds the populated CGF structure along with a
// filled in SGLF structure, populated TileMapArray
// and the variaous TileMapLookup and TileMapPosition.
//
// This returns the raw bytes as they're to be stored
// on disk (or in memory presumably).
//
//func create_cgf_bytes(ctx *CGFContext) []byte {
func CreateCGFBytes(ctx *CGFContext) []byte {
	var dn int

	fin_bytes := make([]byte, 0, 1024*1024)
	buf := make([]byte, 128)

	n := 0
	cgf := ctx.CGF

	tobyte64(buf, cgf.Magic)
	fin_bytes = append(fin_bytes, buf[0:8]...)
	n += 8

	fin_bytes, dn = fill_slice_string(fin_bytes, cgf.Version)
	n += dn

	fin_bytes, dn = fill_slice_string(fin_bytes, cgf.LibraryVersion)
	n += dn

	tobyte64(buf, cgf.PathCount)
	fin_bytes = append(fin_bytes, buf[0:8]...)
	n += 8

	tobyte64(buf, cgf.TileMapLen)
	fin_bytes = append(fin_bytes, buf[0:8]...)
	n += 8

	fin_bytes = append(fin_bytes, cgf.TileMap...)
	n += len(cgf.TileMap)

	for i := 0; i < len(cgf.StepPerPath); i++ {
		tobyte64(buf, cgf.StepPerPath[i])
		fin_bytes = append(fin_bytes, buf[0:8]...)
		n += 8
	}

	PathOffset := make([]uint64, len(cgf.Path)+1)
	path_bytes := make([]byte, 0, 1024)
	for i := 0; i < len(cgf.Path); i++ {

		// PathOffset is from the beginning of PathStruct array
		//

		PathOffset[i] = uint64(len(path_bytes))
		p := cgf.Path[i]

		// Name of this Path
		//
		dn = dlug.FillSliceUint32(buf, uint32(len(p.Name)))
		path_bytes = append(path_bytes, buf[0:dn]...)

		path_bytes = append(path_bytes, []byte(p.Name)...)

		// The 'cache' Vector structure
		//
		tobyte64(buf, uint64(len(p.Vector)))
		path_bytes = append(path_bytes, buf[0:8]...)

		for j := 0; j < len(p.Vector); j++ {
			tobyte64(buf, p.Vector[j])
			path_bytes = append(path_bytes, buf[0:8]...)
		}

		// Overflow
		//

		tobyte64(buf, uint64(p.Overflow.Length))
		path_bytes = append(path_bytes, buf[0:8]...)

		tobyte64(buf, uint64(p.Overflow.Stride))
		path_bytes = append(path_bytes, buf[0:8]...)

		for j := 0; j < len(p.Overflow.Offset); j++ {
			tobyte64(buf, uint64(p.Overflow.Offset[j]))
			path_bytes = append(path_bytes, buf[0:8]...)
		}

		for j := 0; j < len(p.Overflow.Position); j++ {
			tobyte64(buf, uint64(p.Overflow.Position[j]))
			path_bytes = append(path_bytes, buf[0:8]...)
		}

		path_bytes = append(path_bytes, p.Overflow.Map...)

		// FinalOverflow
		//

		tobyte64(buf, uint64(p.FinalOverflow.Length))
		path_bytes = append(path_bytes, buf[0:8]...)

		tobyte64(buf, uint64(p.FinalOverflow.Stride))
		path_bytes = append(path_bytes, buf[0:8]...)

		for j := 0; j < len(p.FinalOverflow.Offset); j++ {
			tobyte64(buf, uint64(p.FinalOverflow.Offset[j]))
			path_bytes = append(path_bytes, buf[0:8]...)
		}

		for j := 0; j < len(p.FinalOverflow.Position); j++ {
			tobyte64(buf, uint64(p.FinalOverflow.Position[j]))
			path_bytes = append(path_bytes, buf[0:8]...)
		}

		path_bytes = append(path_bytes, p.FinalOverflow.DataRecord.Code...)
		path_bytes = append(path_bytes, p.FinalOverflow.DataRecord.Data...)

		if len(p.LowQualityBytes) < 24 {
			b := make([]byte, 24)
			path_bytes = append(path_bytes, b...)
		} else {
			path_bytes = append(path_bytes, p.LowQualityBytes...)
		}

	}

	PathOffset[len(cgf.Path)] = uint64(len(path_bytes))

	for i := 0; i < len(PathOffset); i++ {
		tobyte64(buf, PathOffset[i])
		fin_bytes = append(fin_bytes, buf[0:8]...)
		n += 8
	}

	fin_bytes = append(fin_bytes, path_bytes...)

	return fin_bytes
}