group.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package main
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "strings"
  6. )
  7. type GRP struct {
  8. Name [16]byte
  9. NumOfEntries uint16
  10. _ uint16
  11. }
  12. func (r *Root) ParseGRP(data []byte) {
  13. var grp GRP
  14. err := binary.Read(bytes.NewReader(data), binary.BigEndian, &grp)
  15. if err != nil {
  16. panic(err)
  17. }
  18. // Strip the null bytes from the strings
  19. name := strings.Replace(string(grp.Name[:]), "\x00", "", -1)
  20. entries := make([]string, grp.NumOfEntries)
  21. for i := 0; i < int(grp.NumOfEntries); i++ {
  22. offset := 20 + (i * 16)
  23. object := strings.Replace(string(data[offset:offset+16]), "\x00", "", -1)
  24. entries[i] = object
  25. }
  26. xmlData := XMLGRP{
  27. Name: name,
  28. Entries: entries,
  29. }
  30. r.Panes = append(r.Panes, Children{GRP: &xmlData})
  31. }
  32. func (r *Root) ParseGRS() {
  33. r.Panes = append(r.Panes, Children{
  34. GRS: &XMLGRS{},
  35. })
  36. }
  37. func (r *Root) ParseGRE() {
  38. r.Panes = append(r.Panes, Children{
  39. GRE: &XMLGRE{},
  40. })
  41. }
  42. func (b *BRLYTWriter) WriteGRP(data XMLGRP) {
  43. header := SectionHeader{
  44. Type: SectionTypeGRP,
  45. Size: uint32(28 + (16 * len(data.Entries))),
  46. }
  47. var name [16]byte
  48. copy(name[:], data.Name)
  49. grp := GRP{
  50. Name: name,
  51. NumOfEntries: uint16(len(data.Entries)),
  52. }
  53. write(b, header)
  54. write(b, grp)
  55. for _, str := range data.Entries {
  56. var entry [16]byte
  57. copy(entry[:], str)
  58. write(b, entry)
  59. }
  60. }
  61. func (b *BRLYTWriter) WriteGRS() {
  62. header := SectionHeader{
  63. Type: SectionTypeGRS,
  64. Size: 8,
  65. }
  66. write(b, header)
  67. }
  68. func (b *BRLYTWriter) WriteGRE() {
  69. header := SectionHeader{
  70. Type: SectionTypeGRE,
  71. Size: 8,
  72. }
  73. write(b, header)
  74. }