| 2576 | } |
| 2577 | |
| 2578 | func (g *Generator) generateFileDescriptor(file *FileDescriptor) { |
| 2579 | // Make a copy and trim source_code_info data. |
| 2580 | // TODO: Trim this more when we know exactly what we need. |
| 2581 | pb := proto.Clone(file.FileDescriptorProto).(*descriptor.FileDescriptorProto) |
| 2582 | pb.SourceCodeInfo = nil |
| 2583 | |
| 2584 | b, err := proto.Marshal(pb) |
| 2585 | if err != nil { |
| 2586 | g.Fail(err.Error()) |
| 2587 | } |
| 2588 | |
| 2589 | var buf bytes.Buffer |
| 2590 | w, _ := gzip.NewWriterLevel(&buf, gzip.BestCompression) |
| 2591 | w.Write(b) |
| 2592 | w.Close() |
| 2593 | b = buf.Bytes() |
| 2594 | |
| 2595 | v := file.VarName() |
| 2596 | g.P() |
| 2597 | g.P("func init() { ", g.Pkg["proto"], ".RegisterFile(", strconv.Quote(*file.Name), ", ", v, ") }") |
| 2598 | g.P("var ", v, " = []byte{") |
| 2599 | g.P("// ", len(b), " bytes of a gzipped FileDescriptorProto") |
| 2600 | for len(b) > 0 { |
| 2601 | n := 16 |
| 2602 | if n > len(b) { |
| 2603 | n = len(b) |
| 2604 | } |
| 2605 | |
| 2606 | s := "" |
| 2607 | for _, c := range b[:n] { |
| 2608 | s += fmt.Sprintf("0x%02x,", c) |
| 2609 | } |
| 2610 | g.P(s) |
| 2611 | |
| 2612 | b = b[n:] |
| 2613 | } |
| 2614 | g.P("}") |
| 2615 | } |
| 2616 | |
| 2617 | func (g *Generator) generateEnumRegistration(enum *EnumDescriptor) { |
| 2618 | // // We always print the full (proto-world) package name here. |